summary refs log tree commit diff
path: root/build.zig
diff options
context:
space:
mode:
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig18
1 files changed, 13 insertions, 5 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, .{})) {