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