fix(docker): Replace emsdk image with Ubuntu + emsdk from source

The Docker build used emscripten/emsdk:4.0.2-arm64 as base image but
env.sh couldn't find emsdk there, installing a second copy. The build
then applied wasm-opt/finalize stubs to the wrong emsdk (hardcoded
/emsdk/), so the real wasm-emscripten-finalize ran in Docker and got
OOM-killed.

- Use ubuntu:22.04 base with emsdk installed from source at /emsdk/
- Make stub paths dynamic via $EMSDK instead of hardcoded /emsdk/
- Skip local emsdk install in env.sh when $EMSDK is already active

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Viktor Vaczi 2026-03-19 12:44:26 +01:00
commit d557b21eac
3 changed files with 39 additions and 16 deletions

View file

@ -36,18 +36,26 @@ export WX_BUILD="$BUILD_ROOT/wxwidgets-universal"
# Emscripten settings
export EMSDK_QUIET=1
# Local emsdk: auto-install if missing, then source its environment
# The emsdk bundles its own Python, Node, and LLVM — no Homebrew needed
_EMSDK_DIR="$_KICAD_WASM_PROJECT_ROOT/tools/emsdk"
_EMSDK_ENV="$_EMSDK_DIR/emsdk_env.sh"
# Emscripten SDK setup
# If EMSDK is already set (e.g. Docker entrypoint sourced emsdk_env.sh), use it.
# Otherwise auto-install a local copy under tools/emsdk/.
if [ -n "$EMSDK" ] && [ -f "$EMSDK/emsdk_env.sh" ]; then
# emsdk already active (e.g., Docker entrypoint sourced it)
source "$EMSDK/emsdk_env.sh" 2>/dev/null
else
# Local emsdk: auto-install if missing, then source its environment
# The emsdk bundles its own Python, Node, and LLVM — no Homebrew needed
_EMSDK_DIR="$_KICAD_WASM_PROJECT_ROOT/tools/emsdk"
_EMSDK_ENV="$_EMSDK_DIR/emsdk_env.sh"
if [ ! -f "$_EMSDK_ENV" ]; then
echo "Emscripten SDK not found. Installing..."
"$_KICAD_WASM_SCRIPTS_DIR/setup-emsdk.sh"
fi
if [ ! -f "$_EMSDK_ENV" ]; then
echo "Emscripten SDK not found. Installing..."
"$_KICAD_WASM_SCRIPTS_DIR/setup-emsdk.sh"
fi
if [ -f "$_EMSDK_ENV" ]; then
source "$_EMSDK_ENV" 2>/dev/null
if [ -f "$_EMSDK_ENV" ]; then
source "$_EMSDK_ENV" 2>/dev/null
fi
fi
# Common compiler flags

View file

@ -181,7 +181,11 @@ log_info "Stub libraries built"
# Step 6.2: Replace Emscripten's wasm-opt with stub to bypass asyncify transformation
# This allows Emscripten to generate JS with Asyncify runtime, but we run the real
# wasm-opt --asyncify on the host where more RAM is available (needs 50GB+ for KiCad)
EMSDK_WASM_OPT="/emsdk/upstream/bin/wasm-opt"
if [ -z "${EMSDK}" ]; then
log_error "EMSDK environment variable is not set."
exit 1
fi
EMSDK_WASM_OPT="${EMSDK}/upstream/bin/wasm-opt"
if [ -f "${EMSDK_WASM_OPT}" ] && [ ! -f "${EMSDK_WASM_OPT}.real" ]; then
log_info "Backing up real wasm-opt..."
mv "${EMSDK_WASM_OPT}" "${EMSDK_WASM_OPT}.real"
@ -193,7 +197,7 @@ log_info "wasm-opt stub installed (asyncify will run on host)"
# Step 6.3: Replace wasm-emscripten-finalize with stub (same pattern as wasm-opt)
# This tool also OOMs on large WASM with debug symbols, so we run it on the host
EMSDK_FINALIZE="/emsdk/upstream/bin/wasm-emscripten-finalize"
EMSDK_FINALIZE="${EMSDK}/upstream/bin/wasm-emscripten-finalize"
if [ -f "${EMSDK_FINALIZE}" ] && [ ! -f "${EMSDK_FINALIZE}.real" ]; then
log_info "Backing up real wasm-emscripten-finalize..."
mv "${EMSDK_FINALIZE}" "${EMSDK_FINALIZE}.real"