Refine setup

This commit is contained in:
ktkk 2025-12-01 14:49:05 +00:00
parent f4670e510f
commit d64050a402
16 changed files with 4158 additions and 30 deletions

View file

@ -1,35 +1,33 @@
const std = @import("std");
const nr_of_days = 12;
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// TODO: This should be a non-exhaustive enum with one option: all
const day = b.option(u8, "day", "Build day") orelse 1;
const run_all = b.step("run", "Run all days");
// TODO: Depending on the day chosen, only that day should compile, or all days
const exe = addDay(b, target, optimize, day);
b.installArtifact(exe);
const day_option = b.option(usize, "day", "Build day");
// run step
const run_exe = b.addRunArtifact(exe);
const run_step = b.step("run", "Run the binary");
run_step.dependOn(&run_exe.step);
}
fn addDay(
b: *std.Build,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
day: u8,
) *std.Build.Step.Compile {
return b.addExecutable(.{
.name = "aoc2025",
.root_module = b.createModule(.{
.root_source_file = b.path(b.fmt("src/day_{d}.zig", .{day})),
.target = target,
.optimize = optimize,
}),
});
for (1..nr_of_days + 1) |day| {
const exe = b.addExecutable(.{
.name = b.fmt("run-day{d:0>2}", .{day}),
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
}),
});
exe.root_module.addAnonymousImport("day", .{
.root_source_file = b.path(b.fmt("src/days/day{d:0>2}.zig", .{day})),
});
b.installArtifact(exe);
if (day_option == null or day_option == day) {
const run_cmd = b.addRunArtifact(exe);
run_all.dependOn(&run_cmd.step);
}
}
}

View file

@ -1,5 +0,0 @@
const std = @import("std");
pub fn main() !void {
}

8
src/days/day01.zig Normal file
View file

@ -0,0 +1,8 @@
const std = @import("std");
pub const title = "Day 01: Secret Entrance";
pub fn run(_: std.mem.Allocator) !void {
const input = @embedFile("./input/day01.txt");
}

7
src/days/day02.zig Normal file
View file

@ -0,0 +1,7 @@
const std = @import("std");
pub const title = "Day 02";
pub fn run(_: std.mem.Allocator) !void {
}

7
src/days/day03.zig Normal file
View file

@ -0,0 +1,7 @@
const std = @import("std");
pub const title = "Day 03";
pub fn run(_: std.mem.Allocator) !void {
}

7
src/days/day04.zig Normal file
View file

@ -0,0 +1,7 @@
const std = @import("std");
pub const title = "Day 04";
pub fn run(_: std.mem.Allocator) !void {
}

7
src/days/day05.zig Normal file
View file

@ -0,0 +1,7 @@
const std = @import("std");
pub const title = "Day 05";
pub fn run(_: std.mem.Allocator) !void {
}

7
src/days/day06.zig Normal file
View file

@ -0,0 +1,7 @@
const std = @import("std");
pub const title = "Day 06";
pub fn run(_: std.mem.Allocator) !void {
}

7
src/days/day07.zig Normal file
View file

@ -0,0 +1,7 @@
const std = @import("std");
pub const title = "Day 07";
pub fn run(_: std.mem.Allocator) !void {
}

7
src/days/day08.zig Normal file
View file

@ -0,0 +1,7 @@
const std = @import("std");
pub const title = "Day 08";
pub fn run(_: std.mem.Allocator) !void {
}

7
src/days/day09.zig Normal file
View file

@ -0,0 +1,7 @@
const std = @import("std");
pub const title = "Day 09";
pub fn run(_: std.mem.Allocator) !void {
}

7
src/days/day10.zig Normal file
View file

@ -0,0 +1,7 @@
const std = @import("std");
pub const title = "Day 10";
pub fn run(_: std.mem.Allocator) !void {
}

7
src/days/day11.zig Normal file
View file

@ -0,0 +1,7 @@
const std = @import("std");
pub const title = "Day 11";
pub fn run(_: std.mem.Allocator) !void {
}

7
src/days/day12.zig Normal file
View file

@ -0,0 +1,7 @@
const std = @import("std");
pub const title = "Day 12";
pub fn run(_: std.mem.Allocator) !void {
}

4035
src/days/input/day01.txt Executable file

File diff suppressed because it is too large Load diff

15
src/main.zig Normal file
View file

@ -0,0 +1,15 @@
const std = @import("std");
const day = @import("day");
pub fn main() !void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = arena.allocator();
std.debug.print("{s}\n", .{day.title});
try day.run(allocator);
std.debug.print("\n", .{});
}