diff options
Diffstat (limited to 'build.zig')
-rw-r--r-- | build.zig | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..14373c9 --- /dev/null +++ b/build.zig @@ -0,0 +1,61 @@ +//! Build recipe +const builtin = @import("builtin"); +const std = @import("std"); + +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const arch = target.cpu_arch orelse builtin.target.cpu.arch; + const optimize = b.standardOptimizeOption(.{}); + + const bin = b.addExecutable(.{ + .name = "roux", + .target = target, + .optimize = optimize, + .link_libc = true, + }); + const cflags = .{ + "-std=c99", "-g", "-Wall", "-Wextra", "-Wpedantic", + switch (target.os_tag orelse builtin.target.os.tag) { + .macos => switch (arch) { + .aarch64 => "-DDeftgt=T_arm64_apple", + .x86_64 => "-DDeftgt=T_amd64_apple", + else => unreachable, + }, + else => switch (arch) { + .aarch64 => "-DDeftgt=T_arm64", + .riscv64 => "-DDeftgt=T_rv64", + .x86_64 => "-DDeftgt=T_amd64_sysv", + else => unreachable, + }, + }, + // https://lists.sr.ht/~mpu/qbe/<CYB4FWK7MACC.2IF4DEL4C9BF1@loang.net> + "-fno-sanitize=undefined", + }; + bin.addIncludePath(.{ .path = "." }); + bin.addCSourceFiles(&.{ + "main.c", "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 unit_tests = b.addTest(.{ + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = optimize, + }); + + const run_unit_tests = b.addRunArtifact(unit_tests); + const test_step = b.step("test", "Run unit tests"); + test_step.dependOn(&run_unit_tests.step); +} |