const std = @import("std");

pub fn build(b: *std.Build) void {
    const fetch_module = b.createModule(std.Build.Module.CreateOptions{
        .root_source_file = .{ .path = "fetch.zig" },
    });

    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    const exe = b.addExecutable(std.Build.ExecutableOptions{
        .name = "aoc2023",
        .root_source_file = std.Build.LazyPath{ .path = "src/main.zig" },
        .target = target,
        .optimize = optimize,
    });
    exe.root_module.addImport("fetch", fetch_module);
    b.installArtifact(exe);

    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("run", "Run all solver");
    run_step.dependOn(&run_cmd.step);

    const exe_tests = b.addTest(std.Build.TestOptions{
        .root_source_file = std.Build.LazyPath{ .path = "src/main.zig" },
        .target = target,
        .optimize = optimize,
    });

    const test_cmd = b.addRunArtifact(exe_tests);

    const test_step = b.step("test", "Run unit tests");
    test_step.dependOn(&test_cmd.step);
}