| 1 | const std = @import("std"); |
| 2 | const string = []const u8; |
| 3 | const builtin = @import("builtin"); |
| 4 | const deps = @import("./deps.zig"); |
| 5 | |
| 6 | pub fn build(b: *std.Build) void { |
| 7 | b.reference_trace = 256; |
| 8 | |
| 9 | const target = b.standardTargetOptions(.{}); |
| 10 | const mode = b.option(std.builtin.OptimizeMode, "mode", "") orelse .Debug; |
| 11 | const use_full_name = b.option(bool, "use-full-name", "") orelse false; |
| 12 | const with_arch_os = b.fmt("-{s}-{s}", .{ @tagName(target.result.cpu.arch), @tagName(target.result.os.tag) }); |
| 13 | const exe_name = b.fmt("{s}{s}", .{ "zigmod", if (use_full_name) with_arch_os else "" }); |
| 14 | const exe = b.addExecutable(.{ |
| 15 | .name = exe_name, |
| 16 | .root_module = b.createModule(.{ |
| 17 | .root_source_file = b.path("src/main.zig"), |
| 18 | .target = target, |
| 19 | .optimize = mode, |
| 20 | }), |
| 21 | }); |
| 22 | const tag = b.option(string, "tag", ""); |
| 23 | const strip = b.option(bool, "strip", "Build without debug info.") orelse false; |
| 24 | const disable_llvm = b.option(bool, "disable_llvm", "use the non-llvm zig codegen") orelse false; |
| 25 | _ = &disable_llvm; // macos can't mix the flags rn because it needs llvm but also can't use lld |
| 26 | |
| 27 | const exe_options = b.addOptions(); |
| 28 | exe.root_module.addImport("build_options", exe_options.createModule()); |
| 29 | exe_options.addOption(string, "version", tag orelse std.mem.trimEnd(u8, b.run(&.{ "git", "describe", "--tags" }), "\n")); |
| 30 | |
| 31 | deps.addAllTo(exe); |
| 32 | exe.root_module.linkSystemLibrary("c", .{}); |
| 33 | exe.root_module.strip = strip; |
| 34 | // exe.use_llvm = !disable_llvm; |
| 35 | // exe.use_lld = !disable_llvm; |
| 36 | b.installArtifact(exe); |
| 37 | |
| 38 | const run_cmd = b.addRunArtifact(exe); |
| 39 | run_cmd.step.dependOn(b.getInstallStep()); |
| 40 | if (b.args) |args| { |
| 41 | run_cmd.addArgs(args); |
| 42 | } |
| 43 | |
| 44 | const run_step = b.step("run", "Run the app"); |
| 45 | run_step.dependOn(&run_cmd.step); |
| 46 | |
| 47 | // |
| 48 | |
| 49 | const test_step = b.step("test", "Stub for ziginfra"); |
| 50 | test_step.dependOn(&exe.step); |
| 51 | } |