2020-11-26 22:46:03 +01:00
|
|
|
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;
|
|
|
|
|
|
|
|
fn linkObject(b: *Builder, obj: *LibExeObjStep) void {
|
|
|
|
if (should_link_libc) obj.linkLibC();
|
2021-11-24 05:56:51 +01:00
|
|
|
_ = b;
|
2020-11-26 22:46:03 +01:00
|
|
|
|
|
|
|
// Add linking for packages or third party libraries here
|
|
|
|
}
|
|
|
|
|
2021-12-07 19:52:40 +01:00
|
|
|
const required_zig_version = std.SemanticVersion.parse("0.9.0-dev.1920+de81c504b") catch unreachable;
|
|
|
|
|
2020-11-26 22:46:03 +01:00
|
|
|
pub fn build(b: *Builder) void {
|
2021-12-07 19:52:40 +01:00
|
|
|
if (comptime @import("builtin").zig_version.order(required_zig_version) == .lt) {
|
|
|
|
std.debug.print(
|
|
|
|
\\Error: Your version of Zig is missing features that are needed for this template.
|
|
|
|
\\You will need to download a newer build.
|
|
|
|
\\
|
|
|
|
\\ https://ziglang.org/download/
|
|
|
|
\\
|
|
|
|
\\
|
|
|
|
, .{});
|
|
|
|
std.os.exit(1);
|
|
|
|
}
|
|
|
|
|
2020-11-26 22:46:03 +01:00
|
|
|
// 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();
|
|
|
|
|
2021-11-24 05:56:51 +01:00
|
|
|
const install_all = b.step("install_all", "Install all days");
|
2021-12-07 19:52:40 +01:00
|
|
|
const install_all_tests = b.step("install_tests_all", "Install tests for all days");
|
2021-11-24 05:56:51 +01:00
|
|
|
const run_all = b.step("run_all", "Run all days");
|
|
|
|
|
2020-11-26 22:46:03 +01:00
|
|
|
// Set up an exe for each day
|
2021-11-24 05:56:51 +01:00
|
|
|
var day: u32 = 1;
|
|
|
|
while (day <= 25) : (day += 1) {
|
|
|
|
const dayString = b.fmt("day{:0>2}", .{day});
|
|
|
|
const zigFile = b.fmt("src/{s}.zig", .{dayString});
|
2020-11-26 22:46:03 +01:00
|
|
|
|
|
|
|
const exe = b.addExecutable(dayString, zigFile);
|
|
|
|
exe.setTarget(target);
|
|
|
|
exe.setBuildMode(mode);
|
|
|
|
linkObject(b, exe);
|
|
|
|
|
2022-11-24 18:53:36 +01:00
|
|
|
// NOTE: This line can be commented out once #13480 is fixed.
|
|
|
|
// https://github.com/ziglang/zig/issues/13480
|
|
|
|
// The fix is slated to be merged in PR #13637.
|
|
|
|
// https://github.com/ziglang/zig/pull/13637
|
|
|
|
// Until then, stage 1 is probably the better default for advent of code,
|
|
|
|
// due to the common use of std.StaticBitSet.
|
|
|
|
// If you are using a master branch build of zig, this line may cause
|
|
|
|
// a compile error. You can safely remove it as long as you have a build
|
|
|
|
// from after when PR #13637 was merged.
|
|
|
|
exe.use_stage1 = true; // compile error? see comment above.
|
|
|
|
|
2020-11-26 22:46:03 +01:00
|
|
|
exe.install();
|
|
|
|
|
|
|
|
const install_cmd = b.addInstallArtifact(exe);
|
|
|
|
|
2021-12-07 19:52:40 +01:00
|
|
|
const run_test = b.addTest(zigFile);
|
|
|
|
run_test.setTarget(target);
|
|
|
|
run_test.setBuildMode(mode);
|
|
|
|
linkObject(b, exe);
|
|
|
|
|
|
|
|
const build_test = b.addTestExe(b.fmt("test_{s}", .{dayString}), zigFile);
|
|
|
|
build_test.setTarget(target);
|
|
|
|
build_test.setBuildMode(mode);
|
|
|
|
linkObject(b, exe);
|
|
|
|
const install_test = b.addInstallArtifact(build_test);
|
|
|
|
|
|
|
|
{
|
|
|
|
const step_key = b.fmt("install_{s}", .{dayString});
|
|
|
|
const step_desc = b.fmt("Install {s}.exe", .{dayString});
|
|
|
|
const install_step = b.step(step_key, step_desc);
|
|
|
|
install_step.dependOn(&install_cmd.step);
|
|
|
|
install_all.dependOn(&install_cmd.step);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const step_key = b.fmt("test_{s}", .{dayString});
|
|
|
|
const step_desc = b.fmt("Run tests in {s}", .{zigFile});
|
|
|
|
const step = b.step(step_key, step_desc);
|
|
|
|
step.dependOn(&run_test.step);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const step_key = b.fmt("install_tests_{s}", .{dayString});
|
|
|
|
const step_desc = b.fmt("Install test_{s}.exe", .{dayString});
|
|
|
|
const step = b.step(step_key, step_desc);
|
|
|
|
step.dependOn(&install_test.step);
|
|
|
|
install_all_tests.dependOn(&install_test.step);
|
|
|
|
}
|
2020-11-26 22:46:03 +01:00
|
|
|
|
|
|
|
const run_cmd = exe.run();
|
|
|
|
run_cmd.step.dependOn(&install_cmd.step);
|
|
|
|
if (b.args) |args| {
|
|
|
|
run_cmd.addArgs(args);
|
|
|
|
}
|
|
|
|
|
2021-11-24 05:56:51 +01:00
|
|
|
const run_desc = b.fmt("Run {s}", .{dayString});
|
|
|
|
const run_step = b.step(dayString, run_desc);
|
2020-11-26 22:46:03 +01:00
|
|
|
run_step.dependOn(&run_cmd.step);
|
2021-11-24 05:56:51 +01:00
|
|
|
run_all.dependOn(&run_cmd.step);
|
2020-11-26 22:46:03 +01:00
|
|
|
}
|
|
|
|
|
2021-12-07 19:52:40 +01:00
|
|
|
// Set up tests for util.zig
|
|
|
|
{
|
|
|
|
const test_util = b.step("test_util", "Run tests in util.zig");
|
|
|
|
const test_cmd = b.addTest("src/util.zig");
|
2020-11-26 22:46:03 +01:00
|
|
|
test_cmd.setTarget(target);
|
|
|
|
test_cmd.setBuildMode(mode);
|
|
|
|
linkObject(b, test_cmd);
|
2021-12-07 19:52:40 +01:00
|
|
|
test_util.dependOn(&test_cmd.step);
|
|
|
|
}
|
2020-11-26 22:46:03 +01:00
|
|
|
|
2021-12-07 19:52:40 +01:00
|
|
|
// Set up test executable for util.zig
|
|
|
|
{
|
|
|
|
const test_util = b.step("install_tests_util", "Run tests in util.zig");
|
|
|
|
const test_exe = b.addTestExe("test_util", "src/util.zig");
|
|
|
|
test_exe.setTarget(target);
|
|
|
|
test_exe.setBuildMode(mode);
|
|
|
|
linkObject(b, test_exe);
|
|
|
|
const install = b.addInstallArtifact(test_exe);
|
|
|
|
test_util.dependOn(&install.step);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set up a step to run all tests
|
|
|
|
{
|
|
|
|
const test_step = b.step("test", "Run all tests");
|
|
|
|
const test_cmd = b.addTest("src/test_all.zig");
|
|
|
|
test_cmd.setTarget(target);
|
|
|
|
test_cmd.setBuildMode(mode);
|
|
|
|
linkObject(b, test_cmd);
|
2020-11-26 22:46:03 +01:00
|
|
|
test_step.dependOn(&test_cmd.step);
|
|
|
|
}
|
2021-12-07 19:52:40 +01:00
|
|
|
|
|
|
|
// Set up a step to build tests (but not run them)
|
|
|
|
{
|
|
|
|
const test_build = b.step("install_tests", "Install test_all.exe");
|
|
|
|
const test_exe = b.addTestExe("test_all", "src/test_all.zig");
|
|
|
|
test_exe.setTarget(target);
|
|
|
|
test_exe.setBuildMode(mode);
|
|
|
|
linkObject(b, test_exe);
|
|
|
|
const test_exe_install = b.addInstallArtifact(test_exe);
|
|
|
|
test_build.dependOn(&test_exe_install.step);
|
|
|
|
}
|
2020-11-26 22:46:03 +01:00
|
|
|
}
|