chore: passthrough target arg

This commit is contained in:
Nurul Huda (Apon) 2026-05-16 12:22:33 +06:00
parent 24001a8164
commit 122b4151d0
No known key found for this signature in database
GPG key ID: 5D3F1DE2855A2F79
2 changed files with 15 additions and 11 deletions

View file

@ -3,7 +3,7 @@ const std = @import("std");
pub fn build(b: *std.Build) !void { pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{}); const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{}); const optimize = b.standardOptimizeOption(.{});
const is_wasm_freestanding = target.result.cpu.arch.isWasm() and target.result.os.tag == .freestanding; const is_freestanding = target.result.os.tag == .freestanding;
const force_build_rust = b.option(bool, "build-rust", "Always build Rust library from source") orelse false; const force_build_rust = b.option(bool, "build-rust", "Always build Rust library from source") orelse false;
// --- Rust C ABI & Pre-built via temporal-rs subpackage --- // // --- Rust C ABI & Pre-built via temporal-rs subpackage --- //
@ -25,7 +25,7 @@ pub fn build(b: *std.Build) !void {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "temporalz", .name = "temporalz",
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.root_source_file = if (is_wasm_freestanding) .root_source_file = if (is_freestanding)
b.path("example/src/wasm.zig") b.path("example/src/wasm.zig")
else else
b.path("example/src/main.zig"), b.path("example/src/main.zig"),
@ -36,16 +36,20 @@ pub fn build(b: *std.Build) !void {
}, },
}), }),
}); });
exe.root_module.link_libc = !is_wasm_freestanding; exe.root_module.link_libc = !is_freestanding;
exe.rdynamic = is_wasm_freestanding; exe.rdynamic = is_freestanding;
b.installArtifact(exe); b.installArtifact(exe);
// --- Steps: Run --- // // --- Steps: Run --- //
{ {
const run_step = b.step("run", "Run the app"); const run_step = b.step("run", "Run the example project");
const run_cmd = b.addSystemCommand(&.{ b.graph.zig_exe, "build", "run" }); const run_cmd = b.addSystemCommand(&.{
b.graph.zig_exe,
"build",
"run",
b.fmt("-Dtarget={s}", .{try target.result.zigTriple(b.allocator)}),
});
run_cmd.setCwd(b.path("example")); run_cmd.setCwd(b.path("example"));
if (b.args) |args| run_cmd.addArgs(args); if (b.args) |args| run_cmd.addArgs(args);
run_step.dependOn(&run_cmd.step); run_step.dependOn(&run_cmd.step);
} }
@ -73,9 +77,9 @@ pub fn build(b: *std.Build) !void {
.mode = .simple, .mode = .simple,
}, },
}); });
mod_tests.root_module.link_libc = !is_wasm_freestanding; mod_tests.root_module.link_libc = !is_freestanding;
test_step.dependOn(&b.addRunArtifact(mod_tests).step); test_step.dependOn(&b.addRunArtifact(mod_tests).step);
if (!is_wasm_freestanding) { if (!is_freestanding) {
const exe_tests = b.addTest(.{ .root_module = exe.root_module }); const exe_tests = b.addTest(.{ .root_module = exe.root_module });
test_step.dependOn(&b.addRunArtifact(exe_tests).step); test_step.dependOn(&b.addRunArtifact(exe_tests).step);
} }

View file

@ -3,7 +3,7 @@ const std = @import("std");
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{}); const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{}); const optimize = b.standardOptimizeOption(.{});
const is_wasm_freestanding = target.result.cpu.arch.isWasm() and target.result.os.tag == .freestanding; const is_freestanding = target.result.os.tag == .freestanding;
const temporalz = b.dependency("temporalz", .{ const temporalz = b.dependency("temporalz", .{
.target = target, .target = target,
@ -12,7 +12,7 @@ pub fn build(b: *std.Build) void {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "temporalz", .name = "temporalz",
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.root_source_file = b.path(if (is_wasm_freestanding) "src/wasm.zig" else "src/main.zig"), .root_source_file = b.path(if (is_freestanding) "src/wasm.zig" else "src/main.zig"),
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
.imports = &.{}, .imports = &.{},