summary refs log tree commit diff
diff options
context:
space:
mode:
authorNguyễn Gia Phong <cnx@loang.net>2024-03-08 13:34:24 +0900
committerNguyễn Gia Phong <cnx@loang.net>2024-03-08 13:34:24 +0900
commite2c0c65b769a42ae102972a80361d942b08a0d29 (patch)
tree935fd8bc456619d2e4e5020bbf2a81d52e382444
parent644b604af4b3535c1cc3208fada2a4909fca5a92 (diff)
downloadroux-main.tar.gz
Avoid building roux to test nonnative targets HEAD main
-rw-r--r--build.zig18
-rw-r--r--src/test.zig5
2 files changed, 14 insertions, 9 deletions
diff --git a/build.zig b/build.zig
index f869257..8fe6807 100644
--- a/build.zig
+++ b/build.zig
@@ -1,12 +1,12 @@
 //! Build recipe
 const Build = std.Build;
+const CompileStep = Build.CompileStep;
+const CrossTarget = std.zig.CrossTarget;
+const Mode = std.builtin.Mode;
 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(.{});
-
+fn addExecutable(b: *Build, target: CrossTarget, optimize: Mode) *CompileStep {
     const bin = b.addExecutable(.{
         .name = "roux",
         .root_source_file = .{ .path = "src/main.zig" },
@@ -30,6 +30,14 @@ pub fn build(b: *Build) !void {
         "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);
+    return bin;
+}
+
+pub fn build(b: *Build) !void {
+    const target = b.standardTargetOptions(.{});
+    const optimize = b.standardOptimizeOption(.{});
+
+    const bin = addExecutable(b, target, optimize);
     b.installArtifact(bin);
     const run_cmd = b.addRunArtifact(bin);
     run_cmd.step.dependOn(b.getInstallStep());
@@ -44,7 +52,7 @@ pub fn build(b: *Build) !void {
     });
     const run_tests = b.addRunArtifact(tests);
     run_tests.addArg("-b");
-    run_tests.addArtifactArg(bin);
+    run_tests.addArtifactArg(addExecutable(b, .{}, optimize));
     run_tests.addArgs(&.{ "-z", b.zig_exe });
     run_tests.addArgs(&.{ "-t", try target.zigTriple(b.allocator) });
     switch (getExternalExecutor(tests.target_info, bin.target_info, .{})) {
diff --git a/src/test.zig b/src/test.zig
index 04d7f00..cdd9805 100644
--- a/src/test.zig
+++ b/src/test.zig
@@ -232,10 +232,7 @@ fn check(ssa: []const u8) anyerror!void {
     const s = try joinPath(allocator, &.{ dir, "a.s" });
     defer allocator.free(s);
     const ir_loc = b: {
-        const ir = try collectOutput(if (emulator) |executor|
-            &.{ executor, bin, ssa }
-        else
-            &.{ bin, ssa });
+        const ir = try collectOutput(&.{ bin, "-t", qbe_target, ssa });
         errdefer allocator.free(ir);
         try tmp.parent_dir.writeFile(s, ir);
         break :b loc(ir);