-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.zig
More file actions
152 lines (126 loc) · 5.41 KB
/
build.zig
File metadata and controls
152 lines (126 loc) · 5.41 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const name = b.option([]const u8, "name", "Name of the output file") orelse "topi";
const version = getVersion(b) catch |err| {
std.log.err("Could not get version: {}", .{err});
return;
};
const build_options = b.addOptions();
build_options.addOption([]const u8, "version", version);
const topi = b.addModule("topi", .{
.root_source_file = b.path("src/topi.zig"),
});
_ = b.addModule("topi_docs", .{
.root_source_file = b.path("docs/docs.zig"),
});
const topi_export = b.addModule("export", .{
.root_source_file = b.path("src/export/index.zig"),
});
topi_export.addImport("topi", topi);
const topilib = b.addLibrary(.{
.name = name,
.linkage = .dynamic,
.root_module = b.createModule(.{
.root_source_file = b.path("src/export/main.zig"),
.target = target,
.optimize = optimize,
}),
});
topilib.root_module.addImport("topi", topi);
const art = b.addInstallArtifact(topilib, .{ .dest_dir = .{ .override = .lib } });
b.getInstallStep().dependOn(&art.step);
const exe = b.addExecutable(.{
.name = name,
.root_module = b.createModule(.{
.root_source_file = b.path("src/cli/main.zig"),
.target = b.graph.host,
.optimize = optimize,
}),
});
exe.root_module.addOptions("build", build_options);
exe.root_module.addImport("topi", topi);
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", "Run the app");
run_step.dependOn(&run_cmd.step);
const filter = b.option([]const []const u8, "filter", "Filter strings for tests") orelse &[_][]const u8{};
const tests = b.addTest(.{
.filters = filter,
.root_module = b.createModule(.{
.root_source_file = b.path("test/index.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
tests.root_module.addImport("topi", topi);
tests.root_module.addImport("export", topi_export);
const run_tests = b.addRunArtifact(tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_tests.step);
// Run with: `zig build fuzz --fuzz`
// The top-level `--fuzz` flag tells the build system to enable continuous
// fuzzing for tests that call `std.testing.fuzz`.
const fuzz_step = b.step("fuzz", "Run fuzz tests (add --fuzz to enable continuous fuzzing)");
fuzz_step.dependOn(&run_tests.step);
// --- Benchmark fixture + run ---
// `zig build bench-gen` writes 1 entry + 20 chapter .topi files into bench/fixtures/.
// `zig build bench` runs that and then compiles the fixture with --time.
const bench_gen_exe = b.addExecutable(.{
.name = "bench-gen",
.root_module = b.createModule(.{
.root_source_file = b.path("bench/gen.zig"),
.target = b.graph.host,
.optimize = .Debug,
}),
});
const run_bench_gen = b.addRunArtifact(bench_gen_exe);
run_bench_gen.addArg("bench/fixtures/");
const bench_gen_step = b.step("bench-gen", "Generate benchmark fixture (entry + 20 chapters)");
bench_gen_step.dependOn(&run_bench_gen.step);
const run_bench = b.addRunArtifact(exe);
run_bench.step.dependOn(&run_bench_gen.step);
run_bench.addArgs(&.{ "compile", "bench/fixtures/entry.topi", "--time" });
const bench_step = b.step("bench", "Generate fixture and run topi compile --time on it");
bench_step.dependOn(&run_bench.step);
// --- Many-modules benchmark ---
// `zig build bench-gen-many` writes N independent top-level .topi files
// into bench/fixtures_many/. `zig build bench-many` runs that then
// compiles every file sequentially and in parallel, reporting wall time.
const bench_gen_many_exe = b.addExecutable(.{
.name = "bench-gen-many",
.root_module = b.createModule(.{
.root_source_file = b.path("bench/gen_many.zig"),
.target = b.graph.host,
.optimize = .Debug,
}),
});
const run_bench_gen_many = b.addRunArtifact(bench_gen_many_exe);
run_bench_gen_many.addArg("bench/fixtures_many/");
const bench_gen_many_step = b.step("bench-gen-many", "Generate many-modules benchmark fixture");
bench_gen_many_step.dependOn(&run_bench_gen_many.step);
const bench_many_exe = b.addExecutable(.{
.name = "bench-many",
.root_module = b.createModule(.{
.root_source_file = b.path("bench/bench_many.zig"),
.target = b.graph.host,
.optimize = optimize,
}),
});
bench_many_exe.root_module.addImport("topi", topi);
const run_bench_many = b.addRunArtifact(bench_many_exe);
run_bench_many.step.dependOn(&run_bench_gen_many.step);
run_bench_many.addArg("bench/fixtures_many/");
const bench_many_step = b.step("bench-many", "Generate many-modules fixture and run parallel compile benchmark");
bench_many_step.dependOn(&run_bench_many.step);
}
fn getVersion(b: *std.Build) ![]const u8 {
const zon = @import("build.zig.zon");
return b.allocator.dupe(u8, zon.version);
}