//! Build recipe const Build = std.Build; const getExternalExecutor = std.zig.system.NativeTargetInfo.getExternalExecutor; const std = @import("std"); pub fn build(b: *Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const bin = b.addExecutable(.{ .name = "roux", .root_source_file = .{ .path = "src/main.zig" }, .target = target, .optimize = optimize, .link_libc = true, }); const cflags = .{ "-std=c99", "-g", "-Wall", "-Wextra", "-Wpedantic", // https://lists.sr.ht/~mpu/qbe/ "-fno-sanitize=undefined", }; bin.addIncludePath(.{ .path = "." }); bin.addCSourceFiles(&.{ "util.c", "parse.c", "abi.c", "cfg.c", "mem.c", "ssa.c", "alias.c", "load.c", "copy.c", "fold.c", "simpl.c", "live.c", "spill.c", "rega.c", "emit.c", }, &cflags); bin.addCSourceFiles(&.{ "amd64/targ.c", "amd64/sysv.c", "amd64/isel.c", "amd64/emit.c", "arm64/targ.c", "arm64/abi.c", "arm64/isel.c", "arm64/emit.c", "rv64/targ.c", "rv64/abi.c", "rv64/isel.c", "rv64/emit.c", }, &cflags); b.installArtifact(bin); const run_cmd = b.addRunArtifact(bin); run_cmd.step.dependOn(b.getInstallStep()); if (b.args) |args| run_cmd.addArgs(args); b.step("run", "Run the app").dependOn(&run_cmd.step); const tests = b.addTest(.{ .root_source_file = .{ .path = "src/test.zig" }, .optimize = optimize, .test_runner = "src/test.zig", }); const run_tests = b.addRunArtifact(tests); run_tests.addArg("-b"); run_tests.addArtifactArg(bin); run_tests.addArgs(&.{ "-z", b.zig_exe }); run_tests.addArgs(&.{ "-t", try target.zigTriple(b.allocator) }); switch (getExternalExecutor(tests.target_info, bin.target_info, .{})) { .qemu => |emulator| run_tests.addArgs(&.{ "-e", emulator }), else => {}, } if (b.args) |args| run_tests.addArgs(args); run_tests.has_side_effects = true; b.step("test", "Run unit tests").dependOn(&run_tests.step); }