master
  1const std = @import("std");
  2const ConfigHeader = std.Build.Step.ConfigHeader;
  3
  4pub fn build(b: *std.Build) void {
  5    const config_header = b.addConfigHeader(
  6        .{
  7            .style = .{ .cmake = b.path("config.h.in") },
  8            .include_path = "config.h",
  9        },
 10        .{
 11            .noval = null,
 12            .trueval = true,
 13            .falseval = false,
 14            .zeroval = 0,
 15            .oneval = 1,
 16            .tenval = 10,
 17            .stringval = "test",
 18
 19            .boolnoval = void{},
 20            .booltrueval = true,
 21            .boolfalseval = false,
 22            .boolzeroval = 0,
 23            .booloneval = 1,
 24            .booltenval = 10,
 25            .boolstringval = "test",
 26        },
 27    );
 28
 29    const pwd_sh = b.addConfigHeader(
 30        .{
 31            .style = .{ .cmake = b.path("pwd.sh.in") },
 32            .include_path = "pwd.sh",
 33        },
 34        .{ .DIR = "${PWD}" },
 35    );
 36
 37    const sigil_header = b.addConfigHeader(
 38        .{
 39            .style = .{ .cmake = b.path("sigil.h.in") },
 40            .include_path = "sigil.h",
 41        },
 42        .{},
 43    );
 44
 45    const stack_header = b.addConfigHeader(
 46        .{
 47            .style = .{ .cmake = b.path("stack.h.in") },
 48            .include_path = "stack.h",
 49        },
 50        .{
 51            .AT = "@",
 52            .UNDERSCORE = "_",
 53            .NEST_UNDERSCORE_PROXY = "UNDERSCORE",
 54            .NEST_PROXY = "NEST_UNDERSCORE_PROXY",
 55        },
 56    );
 57
 58    const wrapper_header = b.addConfigHeader(
 59        .{
 60            .style = .{ .cmake = b.path("wrapper.h.in") },
 61            .include_path = "wrapper.h",
 62        },
 63        .{
 64            .DOLLAR = "$",
 65            .TEXT = "TRAP",
 66
 67            .STRING = "TEXT",
 68            .STRING_AT = "@STRING@",
 69            .STRING_CURLY = "{STRING}",
 70            .STRING_VAR = "${STRING}",
 71        },
 72    );
 73
 74    const check_exe = b.addExecutable(.{
 75        .name = "check",
 76        .root_module = b.createModule(.{
 77            .target = b.graph.host,
 78            .root_source_file = b.path("check.zig"),
 79        }),
 80    });
 81
 82    const test_step = b.step("test", "Test it");
 83    b.default_step = test_step;
 84    test_step.dependOn(addCheck(b, check_exe, config_header));
 85    test_step.dependOn(addCheck(b, check_exe, pwd_sh));
 86    test_step.dependOn(addCheck(b, check_exe, sigil_header));
 87    test_step.dependOn(addCheck(b, check_exe, stack_header));
 88    test_step.dependOn(addCheck(b, check_exe, wrapper_header));
 89}
 90
 91fn addCheck(
 92    b: *std.Build,
 93    check_exe: *std.Build.Step.Compile,
 94    ch: *ConfigHeader,
 95) *std.Build.Step {
 96    // We expect `ch.include_path` to only be a basename to infer where the expected output is.
 97    std.debug.assert(std.fs.path.dirname(ch.include_path) == null);
 98    const expected_path = b.fmt("expected_{s}", .{ch.include_path});
 99
100    const run_check = b.addRunArtifact(check_exe);
101    run_check.addFileArg(ch.getOutputFile());
102    run_check.addFileArg(b.path(expected_path));
103
104    return &run_check.step;
105}