Skip to content
zit Artifact [20fe82ab43]
Login

Artifact [20fe82ab43]

Artifact 20fe82ab431c8ed12a5ede5985d4e8f31b56883a0954d3b6b7874110fb6bdfb4:


const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    // The zit library: a Zig implementation of the Fossil formats and protocol
    // as specified by the four RFC drafts in docs/rfcs/.
    const mod = b.addModule("zit", .{
        .root_source_file = b.path("src/root.zig"),
        .target = target,
    });

    // The `zit` command-line tool.
    const exe = b.addExecutable(.{
        .name = "zit",
        .root_module = b.createModule(.{
            .root_source_file = b.path("src/main.zig"),
            .target = target,
            .optimize = optimize,
            .imports = &.{
                .{ .name = "zit", .module = mod },
            },
        }),
    });
    b.installArtifact(exe);

    // `zig build run -- <args>`
    const run_step = b.step("run", "Run the zit CLI");
    const run_cmd = b.addRunArtifact(exe);
    run_step.dependOn(&run_cmd.step);
    run_cmd.step.dependOn(b.getInstallStep());
    if (b.args) |args| run_cmd.addArgs(args);

    // `zig build test` — runs library + CLI unit tests.
    const test_step = b.step("test", "Run unit tests");

    const mod_tests = b.addTest(.{ .root_module = mod });
    test_step.dependOn(&b.addRunArtifact(mod_tests).step);

    const exe_tests = b.addTest(.{ .root_module = exe.root_module });
    test_step.dependOn(&b.addRunArtifact(exe_tests).step);

    // `zig build fuzz -- <target> [--seed N] [--rounds N]` — seeded deterministic
    // fuzz targets, driven in a loop by an out-of-band runner; not part of `test`.
    const fuzz_exe = b.addExecutable(.{
        .name = "fuzz",
        .root_module = b.createModule(.{
            .root_source_file = b.path("src/fuzz_tests.zig"),
            .target = target,
            .optimize = optimize,
            .imports = &.{.{ .name = "zit", .module = mod }},
        }),
    });
    const fuzz_step = b.step("fuzz", "Run a seeded fuzz target (zig build fuzz -- <target> --seed N)");
    const fuzz_run = b.addRunArtifact(fuzz_exe);
    if (b.args) |args| fuzz_run.addArgs(args);
    fuzz_step.dependOn(&fuzz_run.step);

    // `bench` and `smoke` are wired at later milestones (a benchmark suite,
    // and a bounded Fossil interop check run only at layer milestones); until
    // then they exist as named steps that fail loudly rather than silently
    // passing.
    const bench_step = b.step("bench", "Benchmarks");
    bench_step.dependOn(&b.addFail("bench: no benchmark exists yet").step);
    const smoke_step = b.step("smoke", "Fossil interop smoke check (milestone-manual)");
    smoke_step.dependOn(&b.addFail("smoke: wired at layer milestones only").step);
}