Repository navigation
Expand file tree
/
Copy pathbuild.zig
More file actions
80 lines (70 loc) · 2.84 KB
/
Copy pathbuild.zig
File metadata and controls
80 lines (70 loc) · 2.84 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
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const mod = b.addModule("cli", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
// Only the exported module matters to a consumer. The demo, examples, and
// test runner are developer-only.
if (b.pkg_hash.len != 0) return;
// testingx provides the test runner. It is lazy because only the root
// build uses it; a consumer never fetches it. On the first configure pass
// it is not fetched yet, `dependencyLazy` reports that it is needed, and
// the build runner fetches it and reruns this script.
const testingx_dep = b.dependencyLazy("testingx", .{ .target = target }) catch null;
const test_runner: ?std.Build.Step.Compile.TestRunner = if (testingx_dep) |dep|
.{ .path = dep.path("src/runner.zig"), .mode = .simple }
else
null;
const kitchen = addExample(b, mod, target, optimize, "kitchen", "cli-kitchen");
b.installArtifact(kitchen);
const run_cmd = b.addRunArtifact(kitchen);
run_cmd.addPassthruArgs();
run_cmd.step.dependOn(b.getInstallStep());
const run_step = b.step("run", "Run the kitchen-sink demo");
run_step.dependOn(&run_cmd.step);
const examples_step = b.step("examples", "Build the example programs");
examples_step.dependOn(&kitchen.step);
const examples = [_]struct { file: []const u8, name: []const u8 }{
.{ .file = "git", .name = "cli-git" },
.{ .file = "ls", .name = "cli-ls" },
.{ .file = "tar", .name = "cli-tar" },
.{ .file = "verbose", .name = "cli-verbose" },
.{ .file = "codec", .name = "cli-codec" },
};
for (examples) |example| {
const example_exe = addExample(b, mod, target, optimize, example.file, example.name);
b.installArtifact(example_exe);
examples_step.dependOn(&example_exe.step);
}
const mod_tests = b.addTest(.{
.root_module = mod,
.test_runner = test_runner,
});
const run_mod_tests = b.addRunArtifact(mod_tests);
run_mod_tests.addPassthruArgs();
const test_step = b.step("test", "Run tests");
test_step.dependOn(&run_mod_tests.step);
test_step.dependOn(examples_step);
}
fn addExample(
b: *std.Build,
mod: *std.Build.Module,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
file: []const u8,
name: []const u8,
) *std.Build.Step.Compile {
return b.addExecutable(.{
.name = name,
.root_module = b.createModule(.{
.root_source_file = b.path(b.fmt("examples/{s}.zig", .{file})),
.target = target,
.optimize = optimize,
.imports = &.{.{ .name = "cli", .module = mod }},
}),
});
}