1
0
aoc23/build.zig

72 lines
2.6 KiB
Zig

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(.{});
// Build harness based on https://github.com/SpexGuy/Zig-AoC-Template.
// 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");
// 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;
// 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);
// Run
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(
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);
// Test
const unit_test = b.addTest(.{
.root_source_file = .{ .path = src },
.target = target,
.optimize = optimize,
});
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);
}
}