-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.zig
64 lines (53 loc) · 2.17 KB
/
build.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const std = @import("std");
pub fn build(b: *std.Build) void {
const ally = b.allocator;
const optimize = b.standardOptimizeOption(.{});
const target = b.standardTargetOptions(.{});
const no_nanbox = b.option(bool, "no_nanbox", "Do not use nanbox implementation of Janet (default false)") orelse false;
const c_header = b.addTranslateC(.{
.root_source_file = b.path("c/janet.h"),
.optimize = optimize,
.target = target,
});
const mod = b.addModule("jzignet", .{
.root_source_file = b.path("src/janet.zig"),
.imports = &.{.{ .name = "cjanet", .module = c_header.createModule() }},
});
const lib = b.addStaticLibrary(.{
.name = "jzignet",
.optimize = optimize,
.target = target,
});
var janet_flags = std.ArrayList([]const u8).init(ally);
janet_flags.appendSlice(&[_][]const u8{"-std=c99"}) catch unreachable;
if (optimize != .Debug) {
janet_flags.appendSlice(&[_][]const u8{ "-O2", "-flto" }) catch unreachable;
}
if (no_nanbox) {
janet_flags.appendSlice(&[_][]const u8{"-DJANET_NO_NANBOX"}) catch unreachable;
}
lib.linkLibC();
lib.addIncludePath(b.path("c"));
lib.addCSourceFile(.{ .file = b.path("c/janet.c"), .flags = janet_flags.items });
b.installArtifact(lib);
var tests = b.addTest(.{
.root_source_file = b.path("src/janet.zig"),
.optimize = optimize,
.target = target,
});
tests.root_module.addImport("cjanet", c_header.createModule());
tests.root_module.addImport("jzignet", mod);
tests.linkLibrary(lib);
const test_step = b.step("test", "Run library tests");
test_step.dependOn(&b.addRunArtifact(tests).step);
const embed_janet_exe = b.addExecutable(.{
.name = "embed_janet",
.target = target,
.root_source_file = b.path("examples/embed_janet.zig"),
});
embed_janet_exe.root_module.addImport("jzignet", mod);
embed_janet_exe.linkLibrary(lib);
b.installArtifact(embed_janet_exe);
const run_embed_janet_exe = b.step("run-embed_janet", "Run embed_janet example");
run_embed_janet_exe.dependOn(&b.addRunArtifact(embed_janet_exe).step);
}