-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.zig
70 lines (60 loc) · 2.77 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
const std = @import("std");
const YEAR_DIRS = [_][]const u8{ "2022", "2024" };
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// set up zutils
const zutils = b.addModule("zutils", .{
.root_source_file = b.path("zutils/zutils.zig"),
.target = target,
});
const zutils_test = b.addTest(.{ .root_source_file = b.path("zutils/zutils.zig") });
const run_ztest = b.addRunArtifact(zutils_test);
const ztest_step = b.step("test_zutils", "Run zutils tests");
ztest_step.dependOn(&run_ztest.step);
const all_test_step = b.step("test_all", "Run all tests");
all_test_step.dependOn(&run_ztest.step);
// iterate through day files and add targets
const cwd = std.fs.cwd();
for (YEAR_DIRS) |y| {
const year = try cwd.openDir(y, .{ .iterate = true });
const run_year_step = b.step(b.fmt("run_{s}", .{y}), b.fmt("Run all in {s}", .{y}));
var iter = year.iterate();
while (try iter.next()) |ent| {
switch (ent.kind) {
.file => {
if (!std.mem.endsWith(u8, ent.name, ".zig")) {
continue;
}
const zigfile = b.fmt("{s}/{s}", .{ y, ent.name });
// remove .zig
const exename = b.fmt("{s}_{s}", .{ y, ent.name[0 .. ent.name.len - 4] });
// add day exe
const day_exe = b.addExecutable(.{
.name = exename,
.root_source_file = b.path(zigfile),
.target = target,
.optimize = optimize,
});
day_exe.root_module.addImport("zutils", zutils);
b.installArtifact(day_exe);
// add day run
const run_day = b.addRunArtifact(day_exe);
const run_step = b.step(b.fmt("run_{s}", .{exename}), b.fmt("Run {s}", .{exename}));
run_step.dependOn(&run_day.step);
run_year_step.dependOn(&run_day.step);
// add day test
const day_test = b.addTest(.{ .name = exename, .root_source_file = b.path(zigfile) });
day_test.root_module.addImport("zutils", zutils);
const run_test = b.addRunArtifact(day_test);
const test_step = b.step(b.fmt("test_{s}", .{exename}), b.fmt("Run tests for {s}", .{exename}));
test_step.dependOn(&run_test.step);
all_test_step.dependOn(&run_test.step);
},
else => {
continue;
},
}
}
}
}