fix(trace): make ?trace= work by merging Module.ENV in the glue

The emscripten glue's `var ENV = {};` never merged Module.ENV, so boot.ts's
Module.ENV.KICAD_TRACE was a silent no-op — and since environ_get on a pthread
proxies to the main thread, the app/UI thread's getenv read the (empty) main
ENV. Net: KICAD_TRACE never arrived and every KI_TRACE was a no-op.

scripts/common/patch-env-shim.mjs post-processes each generated <app>.js to
merge Module.ENV into ENV (idempotent; runtime no-op when unset), wired into
docker/build.sh's per-app host post-process next to the dyncall-shim inject.
Replaces a fragile manual glue edit re-applied after every build. Verified:
symbol-editor eager load now emits KI_TRACE_SYM_CHOOSER fatLoad timing.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Gergő Törcsvári 2026-07-01 11:01:10 +02:00
commit 89a433fda9
No known key found for this signature in database
GPG key ID: 8E75F2CDE64E5322
3 changed files with 69 additions and 3 deletions

View file

@ -266,6 +266,13 @@ postprocess_app() {
kw_stage dyncall-shims
./scripts/common/inject-dyncall-shims.sh "${out_dir}/${app}.js"
# Merge Module.ENV into the runtime ENV: the emscripten glue never merges it,
# so ?trace= (boot.ts sets Module.ENV.KICAD_TRACE) was a silent no-op —
# environ_get on the app pthread proxies to the main thread, whose ENV stayed
# empty. Replaces a manual per-build glue edit. Idempotent; runtime no-op when
# Module.ENV is unset. See docs/features/libs/0013.
node ./scripts/common/patch-env-shim.mjs "${out_dir}/${app}.js"
# Apply wasm-emscripten-finalize on host (skipped in Docker due to memory limits)
kw_stage finalize
./scripts/common/apply-finalize.sh "${out_dir}/${app}.wasm" "${out_dir}/${app}.wasm"