build.zig

2.0 KB · raw

1const std = @import("std");23pub fn build(b: *std.Build) void {4    // When built by Kepr Builds, KEPR_TARGET carries the cross-compile triple5    // so the same command works across all platforms without shell expansion.6    const target = if (b.graph.environ_map.get("KEPR_TARGET")) |t|7        b.resolveTargetQuery(std.Target.Query.parse(8            .{ .arch_os_abi = t },9        ) catch std.Target.Query{})10    else11        b.standardTargetOptions(.{});12    const optimize = b.standardOptimizeOption(.{});1314    // VERSION file → build_options.version, accessible from version.zig.15    const version_raw = @embedFile("VERSION");16    const version = std.mem.trim(u8, version_raw, " \r\n\t");17    const options = b.addOptions();18    options.addOption([]const u8, "version", version);19    // Absolute path to README.md, baked in at build time so tests can read it20    // regardless of the cwd `zig build test` happens to run from. README.md21    // lives outside src/, so it can't be @embedFile'd from within the src/22    // module's package boundary.23    options.addOption([]const u8, "readme_path", b.pathJoin(&.{ b.build_root.path.?, "README.md" }));2425    const exe = b.addExecutable(.{26        .name = "nina",27        .root_module = b.createModule(.{28            .root_source_file = b.path("src/main.zig"),29            .target = target,30            .optimize = optimize,31        }),32    });33    exe.root_module.addOptions("build_options", options);34    b.installArtifact(exe);3536    const run_cmd = b.addRunArtifact(exe);37    run_cmd.step.dependOn(b.getInstallStep());38    if (b.args) |args| run_cmd.addArgs(args);39    const run_step = b.step("run", "Run nina");40    run_step.dependOn(&run_cmd.step);4142    const tests = b.addTest(.{43        .root_module = b.createModule(.{44            .root_source_file = b.path("src/main.zig"),45            .target = target,46            .optimize = optimize,47        }),48    });49    tests.root_module.addOptions("build_options", options);50    const test_step = b.step("test", "Run unit tests");51    test_step.dependOn(&b.addRunArtifact(tests).step);52}