From 380206dcfc2be30751db3faec4396f7f8882a8ae Mon Sep 17 00:00:00 2001 From: Istvan Matejcsok <119620946+matejcsok-ee@users.noreply.github.com> Date: Thu, 11 Jun 2026 13:23:23 +0200 Subject: [PATCH] fix(build): host postprocess silently no-ops when emsdk tools are stubbed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit build-kicad-target.sh swaps emsdk's wasm-opt/wasm-emscripten-finalize for no-op stubs (real binaries preserved as *.real) so emcc skips in-link asyncify — intended for the CONTAINER emsdk, but a host-mode run left the host tools/emsdk stubbed (since Jun 9). The stub fakes --version and exits 0, so every local build's host-side finalize/asyncify/-O2 "succeeded" while doing nothing: output wasm shipped non-asyncified and aborts at boot with "asyncify_stop_unwind is not a function" (and stayed 122M vs the correct 187M). get-wasm-opt.sh and apply-finalize.sh now prefer the *.real binary whenever it exists, making the resolution immune to a stubbed emsdk. Found while validating the CI e2e fix: pcbnew.wasm built this morning could not boot in any browser. Local artifacts built since Jun 9 may need their postprocess re-run (apply-finalize.sh + apply-asyncify.sh). Co-Authored-By: Claude Fable 5 --- scripts/common/apply-finalize.sh | 6 ++++++ scripts/common/get-wasm-opt.sh | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/scripts/common/apply-finalize.sh b/scripts/common/apply-finalize.sh index 1f778c5..d4e8585 100755 --- a/scripts/common/apply-finalize.sh +++ b/scripts/common/apply-finalize.sh @@ -13,6 +13,12 @@ PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" WASM_OPT=$("${SCRIPT_DIR}/get-wasm-opt.sh") BINARYEN_BIN=$(dirname "${WASM_OPT}") FINALIZE="${BINARYEN_BIN}/wasm-emscripten-finalize" +# Same stub hazard as wasm-opt (see get-wasm-opt.sh): a host-mode kicad build +# leaves the emsdk finalize stubbed with the real binary at .real — prefer it, +# the stub exits 0 having done nothing. +if [ -x "${FINALIZE}.real" ]; then + FINALIZE="${FINALIZE}.real" +fi INPUT_WASM="${1:-output/pcbnew.wasm}" OUTPUT_WASM="${2:-${INPUT_WASM}}" diff --git a/scripts/common/get-wasm-opt.sh b/scripts/common/get-wasm-opt.sh index 1e9e9f7..6b33b3a 100755 --- a/scripts/common/get-wasm-opt.sh +++ b/scripts/common/get-wasm-opt.sh @@ -25,6 +25,15 @@ PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" # v130 (see docs/ci-build-slowness-findings.md). Validate any bump with the e2e # suite: a Binaryen/emsdk skew can corrupt asyncify metadata ("func is not a function"). EMSDK_WASM_OPT="${PROJECT_ROOT}/tools/emsdk/upstream/bin/wasm-opt" +# build-kicad-target.sh replaces emsdk's wasm-opt with a no-op stub (moving the +# real binary to wasm-opt.real) so emcc skips the in-link asyncify. That's meant +# for the container emsdk, but a host-mode run leaves the HOST emsdk stubbed — +# and the stub fakes --version and exits 0, so the host-side asyncify/-O2 +# "succeed" while doing NOTHING (broken wasm: "asyncify_stop_unwind is not a +# function"). Always prefer the preserved real binary when it exists. +if [ -x "${EMSDK_WASM_OPT}.real" ]; then + EMSDK_WASM_OPT="${EMSDK_WASM_OPT}.real" +fi if [ -z "${BINARYEN_VERSION:-}" ] && [ -x "${EMSDK_WASM_OPT}" ]; then EMSDK_VERSION=$("${EMSDK_WASM_OPT}" --version 2>&1 || true) echo "Using emsdk-bundled Binaryen: ${EMSDK_VERSION}" >&2