aboutsummaryrefslogtreecommitdiff
path: root/examples/multi-step/build.zig
blob: f9a2d3d3b0bcfc174b997f09dd7f54e58f4d7b4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const std = @import("std");

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

    const lib_mod = b.addModule("multi_step", .{
        .root_source_file = b.path("src/lib.zig"),
        .target = target,
    });

    const exe = b.addExecutable(.{
        .name = "multi-step",
        .root_module = b.createModule(.{
            .root_source_file = b.path("src/main.zig"),
            .target = target,
            .optimize = optimize,
            .imports = &.{
                .{ .name = "multi_step", .module = lib_mod },
            },
        }),
    });
    b.installArtifact(exe);

    // ── Step: run ──────────────────────────────────────────────────────────────
    const run_cmd = b.addRunArtifact(exe);
    if (b.args) |args| run_cmd.addArgs(args);
    const run_step = b.step("run", "Build and run the multi-step demo");
    run_step.dependOn(&run_cmd.step);

    // ── Step: test ─────────────────────────────────────────────────────────────
    const lib_tests = b.addTest(.{ .root_module = lib_mod });
    const run_tests = b.addRunArtifact(lib_tests);
    const test_step = b.step("test", "Run all unit tests");
    test_step.dependOn(&run_tests.step);

    // ── Step: check-fmt (hyphenated) ───────────────────────────────────────────
    const fmt_check = b.addFmt(.{
        .paths = &.{ "src", "build.zig" },
        .check = true,
    });
    const fmt_step = b.step("check-fmt", "Verify source formatting without modifying files");
    fmt_step.dependOn(&fmt_check.step);

    // ── Step: gen-docs (hyphenated) ────────────────────────────────────────────
    const docs = b.addInstallDirectory(.{
        .source_dir = exe.getEmittedDocs(),
        .install_dir = .prefix,
        .install_subdir = "docs",
    });
    const docs_step = b.step("gen-docs", "Generate and install HTML documentation");
    docs_step.dependOn(&docs.step);

    // ── Step: run_server (underscore) ──────────────────────────────────────────
    const server_cmd = b.addRunArtifact(exe);
    server_cmd.addArg("--server");
    const server_step = b.step("run_server", "Run the executable in server mode");
    server_step.dependOn(&server_cmd.step);

    // ── Step: bench (short name, ReleaseFast) ──────────────────────────────────
    const bench_exe = b.addExecutable(.{
        .name = "bench",
        .root_module = b.createModule(.{
            .root_source_file = b.path("src/main.zig"),
            .target = target,
            .optimize = .ReleaseFast,
            .imports = &.{
                .{ .name = "multi_step", .module = lib_mod },
            },
        }),
    });
    const bench_cmd = b.addRunArtifact(bench_exe);
    bench_cmd.addArg("--bench");
    const bench_step = b.step("bench", "Build and run benchmarks (ReleaseFast)");
    bench_step.dependOn(&bench_cmd.step);

    // ── Step: release-macos (compound hyphenated, cross-compile) ───────────────
    const macos_target = b.resolveTargetQuery(.{
        .cpu_arch = .aarch64,
        .os_tag = .macos,
    });
    const release_exe = b.addExecutable(.{
        .name = "multi-step",
        .root_module = b.createModule(.{
            .root_source_file = b.path("src/main.zig"),
            .target = macos_target,
            .optimize = .ReleaseSmall,
            .imports = &.{
                .{ .name = "multi_step", .module = lib_mod },
            },
        }),
    });
    const release_install = b.addInstallArtifact(release_exe, .{});
    const release_step = b.step("release-macos", "Build a ReleaseSmall binary for aarch64-macos");
    release_step.dependOn(&release_install.step);
}