summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig48
1 files changed, 48 insertions, 0 deletions
diff --git a/build.zig b/build.zig
new file mode 100644
index 0000000..06c012b
--- /dev/null
+++ b/build.zig
@@ -0,0 +1,48 @@
1const builtin = @import("builtin");
2const std = @import("std");
3
4const Mode = builtin.Mode;
5const Builder = std.build.Builder;
6
7pub fn build(b: *Builder) void {
8 const mode = b.standardReleaseOptions();
9
10 const example_step = b.step("examples", "Build examples");
11 inline for ([][]const u8{
12 "comptime-clap",
13 "streaming-clap",
14 }) |example_name| {
15 const example = b.addExecutable(example_name, "example/" ++ example_name ++ ".zig");
16 example.addPackagePath("clap", "src/index.zig");
17 example.setBuildMode(mode);
18 example_step.dependOn(&example.step);
19 }
20
21 const test_all_step = b.step("test", "Run all tests in all modes.");
22 inline for ([]Mode{ Mode.Debug, Mode.ReleaseFast, Mode.ReleaseSafe, Mode.ReleaseSmall }) |test_mode| {
23 const mode_str = comptime modeToString(test_mode);
24
25 const tests = b.addTest("src/index.zig");
26 tests.setBuildMode(test_mode);
27 tests.setNamePrefix(mode_str ++ " ");
28
29 const test_step = b.step("test-" ++ mode_str, "Run all tests in " ++ mode_str ++ ".");
30 test_step.dependOn(&tests.step);
31 test_all_step.dependOn(test_step);
32 }
33
34 const all_step = b.step("all", "Build everything and runs all tests");
35 all_step.dependOn(test_all_step);
36 all_step.dependOn(example_step);
37
38 b.default_step.dependOn(all_step);
39}
40
41fn modeToString(mode: Mode) []const u8 {
42 return switch (mode) {
43 Mode.Debug => "debug",
44 Mode.ReleaseFast => "release-fast",
45 Mode.ReleaseSafe => "release-safe",
46 Mode.ReleaseSmall => "release-small",
47 };
48}