From ff3260ab6d2b142dc193359b6f473cdfd88e40a0 Mon Sep 17 00:00:00 2001 From: "Nurul Huda (Apon)" Date: Sat, 14 Mar 2026 18:54:58 +0600 Subject: [PATCH] chore: update run step --- build.zig | 9 ++++----- example/build.zig | 31 ++++++++++++++++++++----------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/build.zig b/build.zig index 68c8b41..5c6425a 100644 --- a/build.zig +++ b/build.zig @@ -20,14 +20,13 @@ pub fn build(b: *std.Build) !void { mod.addImport("temporal_rs", temporal.module("temporal_rs")); // --- Zig Executable: temporalz --- // - const exe_root = if (is_wasm_freestanding) - b.path("example/src/wasm.zig") - else - b.path("example/src/main.zig"); const exe = b.addExecutable(.{ .name = "temporalz", .root_module = b.createModule(.{ - .root_source_file = exe_root, + .root_source_file = if (is_wasm_freestanding) + b.path("example/src/wasm.zig") + else + b.path("example/src/main.zig"), .target = target, .optimize = optimize, .imports = &.{ diff --git a/example/build.zig b/example/build.zig index 357ae9f..2ff2227 100644 --- a/example/build.zig +++ b/example/build.zig @@ -3,7 +3,7 @@ const std = @import("std"); pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - const is_wasm = target.result.cpu.arch.isWasm(); + const is_wasm_freestanding = target.result.cpu.arch.isWasm() and target.result.os.tag == .freestanding; const temporalz = b.dependency("temporalz", .{ .target = target, @@ -12,7 +12,7 @@ pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ .name = "temporalz", .root_module = b.createModule(.{ - .root_source_file = b.path(if (is_wasm) "src/wasm.zig" else "src/main.zig"), + .root_source_file = b.path(if (is_wasm_freestanding) "src/wasm.zig" else "src/main.zig"), .target = target, .optimize = optimize, .imports = &.{}, @@ -22,14 +22,23 @@ pub fn build(b: *std.Build) void { b.installArtifact(exe); const run_step = b.step("run", "Run the app"); - if (is_wasm) { - const run_cmd = b.addSystemCommand(&.{ "node", "src/main.mjs" }); - run_cmd.step.dependOn(b.getInstallStep()); - run_step.dependOn(&run_cmd.step); - } else { - const run_cmd = b.addRunArtifact(exe); - run_step.dependOn(&run_cmd.step); - run_cmd.step.dependOn(b.getInstallStep()); - if (b.args) |args| run_cmd.addArgs(args); + switch (target.result.os.tag) { + .freestanding => { + const run_cmd = b.addSystemCommand(&.{ "node", "src/main.mjs" }); + run_cmd.step.dependOn(b.getInstallStep()); + run_step.dependOn(&run_cmd.step); + }, + .wasi => { + const run_cmd = b.addSystemCommand(&.{"wasmtime"}); + run_cmd.addFileArg(exe.getEmittedBin()); + run_cmd.step.dependOn(b.getInstallStep()); + run_step.dependOn(&run_cmd.step); + }, + else => { + const run_cmd = b.addRunArtifact(exe); + run_cmd.step.dependOn(b.getInstallStep()); + if (b.args) |args| run_cmd.addArgs(args); + run_step.dependOn(&run_cmd.step); + }, } }