Skip to content
zit Artifact [d203a6eeb5]
Login

Artifact [d203a6eeb5]

Artifact d203a6eeb53fcf9447a94e921eb378a74026c33a2c9a6a606e05c0a5e348b76d:


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);

    // `zig build dst [-- --seed N | --seeds K] [--steps M]` — deterministic
    // simulation of the repostate derivation. No args runs the fixed smoke
    // sweep (seeds 1..25 x 10_000 steps); deep sweeps pass `--seeds`.
    const dst_exe = b.addExecutable(.{
        .name = "dst",
        .root_module = b.createModule(.{
            .root_source_file = b.path("src/dst.zig"),
            .target = target,
            .optimize = optimize,
            .imports = &.{.{ .name = "zit", .module = mod }},
        }),
    });
    const dst_step = b.step("dst", "Deterministic simulation (default smoke sweep; zig build dst -- --seed N)");
    const dst_run = b.addRunArtifact(dst_exe);
    if (b.args) |args| dst_run.addArgs(args);
    dst_step.dependOn(&dst_run.step);

    // `bench` is wired at a later milestone (a benchmark suite); until then
    // it exists as a named step that fails loudly rather than silently
    // passing.
    const bench_step = b.step("bench", "Benchmarks");
    bench_step.dependOn(&b.addFail("bench: no benchmark exists yet").step);

    // `zig build smoke` — the one sanctioned use of the real `fossil` binary:
    // confirms zit-produced artifacts/deltas against fossil's own
    // parser/hasher/store. Confined to this step; never part of `test` or
    // pre-commit. `zig build test` still compiles smoke.zig (catching type
    // errors) without running its fossil-driving scenarios.
    const smoke_exe = b.addExecutable(.{
        .name = "smoke",
        .root_module = b.createModule(.{
            .root_source_file = b.path("src/smoke.zig"),
            .target = target,
            .optimize = optimize,
            .imports = &.{.{ .name = "zit", .module = mod }},
        }),
    });
    test_step.dependOn(&smoke_exe.step);

    const smoke_step = b.step("smoke", "Fossil interop smoke check (milestone-manual)");
    const smoke_run = b.addRunArtifact(smoke_exe);
    if (b.args) |args| smoke_run.addArgs(args);
    smoke_step.dependOn(&smoke_run.step);
}