generated from SpexGuy/Zig-AoC-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
69 lines (53 loc) · 2.24 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
const std = @import("std");
const Builder = std.build.Builder;
const LibExeObjStep = std.build.LibExeObjStep;
// set this to true to link libc
const should_link_libc = false;
const test_files = [_][]const u8 {
// list any zig files with tests here
};
fn linkObject(b: *Builder, obj: *LibExeObjStep) void {
if (should_link_libc) obj.linkLibC();
// Add linking for packages or third party libraries here
}
pub fn build(b: *Builder) void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{});
// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const mode = b.standardReleaseOptions();
// Set up an exe for each day
comptime var day = 1;
inline while (day <= 25) : (day += 1) {
@setEvalBranchQuota(100000); // this comptimePrint is pretty expensive
const dayString = comptime std.fmt.comptimePrint("day{:0>2}", .{ day });
const zigFile = "src/" ++ dayString ++ ".zig";
const exe = b.addExecutable(dayString, zigFile);
exe.setTarget(target);
exe.setBuildMode(mode);
linkObject(b, exe);
exe.install();
const install_cmd = b.addInstallArtifact(exe);
const install_step = b.step("install_" ++ dayString, "Install " ++ dayString ++ ".exe");
install_step.dependOn(&install_cmd.step);
const run_cmd = exe.run();
run_cmd.step.dependOn(&install_cmd.step);
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step(dayString, "Run " ++ dayString);
run_step.dependOn(&run_cmd.step);
}
// Set up a step to run all tests
const test_step = b.step("test", "Run all tests");
for (test_files) |file| {
const test_cmd = b.addTest(file);
test_cmd.setTarget(target);
test_cmd.setBuildMode(mode);
linkObject(b, test_cmd);
test_step.dependOn(&test_cmd.step);
}
}