From 2993072972ddacc8bc3c84e665db7ba421779c1c Mon Sep 17 00:00:00 2001 From: agra Date: Wed, 27 May 2026 17:08:14 +0300 Subject: [PATCH] main: "--- build done ---" delimiter on stderr for top-level #run MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tests that exercise top-level #run produce two interleaved output streams: the interp's #run prints (flushed via std.debug.print → stderr at core.zig:187/190) and the JIT- executed main's prints (libc write fd=1 → stdout). When the test runner captures both via 2>&1 the boundary between them is invisible — the snapshot reads as one block. Now `sx run` emits "--- build done ---\n" on stderr right before invoking the JIT, when `hasTopLevelRun(root)` is true. Tests without top-level #run keep their current snapshots unchanged; only the 7 affected tests pick up the delimiter between the build-time and run-time sections. Example: 05-run flips from hello 25 hello 25 to hello 25 --- build done --- hello 25 — the first "hello 25" is from `#run main()` running at compile time, the second is from JIT main() running at runtime. The delimiter makes that explicit. 204/204 example tests + `zig build test` green. --- src/main.zig | 9 +++++++++ tests/expected/05-run.txt | 1 + tests/expected/115-post-link-callback.txt | 1 + tests/expected/119-interp-cast-ptr-cmp.txt | 1 + tests/expected/120-interp-variadic-any.txt | 1 + tests/expected/121-ios-sim-bundle.txt | 1 + tests/expected/38-build-config.txt | 1 + tests/expected/65-add-framework.txt | 2 +- 8 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main.zig b/src/main.zig index 769e809..6b24d66 100644 --- a/src/main.zig +++ b/src/main.zig @@ -283,6 +283,15 @@ pub fn main(init: std.process.Init) !void { // JIT from precompiled object (relocation only, no IR compilation) sx.llvm_api.initNativeTarget(); timer.mark(); + // Phase separator: emit a clear delimiter between any #run output + // (which prints via the interp to stderr) and the JIT-executed + // main's runtime output (which writes to stdout). Without this, + // test logs and human-eye reads interleave compile-time and + // run-time output ambiguously. Only when top-level #run exists — + // pure-runtime tests keep their current snapshots. + if (hasTopLevelRun(root)) { + std.debug.print("--- build done ---\n", .{}); + } const exit_code = sx.target.runJITFromObject(obj_buf) catch { // JIT failed — fall back to AOT timer.record("jit-fail"); diff --git a/tests/expected/05-run.txt b/tests/expected/05-run.txt index 39e6780..bdbd4ed 100644 --- a/tests/expected/05-run.txt +++ b/tests/expected/05-run.txt @@ -1,2 +1,3 @@ hello 25 +--- build done --- hello 25 diff --git a/tests/expected/115-post-link-callback.txt b/tests/expected/115-post-link-callback.txt index 6ce5eca..288e060 100644 --- a/tests/expected/115-post-link-callback.txt +++ b/tests/expected/115-post-link-callback.txt @@ -1 +1,2 @@ +--- build done --- runtime main diff --git a/tests/expected/119-interp-cast-ptr-cmp.txt b/tests/expected/119-interp-cast-ptr-cmp.txt index b35b8e2..a368de4 100644 --- a/tests/expected/119-interp-cast-ptr-cmp.txt +++ b/tests/expected/119-interp-cast-ptr-cmp.txt @@ -1 +1,2 @@ +--- build done --- rt diff --git a/tests/expected/120-interp-variadic-any.txt b/tests/expected/120-interp-variadic-any.txt index b35b8e2..a368de4 100644 --- a/tests/expected/120-interp-variadic-any.txt +++ b/tests/expected/120-interp-variadic-any.txt @@ -1 +1,2 @@ +--- build done --- rt diff --git a/tests/expected/121-ios-sim-bundle.txt b/tests/expected/121-ios-sim-bundle.txt index 2e90bae..7a3d5ce 100644 --- a/tests/expected/121-ios-sim-bundle.txt +++ b/tests/expected/121-ios-sim-bundle.txt @@ -1 +1,2 @@ +--- build done --- ios-sim runtime main diff --git a/tests/expected/38-build-config.txt b/tests/expected/38-build-config.txt index c7e4b60..c06da6c 100644 --- a/tests/expected/38-build-config.txt +++ b/tests/expected/38-build-config.txt @@ -1,3 +1,4 @@ +--- build done --- build config: ok pointer size: 8 os: macos diff --git a/tests/expected/65-add-framework.txt b/tests/expected/65-add-framework.txt index 8b13789..cda3766 100644 --- a/tests/expected/65-add-framework.txt +++ b/tests/expected/65-add-framework.txt @@ -1 +1 @@ - +--- build done ---