-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuild.zig
90 lines (77 loc) · 2.63 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// libgc
const gc = b.addStaticLibrary(.{
.name = "gc",
.target = target,
.optimize = optimize,
});
{
// TODO(mitchellh): support more complex features that are usually on
// with libgc like threading, parallelization, etc.
const cflags = [_][]const u8{};
const libgc_srcs = [_][]const u8{
"alloc.c", "reclaim.c", "allchblk.c", "misc.c", "mach_dep.c", "os_dep.c",
"mark_rts.c", "headers.c", "mark.c", "obj_map.c", "blacklst.c", "finalize.c",
"new_hblk.c", "dbg_mlc.c", "malloc.c", "dyn_load.c", "typd_mlc.c", "ptr_chck.c",
"mallocx.c",
};
gc.linkLibC();
if (target.isDarwin()) {
gc.linkFramework("Foundation");
}
gc.addIncludePath("vendor/bdwgc/include");
inline for (libgc_srcs) |src| {
gc.addCSourceFile("vendor/bdwgc/" ++ src, &cflags);
}
const gc_step = b.step("libgc", "build libgc");
gc_step.dependOn(&gc.step);
}
// lib for zig
const lib = b.addStaticLibrary(.{
.name = "gc",
.root_source_file = .{ .path = "src/gc.zig" },
.target = target,
.optimize = optimize,
});
{
var main_tests = b.addTest(.{
.root_source_file = .{ .path = "src/gc.zig" },
.target = target,
.optimize = optimize,
});
main_tests.linkLibC();
main_tests.addIncludePath("vendor/bdwgc/include");
main_tests.linkLibrary(gc);
const test_step = b.step("test", "Run library tests");
test_step.dependOn(&main_tests.step);
b.default_step.dependOn(&lib.step);
b.installArtifact(lib);
}
const module = b.createModule(.{
.source_file = .{ .path = "src/gc.zig" },
});
// example app
const exe = b.addExecutable(.{
.name = "example",
.root_source_file = .{ .path = "example/basic.zig" },
.target = target,
.optimize = optimize,
});
{
exe.linkLibC();
exe.addIncludePath("vendor/bdwgc/include");
exe.linkLibrary(gc);
exe.addModule("gc", module);
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run_example", "run example");
run_step.dependOn(&run_cmd.step);
}
}