-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.zig
97 lines (81 loc) · 2.68 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
91
92
93
94
95
96
97
const std = @import("std");
const Build = std.Build;
const Step = Build.Step;
pub const NamedModule = struct {
mod: *Build.Module,
name: []const u8,
pub fn init(b: *Build, name: []const u8, options: Build.Module.CreateOptions) NamedModule {
const mod = b.addModule(name, options);
return NamedModule{
.mod = mod,
.name = name,
};
}
};
pub fn build(b: *Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Lib module
const lib_mod = NamedModule.init(b, "lib", .{
.root_source_file = b.path("patcher/src/lib/root.zig"),
.target = target,
.optimize = optimize,
});
// Check step
const check = b.step("check", "Check if project compiles");
// Create exe
const exe = addExe(b, check, &.{lib_mod}, .{
.name = "config-patcher",
.root_source_file = b.path("patcher/src/main.zig"),
.target = target,
.optimize = optimize,
});
// Run command
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);
// Tests
const test_step = b.step("test", "Run unit tests");
_ = addTest(b, check, &.{lib_mod}, test_step, .{
.root_source_file = b.path("patcher/src/lib/root.zig"),
.target = target,
.optimize = optimize,
});
_ = addTest(b, check, &.{lib_mod}, test_step, .{
.root_source_file = b.path("patcher/test/root.zig"),
.target = target,
.optimize = optimize,
});
}
fn addExe(b: *Build, check: *Step, mods: []const NamedModule, options: Build.ExecutableOptions) *Step.Compile {
const exe = b.addExecutable(options);
for (mods) |mod| {
exe.root_module.addImport(mod.name, mod.mod);
}
b.installArtifact(exe);
const check_exe = b.addExecutable(options);
for (mods) |mod| {
check_exe.root_module.addImport(mod.name, mod.mod);
}
check.dependOn(&check_exe.step);
return exe;
}
fn addTest(b: *Build, check: *Step, mods: []const NamedModule, tst_step: *Step, options: Build.TestOptions) *Step.Compile {
const tst = b.addTest(options);
for (mods) |mod| {
tst.root_module.addImport(mod.name, mod.mod);
}
const run_tst = b.addRunArtifact(tst);
run_tst.has_side_effects = true;
tst_step.dependOn(&run_tst.step);
const check_tst = b.addTest(options);
for (mods) |mod| {
check_tst.root_module.addImport(mod.name, mod.mod);
}
check.dependOn(&check_tst.step);
return tst;
}