2023-11-30 12:12:51 +11:00
|
|
|
const std = @import("std");
|
|
|
|
|
|
|
|
// Although this function looks imperative, note that its job is to
|
|
|
|
// declaratively construct a build graph that will be executed by an external
|
|
|
|
// runner.
|
|
|
|
pub fn build(b: *std.Build) 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 optimization options allow the person running `zig build` to select
|
|
|
|
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
|
|
|
|
// set a preferred release mode, allowing the user to decide how to optimize.
|
|
|
|
const optimize = b.standardOptimizeOption(.{});
|
|
|
|
|
2023-11-30 14:52:04 +11:00
|
|
|
// Build harness based on https://github.com/SpexGuy/Zig-AoC-Template.
|
2023-11-30 12:12:51 +11:00
|
|
|
|
2023-11-30 14:52:04 +11:00
|
|
|
// Build, run, and install targets for "all."
|
|
|
|
const build_all = b.step("all", "Build all days");
|
|
|
|
const run_all = b.step("run", "Run all days");
|
|
|
|
const test_all = b.step("test", "Run all tests");
|
2023-11-30 12:12:51 +11:00
|
|
|
|
2023-11-30 14:52:04 +11:00
|
|
|
// Generate build, run, and install targets for all days that have been
|
|
|
|
// created.
|
|
|
|
for (1..25) |day| {
|
|
|
|
const day_string = b.fmt("day{:0>2}", .{day});
|
|
|
|
const src = b.fmt("src/{s}.zig", .{day_string});
|
|
|
|
std.fs.cwd().access(src, .{}) catch continue;
|
2023-11-30 12:12:51 +11:00
|
|
|
|
2023-11-30 14:52:04 +11:00
|
|
|
// Build and install
|
|
|
|
const exe = b.addExecutable(.{
|
|
|
|
.name = b.fmt("aoc23-{s}", .{day_string}),
|
|
|
|
.root_source_file = .{ .path = src },
|
|
|
|
.target = target,
|
|
|
|
.optimize = optimize,
|
|
|
|
});
|
|
|
|
b.installArtifact(exe);
|
|
|
|
build_all.dependOn(&exe.step);
|
2023-11-30 12:12:51 +11:00
|
|
|
|
2023-11-30 14:52:04 +11:00
|
|
|
// Run
|
|
|
|
const run_cmd = b.addRunArtifact(exe);
|
|
|
|
run_cmd.step.dependOn(b.getInstallStep());
|
|
|
|
if (b.args) |args| {
|
|
|
|
run_cmd.addArgs(args);
|
|
|
|
}
|
2023-11-30 12:12:51 +11:00
|
|
|
|
2023-11-30 14:52:04 +11:00
|
|
|
const run_step = b.step(
|
|
|
|
b.fmt("run-{s}", .{day_string}),
|
|
|
|
b.fmt("Run {s} executable", .{day_string}),
|
|
|
|
);
|
|
|
|
run_step.dependOn(&run_cmd.step);
|
|
|
|
run_all.dependOn(&run_cmd.step);
|
2023-11-30 12:12:51 +11:00
|
|
|
|
2023-11-30 14:52:04 +11:00
|
|
|
// Test
|
|
|
|
const unit_test = b.addTest(.{
|
|
|
|
.root_source_file = .{ .path = src },
|
|
|
|
.target = target,
|
|
|
|
.optimize = optimize,
|
|
|
|
});
|
2023-11-30 12:12:51 +11:00
|
|
|
|
2023-11-30 14:52:04 +11:00
|
|
|
const test_cmd = b.addRunArtifact(unit_test);
|
|
|
|
const test_step = b.step(
|
|
|
|
b.fmt("test-{s}", .{day_string}),
|
|
|
|
b.fmt("Run {s} tests", .{day_string}),
|
|
|
|
);
|
|
|
|
test_step.dependOn(&test_cmd.step);
|
|
|
|
test_all.dependOn(&test_cmd.step);
|
|
|
|
}
|
2023-11-30 12:12:51 +11:00
|
|
|
}
|