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")); mod.addImport("temporal_rs", temporal.module("temporal_rs"));
// --- Zig Executable: temporalz --- // // --- 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(.{ const exe = b.addExecutable(.{
.name = "temporalz", .name = "temporalz",
.root_module = b.createModule(.{ .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, .target = target,
.optimize = optimize, .optimize = optimize,
.imports = &.{ .imports = &.{

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 = 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", .{ 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) "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, .target = target,
.optimize = optimize, .optimize = optimize,
.imports = &.{}, .imports = &.{},
@ -22,14 +22,23 @@ pub fn build(b: *std.Build) void {
b.installArtifact(exe); b.installArtifact(exe);
const run_step = b.step("run", "Run the app"); const run_step = b.step("run", "Run the app");
if (is_wasm) { switch (target.result.os.tag) {
const run_cmd = b.addSystemCommand(&.{ "node", "src/main.mjs" }); .freestanding => {
run_cmd.step.dependOn(b.getInstallStep()); const run_cmd = b.addSystemCommand(&.{ "node", "src/main.mjs" });
run_step.dependOn(&run_cmd.step); run_cmd.step.dependOn(b.getInstallStep());
} else { run_step.dependOn(&run_cmd.step);
const run_cmd = b.addRunArtifact(exe); },
run_step.dependOn(&run_cmd.step); .wasi => {
run_cmd.step.dependOn(b.getInstallStep()); const run_cmd = b.addSystemCommand(&.{"wasmtime"});
if (b.args) |args| run_cmd.addArgs(args); 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);
},
} }
} }