Skip to content

Commit cd8fdd2

Browse files
committed
build.zig: use Step.UpdateSourceFiles for zig1.wasm
We were already using this for `stage1/zig.h`, but `stage1/zig1.wasm` was being modified directly by the `wasm-opt` command. That's a bad idea because it forces the build system to assume that `wasm-opt` has side effects, so it is re-run every time you run `zig build update-zig1`, i.e. it does not interact with the cache system correctly. It is much better to create non-side-effecting `Run` steps (using `addOutput*Arg`) where possible so that the build system has a more correct understanding of the step graph.
1 parent bc78d8e commit cd8fdd2

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

build.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -678,14 +678,14 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
678678
});
679679
run_opt.addArtifactArg(exe);
680680
run_opt.addArg("-o");
681-
run_opt.addFileArg(b.path("stage1/zig1.wasm"));
681+
const optimized_wasm = run_opt.addOutputFileArg("zig1.wasm");
682682

683-
const copy_zig_h = b.addUpdateSourceFiles();
684-
copy_zig_h.addCopyFileToSource(b.path("lib/zig.h"), "stage1/zig.h");
683+
const update_zig1 = b.addUpdateSourceFiles();
684+
update_zig1.addCopyFileToSource(optimized_wasm, "stage1/zig1.wasm");
685+
update_zig1.addCopyFileToSource(b.path("lib/zig.h"), "stage1/zig.h");
685686

686687
const update_zig1_step = b.step("update-zig1", "Update stage1/zig1.wasm");
687-
update_zig1_step.dependOn(&run_opt.step);
688-
update_zig1_step.dependOn(&copy_zig_h.step);
688+
update_zig1_step.dependOn(&update_zig1.step);
689689
}
690690

691691
const AddCompilerModOptions = struct {

0 commit comments

Comments
 (0)