build.zig (2067B) - raw
1 const std = @import("std"); 2 3 pub fn build(b: *std.Build) void { 4 // Standard target options allows the person running `zig build` to choose 5 // what target to build for. Here we do not override the defaults, which 6 // means any target is allowed, and the default is native. Other options 7 // for restricting supported target set are available. 8 const target = b.standardTargetOptions(.{}); 9 10 // Standard release options allow the person running `zig build` to select 11 // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. 12 const optimize = b.standardOptimizeOption(.{}); 13 14 // Build options 15 const build_options_step = b.addOptions(); 16 17 const trace_value = b.option(bool, "trace", "enable tracing instructions for interpreter") orelse false; 18 build_options_step.addOption(bool, "TRACE", trace_value); 19 20 const debug_ops_value = b.option(bool, "debug-ops", "enable debug output for ops") orelse false; 21 build_options_step.addOption(bool, "DEBUG_OPS", debug_ops_value); 22 23 const stages = [_][]const u8{ 24 "og", 25 "opt1", 26 "opt2", 27 }; 28 29 const test_step = b.step("test", "Run unit tests"); 30 31 inline for (stages) |stage| { 32 var exe_mod = b.createModule(.{ 33 .root_source_file = b.path("src/" ++ stage ++ ".zig"), 34 .target = target, 35 .optimize = optimize, 36 }); 37 exe_mod.addOptions("build_options", build_options_step); 38 const exe = b.addExecutable(.{ 39 .name = stage, 40 .root_module = exe_mod, 41 }); 42 b.installArtifact(exe); 43 44 const run_cmd = b.addRunArtifact(exe); 45 run_cmd.step.dependOn(b.getInstallStep()); 46 if (b.args) |args| { 47 run_cmd.addArgs(args); 48 } 49 50 const run_step = b.step(stage, "Run " ++ stage); 51 run_step.dependOn(&run_cmd.step); 52 53 const exe_tests = b.addTest(.{ 54 .root_module = exe_mod, 55 }); 56 const run_exe_tests = b.addRunArtifact(exe_tests); 57 test_step.dependOn(&run_exe_tests.step); 58 } 59 }