2026-06-29 19:50:18 +02:00
|
|
|
#!/bin/bash
|
2026-06-30 11:55:52 +02:00
|
|
|
# Build the host post-process Binaryen tools from our submodule: wasm-opt (with the
|
|
|
|
|
# catch-arm-hoisting pass, --hoist-cpp-catches) AND wasm-emscripten-finalize.
|
2026-06-29 19:50:18 +02:00
|
|
|
#
|
|
|
|
|
# Source of truth is the tracked Binaryen submodule (binaryen/, branch wasm-port =
|
|
|
|
|
# upstream version_130 + src/passes/HoistCppCatches.cpp). This configures an out-of-source
|
|
|
|
|
# build into the gitignored build-wasm/ tree and prints the wasm-opt path on stdout
|
2026-06-30 11:55:52 +02:00
|
|
|
# (build progress to stderr); wasm-emscripten-finalize lands next to it in the same bin/
|
|
|
|
|
# (apply-finalize.sh derives it from the wasm-opt dir). Building both from one submodule
|
|
|
|
|
# keeps finalize and asyncify on a single Binaryen version and removes the host emsdk
|
|
|
|
|
# dependency from the post-process. See docs/features/wasm-exceptions/06-spike-plan.md (Phase 1.5).
|
2026-06-29 19:50:18 +02:00
|
|
|
set -eo pipefail
|
|
|
|
|
|
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
|
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
|
|
|
|
|
SRC="${PROJECT_ROOT}/binaryen"
|
|
|
|
|
BUILD="${PROJECT_ROOT}/build-wasm/tools/binaryen-hoist-build"
|
|
|
|
|
|
|
|
|
|
if [ ! -f "${SRC}/src/passes/HoistCppCatches.cpp" ]; then
|
|
|
|
|
echo "ERROR: binaryen submodule is missing the hoist pass." >&2
|
|
|
|
|
echo " Run: git submodule update --init binaryen" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2026-07-02 14:29:20 +02:00
|
|
|
# CI fast-path: the workflow cache-restores bin/ + lib/ keyed on the exact submodule
|
|
|
|
|
# SHA and sets this var on a hit, so the restored binaries are authoritative — skip
|
|
|
|
|
# cmake+ninja. Trust only if both tools actually RUN: the binaries dynamically link
|
|
|
|
|
# lib/libbinaryen.so, so an existence check alone passes on an incomplete restore
|
|
|
|
|
# (bin/ without lib/ shipped a red main, run 28585074335) while --version proves the
|
|
|
|
|
# loader resolves everything. Never set the var locally when iterating on the pass:
|
|
|
|
|
# uncommitted source edits would be silently ignored (the SHA key can't see them).
|
perf(ci): cache the per-run toolchain + test-app work (binaryen, emsdk, apps, browsers)
Four new caches in wasm-build.yml, keyed on their real inputs:
- Binaryen post-process tools (bin/ only, keyed on the submodule SHA): on a
hit BINARYEN_TRUST_PREBUILT=1 tells build-wasm-opt.sh to skip cmake+ninja
and trust the restored binaries (~46s/run). The guard is env-gated so local
pass iteration (uncommitted sources, same SHA) is unaffected.
- Built wx test apps (tests/apps minus kicad/ staging + gal-webgl/): skips
the whole build step on a hit (~3 min — the post-link hoist+asyncify over
~74 apps dominates). Key covers wx SHA + kicad SHA (some apps compile real
KiCad sources: thread_pool.cpp, libcontext), binaryen SHA, tracked app
sources, and the build/post-link scripts + shims. Gated on a wx cache HIT:
the app build creates the libwx_*.a symlinks the GAL link needs, so on a
wx rebuild the apps must rebuild too.
- Host emsdk (tools/emsdk, keyed on the pinned EMSCRIPTEN_VERSION): mostly
availability insurance — a fresh install is only ~23s but pulls ~340 MB
from github.com + storage.googleapis.com on every run. downloads/ tarballs
are pruned before the post-job save.
- Playwright browsers (~/.cache/ms-playwright keyed on tests/package-lock).
Warm-cache runs should drop from ~12 min to ~8-8.5 min (e2e suites are the
floor). Measured baselines from runs 28577824366 / 28520845242.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XeiSRRScdaox5jBueJNcyG
2026-07-02 12:40:22 +02:00
|
|
|
if [ "${BINARYEN_TRUST_PREBUILT:-0}" = "1" ] \
|
2026-07-02 14:29:20 +02:00
|
|
|
&& "${BUILD}/bin/wasm-opt" --version >/dev/null 2>&1 \
|
|
|
|
|
&& "${BUILD}/bin/wasm-emscripten-finalize" --version >/dev/null 2>&1; then
|
perf(ci): cache the per-run toolchain + test-app work (binaryen, emsdk, apps, browsers)
Four new caches in wasm-build.yml, keyed on their real inputs:
- Binaryen post-process tools (bin/ only, keyed on the submodule SHA): on a
hit BINARYEN_TRUST_PREBUILT=1 tells build-wasm-opt.sh to skip cmake+ninja
and trust the restored binaries (~46s/run). The guard is env-gated so local
pass iteration (uncommitted sources, same SHA) is unaffected.
- Built wx test apps (tests/apps minus kicad/ staging + gal-webgl/): skips
the whole build step on a hit (~3 min — the post-link hoist+asyncify over
~74 apps dominates). Key covers wx SHA + kicad SHA (some apps compile real
KiCad sources: thread_pool.cpp, libcontext), binaryen SHA, tracked app
sources, and the build/post-link scripts + shims. Gated on a wx cache HIT:
the app build creates the libwx_*.a symlinks the GAL link needs, so on a
wx rebuild the apps must rebuild too.
- Host emsdk (tools/emsdk, keyed on the pinned EMSCRIPTEN_VERSION): mostly
availability insurance — a fresh install is only ~23s but pulls ~340 MB
from github.com + storage.googleapis.com on every run. downloads/ tarballs
are pruned before the post-job save.
- Playwright browsers (~/.cache/ms-playwright keyed on tests/package-lock).
Warm-cache runs should drop from ~12 min to ~8-8.5 min (e2e suites are the
floor). Measured baselines from runs 28577824366 / 28520845242.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XeiSRRScdaox5jBueJNcyG
2026-07-02 12:40:22 +02:00
|
|
|
echo "Using prebuilt Binaryen tools (BINARYEN_TRUST_PREBUILT=1): ${BUILD}/bin" >&2
|
|
|
|
|
echo "${BUILD}/bin/wasm-opt"
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
2026-06-29 19:50:18 +02:00
|
|
|
# Configure once (mirrors scripts/common/get-wasm-opt.sh's from-source flags).
|
|
|
|
|
if [ ! -f "${BUILD}/build.ninja" ]; then
|
|
|
|
|
echo "Configuring Binaryen submodule build (one-time, ~5 min to build)..." >&2
|
|
|
|
|
cmake -S "${SRC}" -B "${BUILD}" -G Ninja \
|
|
|
|
|
-DCMAKE_BUILD_TYPE=Release \
|
|
|
|
|
-DCMAKE_CXX_FLAGS="-Wno-maybe-uninitialized" \
|
|
|
|
|
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON -DBUILD_TESTS=OFF >&2
|
|
|
|
|
fi
|
|
|
|
|
|
2026-06-30 11:55:52 +02:00
|
|
|
ninja -C "${BUILD}" wasm-opt wasm-emscripten-finalize >&2
|
2026-06-29 19:50:18 +02:00
|
|
|
|
|
|
|
|
echo "${BUILD}/bin/wasm-opt"
|