chore: update run step

This commit is contained in:
Nurul Huda (Apon) 2026-03-14 18:54:58 +06:00
parent ca64dae639
commit ff3260ab6d
No known key found for this signature in database
GPG key ID: 5D3F1DE2855A2F79
2 changed files with 24 additions and 16 deletions

View file

@ -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 = &.{

View file

@ -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) {
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);
} else {
const run_cmd = b.addRunArtifact(exe);
},
.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);
},
}
}