const std = @import("std"); const builtin = @import("builtin"); const zon = @import("build.zig.zon"); pub fn build(b: *std.Build) void { // Linux builds default to musl: static binaries with no dependency on the host's libc. const target = b.standardTargetOptions(.{ .default_target = if (builtin.os.tag == .linux) .{ .abi = .musl } else .{}, }); if (target.result.os.tag == .windows) b.fatal("zag does not support Windows (supported: Linux and macOS)", .{}); const optimize = b.standardOptimizeOption(.{}); const strip = b.option(bool, "strip", "Strip debug symbols from the binary") orelse false; const options = b.addOptions(); options.addOption([]const u8, "version", zon.version); // libc is linked for `localtime_r` (human-readable local timestamps). const mod = b.addModule("zag", .{ .root_source_file = b.path("src/root.zig"), .target = target, .optimize = optimize, .link_libc = true, }); mod.addOptions("build_options", options); const exe = b.addExecutable(.{ .name = "zag", .root_module = b.createModule(.{ .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, .link_libc = true, .strip = strip, .imports = &.{.{ .name = "zag", .module = mod }}, }), }); b.installArtifact(exe); const run_step = b.step("run", "Run zag"); 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); const e2e_step = b.step("e2e", "Run the end-to-end smoke test against the built binary"); const e2e = b.addSystemCommand(&.{ "bash", "test/e2e.sh" }); e2e.addArtifactArg(exe); e2e_step.dependOn(&e2e.step); const test_step = b.step("test", "Run tests"); test_step.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = mod })).step); test_step.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = exe.root_module })).step); }