From fb98b90b7da6d13594b0292b635cb85498583eb9 Mon Sep 17 00:00:00 2001 From: Mathias Magnusson Date: Mon, 1 Dec 2025 14:04:18 +0100 Subject: aoc2025: copy zig project from 2024 & upgrade to 0.15.2 --- aoc25/build.zig | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 aoc25/build.zig (limited to 'aoc25/build.zig') diff --git a/aoc25/build.zig b/aoc25/build.zig new file mode 100644 index 0000000..0032005 --- /dev/null +++ b/aoc25/build.zig @@ -0,0 +1,97 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + + const optimize = b.standardOptimizeOption(.{}); + + const generate_main = b.addExecutable(.{ + .name = "generate_main", + .root_module = b.createModule(.{ + .root_source_file = b.path("tools/generate_main.zig"), + .target = b.graph.host, + .optimize = optimize, + }), + }); + + const download_input = b.addExecutable(.{ + .name = "download_input", + .root_module = b.createModule(.{ + .root_source_file = b.path("tools/download_input.zig"), + .target = b.graph.host, + .optimize = optimize, + }), + }); + + for (1..13) |day| { + const run_download_input = b.addRunArtifact(download_input); + run_download_input.addArg(b.fmt("{}", .{day})); + const input_path = run_download_input.addOutputFileArg(b.fmt("{}.txt", .{day})); + const path = b.path(b.fmt("src/day{}.zig", .{day})); + + for ([_]usize{ 1, 2 }) |part| { + const name = b.fmt("day{}p{}", .{ day, part }); + + const run_generate_main = b.addRunArtifact(generate_main); + run_generate_main.addArg(b.fmt("{}", .{part})); + const main_path = run_generate_main.addOutputFileArg(b.fmt("{s}_main.zig", .{name})); + + const exe = b.addExecutable(.{ + .name = b.fmt("{s}", .{name}), + .root_module = b.createModule(.{ + .root_source_file = main_path, + .target = target, + .optimize = optimize, + }), + }); + exe.root_module.addAnonymousImport("solution", .{ + .root_source_file = path, + .target = target, + .optimize = optimize, + }); + exe.root_module.addAnonymousImport("input", .{ + .root_source_file = input_path, + .target = target, + .optimize = optimize, + }); + + const install_artifact = b.addInstallArtifact(exe, .{}); + const install_step = b.step(b.fmt("{s}-install", .{name}), b.fmt("Install {s} to the output directory", .{name})); + install_step.dependOn(&install_artifact.step); + + // This *creates* a Run step in the build graph, to be executed when another + // step is evaluated that depends on it. The next line below will establish + // such a dependency. + const run_cmd = b.addRunArtifact(exe); + + // This allows the user to pass arguments to the application in the build + // command itself, like this: `zig build run -- arg1 arg2 etc` + if (b.args) |args| { + run_cmd.addArgs(args); + } + + // This creates a build step. It will be visible in the `zig build --help` menu, + // and can be selected like this: `zig build run` + // This will evaluate the `run` step rather than the default, which is "install". + const run_step = b.step(name, b.fmt("Run {s}", .{name})); + run_step.dependOn(&run_cmd.step); + + const exe_unit_tests = b.addTest(.{ + .root_module = b.createModule(.{ + .root_source_file = path, + .target = target, + .optimize = optimize, + }), + .filters = &.{b.fmt("part{}", .{part})}, + }); + + const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests); + + // Similar to creating the run step earlier, this exposes a `test` step to + // the `zig build --help` menu, providing a way for the user to request + // running the unit tests. + const test_step = b.step(b.fmt("{s}-test", .{name}), b.fmt("Test {s}", .{name})); + test_step.dependOn(&run_exe_unit_tests.step); + } + } +} -- cgit v1.2.3