2025-11-28 13:10:05 +01:00
|
|
|
#!/bin/bash
|
2025-11-29 16:19:13 +01:00
|
|
|
# Build the wxWidgets WASM test applications
|
2026-01-03 11:55:54 +01:00
|
|
|
|
|
|
|
|
# Redirect all output to a log file (re-execs script with redirection)
|
|
|
|
|
source "$(dirname "$0")/common/logging.sh"
|
perf(build): use all cores in host builds — wx lib, test apps, gal-webgl
env.sh exports a docker-safe JOBS=1 default, and every host build silently
inherited it (the docker kicad path dodges it by passing -j explicitly):
- build-wx-wasm.sh: the intended "${JOBS:-nproc}" fallback sat BELOW the
env.sh source, so it was dead code — full wx builds ran make -j1 on the
Mac and on CI. Compute the all-cores default before env.sh instead
(explicit JOBS/PARALLEL_JOBS still wins); also -j the PCRE pre-build.
- build-wasm-test.sh: same default fix, plus fan the post-link
hoist+asyncify loop out across JOBS with xargs -P. Per-app wasm-opt
can't feed many cores (small modules), so serial stays ~4min even with
BINARYEN_CORES=16; fanning across the 74 independent apps is what
scales. Safe: apply-asyncify is in-place per wasm, injector tmp is
per-js, HOIST_WASMOPT resolved once up front.
- build-gal-webgl-test.sh: make had no -j at all.
Measured on a 16-core M4 Max, clean test-app build: 15m36s (-j1) → 2m08s,
peak RAM 10.7 GB summed across all build processes (64 GB machine; CI
runners have 120 GB). Core counts are always derived from nproc at
runtime — nothing hardcoded, CI workers differ.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XeiSRRScdaox5jBueJNcyG
2026-07-02 10:54:14 +02:00
|
|
|
# Default to all cores BEFORE env.sh (its docker-safe JOBS=1 default would stick
|
|
|
|
|
# otherwise); an explicit JOBS/PARALLEL_JOBS from the caller still wins. Measured
|
|
|
|
|
# 2026-07-02 (16-core M4 Max): clean build 15m36s at -j1 → ~2min, peak RAM ~11 GB.
|
|
|
|
|
JOBS="${JOBS:-$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)}"
|
2026-01-10 21:24:51 +01:00
|
|
|
source "$(dirname "$0")/common/env.sh"
|
2025-11-29 16:19:13 +01:00
|
|
|
# This script creates library symlinks and builds the test apps
|
2025-11-29 22:15:56 +01:00
|
|
|
#
|
|
|
|
|
# Usage:
|
2025-12-27 11:26:25 +01:00
|
|
|
# ./build-wasm-test.sh # Incremental build (default)
|
|
|
|
|
# ./build-wasm-test.sh --clean # Clean build from scratch
|
|
|
|
|
# ./build-wasm-test.sh --debug # Build with debug symbols
|
|
|
|
|
# ./build-wasm-test.sh menu # Build only the menu test
|
|
|
|
|
# ./build-wasm-test.sh --debug menu # Build menu test with debug symbols
|
2025-11-28 13:10:05 +01:00
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
2025-11-29 22:15:56 +01:00
|
|
|
DEBUG_BUILD=0
|
2025-12-27 11:26:25 +01:00
|
|
|
CLEAN_BUILD=0
|
2025-12-15 11:47:50 +01:00
|
|
|
TARGET=""
|
|
|
|
|
|
|
|
|
|
# Parse arguments
|
2025-11-29 22:15:56 +01:00
|
|
|
for arg in "$@"; do
|
|
|
|
|
if [ "$arg" = "--debug" ]; then
|
|
|
|
|
DEBUG_BUILD=1
|
2025-12-27 11:26:25 +01:00
|
|
|
elif [ "$arg" = "--clean" ]; then
|
|
|
|
|
CLEAN_BUILD=1
|
2025-12-15 11:47:50 +01:00
|
|
|
elif [ "$arg" != "" ]; then
|
|
|
|
|
TARGET="$arg"
|
2025-11-29 22:15:56 +01:00
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
2025-11-28 13:10:05 +01:00
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
|
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
|
|
|
|
TESTS_DIR="$PROJECT_ROOT/tests"
|
2026-06-10 17:17:57 +02:00
|
|
|
|
2026-06-12 10:18:16 +02:00
|
|
|
BUILD_DIR="$PROJECT_ROOT/build-wasm/wxwidgets"
|
|
|
|
|
WASM_APP_DIR="$TESTS_DIR/apps"
|
2025-11-29 16:19:13 +01:00
|
|
|
STANDALONE_DIR="$WASM_APP_DIR/standalone"
|
2025-11-28 13:10:05 +01:00
|
|
|
|
2025-11-29 16:19:13 +01:00
|
|
|
echo "=== Building wxWidgets WASM Test Applications ==="
|
2025-11-29 22:15:56 +01:00
|
|
|
if [ "$DEBUG_BUILD" = "1" ]; then
|
|
|
|
|
echo "Mode: DEBUG (with DWARF symbols and source maps)"
|
|
|
|
|
else
|
|
|
|
|
echo "Mode: Release (optimized)"
|
|
|
|
|
fi
|
2025-12-15 11:47:50 +01:00
|
|
|
if [ -n "$TARGET" ]; then
|
|
|
|
|
echo "Target: $TARGET"
|
|
|
|
|
else
|
|
|
|
|
echo "Target: all"
|
|
|
|
|
fi
|
2025-11-28 13:10:05 +01:00
|
|
|
echo "Project root: $PROJECT_ROOT"
|
|
|
|
|
echo "wxWidgets build: $BUILD_DIR"
|
|
|
|
|
echo "Test app dir: $WASM_APP_DIR"
|
|
|
|
|
|
|
|
|
|
# Verify wxWidgets is built
|
|
|
|
|
if [ ! -f "$BUILD_DIR/wx-config" ]; then
|
2026-06-12 10:18:16 +02:00
|
|
|
echo "ERROR: wxWidgets not built. Run build-wx-wasm.sh first"
|
2025-11-28 13:10:05 +01:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Create library symlinks
|
|
|
|
|
# wx-config outputs paths like libwx_baseu-3.2.a but files are named libwx_baseu-3.2-emscripten.a
|
|
|
|
|
echo ""
|
|
|
|
|
echo "=== Creating library symlinks ==="
|
|
|
|
|
cd "$BUILD_DIR/lib"
|
|
|
|
|
for f in libwx_*-emscripten.a; do
|
|
|
|
|
if [ -f "$f" ]; then
|
|
|
|
|
link="${f%-emscripten.a}.a"
|
|
|
|
|
if [ ! -e "$link" ]; then
|
|
|
|
|
ln -s "$f" "$link"
|
|
|
|
|
echo "Created: $link -> $f"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
2025-11-29 16:19:13 +01:00
|
|
|
# Build the test apps
|
2025-11-28 13:10:05 +01:00
|
|
|
echo ""
|
2025-11-29 16:19:13 +01:00
|
|
|
echo "=== Building test applications ==="
|
2025-11-28 13:10:05 +01:00
|
|
|
cd "$WASM_APP_DIR"
|
|
|
|
|
|
2025-12-27 11:26:25 +01:00
|
|
|
# Determine make target
|
2025-12-15 11:47:50 +01:00
|
|
|
if [ -n "$TARGET" ]; then
|
|
|
|
|
MAKE_TARGET="$TARGET"
|
|
|
|
|
else
|
|
|
|
|
MAKE_TARGET="all"
|
2025-12-27 11:26:25 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Clean if requested
|
|
|
|
|
if [ "$CLEAN_BUILD" = "1" ]; then
|
|
|
|
|
echo "Cleaning build artifacts..."
|
2025-12-15 11:47:50 +01:00
|
|
|
make -f Makefile.wasm clean 2>/dev/null || true
|
|
|
|
|
fi
|
2025-11-28 13:10:05 +01:00
|
|
|
|
jspi: retire the asyncify pipeline — knob, post-link tail, binaryen hooks
Phase 8 in the parent repo. Deleted: asyncify-scheduler.js, apply-asyncify.sh,
apply-finalize.sh, inject-dyncall-shims.sh, asyncify-imports/removelist.txt,
the wasm-opt/finalize stub pair, scripts/binaryen-hoist-pass/ (the fork stays
a dormant submodule; removal is a follow-up), bench/wasm-opt-bench.sh (README
marked historical), wasm/shims/context_sleep.cpp, and the sched-context
harness app + Makefile targets.
PCBJAM_ASYNC_BACKEND is gone: build-wx-wasm.sh hardcodes the jspi stamp
(still force-cleans pre-migration trees), build-kicad-target.sh gives editors
the JSPI link surface and the CLIs nothing (they pin ASYNCIFY=0), the stub
dance is replaced by an unconditional .real-restore, build-wasm-test.sh lost
its whole post-link loop, docker/build.sh's postprocess is the ENV shim only,
and Makefile.wasm links every app JSPI with the scheduler shim as a tracked
prerequisite. pcbjam_async_policy.h keys on __EMSCRIPTEN__.
jspi-scheduler.js: wxWasmMainLoopPump dropped from the wrap census (the
export died with the D5 detach); inert [TRACE] instrumentation removed.
CI: wasm-build.yml rewritten for the single-cache pipeline (one output cache
keyed on compile inputs; post-processed bytes cached after the shim);
opt_level input removed from both callers. wasm-cache-hash.mjs inputs now
cover patch-env-shim.mjs + jspi-scheduler.js + jspi-exports.txt.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NDeBaKKhQztd8KiVtHuyXr
2026-08-13 08:39:12 +02:00
|
|
|
# JSPI: no binaryen instrumentation exists — no fork build, no stub dance, no
|
|
|
|
|
# post-link pass, no shim injection (the jspi-scheduler ships as a --pre-js
|
|
|
|
|
# from Makefile.wasm). emcc's real wasm-opt runs in-link like any normal build.
|
2026-06-29 19:50:18 +02:00
|
|
|
|
2026-06-10 22:00:34 +02:00
|
|
|
# Build (pass DEBUG flag if requested). App links are independent, so honor
|
jspi: retire the asyncify pipeline — knob, post-link tail, binaryen hooks
Phase 8 in the parent repo. Deleted: asyncify-scheduler.js, apply-asyncify.sh,
apply-finalize.sh, inject-dyncall-shims.sh, asyncify-imports/removelist.txt,
the wasm-opt/finalize stub pair, scripts/binaryen-hoist-pass/ (the fork stays
a dormant submodule; removal is a follow-up), bench/wasm-opt-bench.sh (README
marked historical), wasm/shims/context_sleep.cpp, and the sched-context
harness app + Makefile targets.
PCBJAM_ASYNC_BACKEND is gone: build-wx-wasm.sh hardcodes the jspi stamp
(still force-cleans pre-migration trees), build-kicad-target.sh gives editors
the JSPI link surface and the CLIs nothing (they pin ASYNCIFY=0), the stub
dance is replaced by an unconditional .real-restore, build-wasm-test.sh lost
its whole post-link loop, docker/build.sh's postprocess is the ENV shim only,
and Makefile.wasm links every app JSPI with the scheduler shim as a tracked
prerequisite. pcbjam_async_policy.h keys on __EMSCRIPTEN__.
jspi-scheduler.js: wxWasmMainLoopPump dropped from the wrap census (the
export died with the D5 detach); inert [TRACE] instrumentation removed.
CI: wasm-build.yml rewritten for the single-cache pipeline (one output cache
keyed on compile inputs; post-processed bytes cached after the shim);
opt_level input removed from both callers. wasm-cache-hash.mjs inputs now
cover patch-env-shim.mjs + jspi-scheduler.js + jspi-exports.txt.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NDeBaKKhQztd8KiVtHuyXr
2026-08-13 08:39:12 +02:00
|
|
|
# JOBS/PARALLEL_JOBS from env.sh.
|
2025-11-29 22:15:56 +01:00
|
|
|
if [ "$DEBUG_BUILD" = "1" ]; then
|
2026-06-12 10:18:16 +02:00
|
|
|
make -j"${JOBS:-1}" -f Makefile.wasm DEBUG=1 "$MAKE_TARGET"
|
2025-11-29 22:15:56 +01:00
|
|
|
else
|
2026-06-12 10:18:16 +02:00
|
|
|
make -j"${JOBS:-1}" -f Makefile.wasm "$MAKE_TARGET"
|
2025-11-29 22:15:56 +01:00
|
|
|
fi
|
2026-06-29 19:50:18 +02:00
|
|
|
make_rc=$?
|
|
|
|
|
if [ "$make_rc" -ne 0 ]; then
|
|
|
|
|
echo "" >&2
|
jspi: retire the asyncify pipeline — knob, post-link tail, binaryen hooks
Phase 8 in the parent repo. Deleted: asyncify-scheduler.js, apply-asyncify.sh,
apply-finalize.sh, inject-dyncall-shims.sh, asyncify-imports/removelist.txt,
the wasm-opt/finalize stub pair, scripts/binaryen-hoist-pass/ (the fork stays
a dormant submodule; removal is a follow-up), bench/wasm-opt-bench.sh (README
marked historical), wasm/shims/context_sleep.cpp, and the sched-context
harness app + Makefile targets.
PCBJAM_ASYNC_BACKEND is gone: build-wx-wasm.sh hardcodes the jspi stamp
(still force-cleans pre-migration trees), build-kicad-target.sh gives editors
the JSPI link surface and the CLIs nothing (they pin ASYNCIFY=0), the stub
dance is replaced by an unconditional .real-restore, build-wasm-test.sh lost
its whole post-link loop, docker/build.sh's postprocess is the ENV shim only,
and Makefile.wasm links every app JSPI with the scheduler shim as a tracked
prerequisite. pcbjam_async_policy.h keys on __EMSCRIPTEN__.
jspi-scheduler.js: wxWasmMainLoopPump dropped from the wrap census (the
export died with the D5 detach); inert [TRACE] instrumentation removed.
CI: wasm-build.yml rewritten for the single-cache pipeline (one output cache
keyed on compile inputs; post-processed bytes cached after the shim);
opt_level input removed from both callers. wasm-cache-hash.mjs inputs now
cover patch-env-shim.mjs + jspi-scheduler.js + jspi-exports.txt.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NDeBaKKhQztd8KiVtHuyXr
2026-08-13 08:39:12 +02:00
|
|
|
echo "ERROR: make failed (exit $make_rc)." >&2
|
2026-06-29 19:50:18 +02:00
|
|
|
exit "$make_rc"
|
|
|
|
|
fi
|
|
|
|
|
|
2025-11-28 13:10:05 +01:00
|
|
|
echo ""
|
|
|
|
|
echo "=== Build complete ==="
|
2025-11-29 16:19:13 +01:00
|
|
|
|
2026-08-14 21:46:24 +02:00
|
|
|
# JSPI micro-harnesses (jspi-stack, jspi-coroutine): still on their ad-hoc
|
|
|
|
|
# per-directory build.sh scripts (Makefile.wasm wiring is the Phase 3 TODO).
|
|
|
|
|
# Without this the jspi/ Playwright suites 404 their built .mjs modules on any
|
|
|
|
|
# machine that never ran the scripts by hand — which is exactly what CI is.
|
|
|
|
|
if [ -z "$TARGET" ]; then
|
|
|
|
|
echo ""
|
|
|
|
|
echo "=== JSPI micro-harnesses ==="
|
|
|
|
|
for harness in jspi-stack jspi-coroutine; do
|
|
|
|
|
echo "Building $harness..."
|
|
|
|
|
"$STANDALONE_DIR/$harness/build.sh"
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
|
2025-12-15 11:47:50 +01:00
|
|
|
if [ -n "$TARGET" ]; then
|
|
|
|
|
# Show just the built target
|
|
|
|
|
echo ""
|
|
|
|
|
if [ -f "$STANDALONE_DIR/$TARGET/${TARGET}_test.html" ]; then
|
|
|
|
|
echo "Built: $TARGET"
|
|
|
|
|
ls -lh "$STANDALONE_DIR/$TARGET/${TARGET}_test.html"
|
|
|
|
|
elif [ -f "$WASM_APP_DIR/${TARGET}_test.html" ]; then
|
|
|
|
|
echo "Built: $TARGET"
|
|
|
|
|
ls -lh "$WASM_APP_DIR/${TARGET}_test.html"
|
2025-11-29 16:19:13 +01:00
|
|
|
else
|
2025-12-15 11:47:50 +01:00
|
|
|
echo "Warning: Expected output file not found"
|
2025-11-29 16:19:13 +01:00
|
|
|
fi
|
2025-12-15 11:47:50 +01:00
|
|
|
else
|
|
|
|
|
# Show all built targets
|
|
|
|
|
echo ""
|
|
|
|
|
echo "Main test app:"
|
|
|
|
|
ls -lh "$WASM_APP_DIR"/minimal_test.html 2>/dev/null || echo " (not built)"
|
|
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
|
echo "Standalone test apps:"
|
|
|
|
|
for test in menu clipboard filedialog layout aui toolbar grid dialog timer tree; do
|
|
|
|
|
if [ -f "$STANDALONE_DIR/$test/${test}_test.html" ]; then
|
|
|
|
|
echo " $test: OK"
|
|
|
|
|
ls -lh "$STANDALONE_DIR/$test/${test}_test.html"
|
|
|
|
|
else
|
|
|
|
|
echo " $test: (not built)"
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
fi
|
2025-11-28 13:10:05 +01:00
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
|
echo "To run the tests:"
|
|
|
|
|
echo " cd $TESTS_DIR"
|
|
|
|
|
echo " npm install"
|
|
|
|
|
echo " npm test"
|