2025-12-08 12:07:01 +01:00
|
|
|
#!/bin/bash
|
2025-12-13 22:13:31 +01:00
|
|
|
# Build KiCad WASM inside Docker container, then apply asyncify on host
|
|
|
|
|
#
|
|
|
|
|
# The build is split into two phases:
|
|
|
|
|
# 1. Docker: Compile KiCad to WASM (without asyncify)
|
|
|
|
|
# 2. Host: Apply asyncify transformation (uses Binaryen v121)
|
|
|
|
|
#
|
|
|
|
|
# Binaryen is downloaded automatically - no prerequisites needed.
|
|
|
|
|
|
2025-12-08 12:07:01 +01:00
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
cd "$(dirname "$0")/.."
|
|
|
|
|
|
2025-12-13 22:13:31 +01:00
|
|
|
# Get wasm-opt (downloads Binaryen v121 if not cached)
|
|
|
|
|
echo "Checking wasm-opt..."
|
|
|
|
|
WASM_OPT=$(./scripts/common/get-wasm-opt.sh)
|
|
|
|
|
echo "Using: ${WASM_OPT}"
|
|
|
|
|
|
2025-12-08 12:07:01 +01:00
|
|
|
# Start container if not running
|
|
|
|
|
docker compose -f docker/docker-compose.yml up -d
|
|
|
|
|
|
2025-12-13 22:13:31 +01:00
|
|
|
# Run build command (without asyncify - handled on host due to memory requirements)
|
2025-12-08 12:07:01 +01:00
|
|
|
docker compose -f docker/docker-compose.yml exec kicad-wasm-builder \
|
|
|
|
|
/workspace/scripts/kicad/build-pcbnew.sh "$@"
|
|
|
|
|
|
|
|
|
|
# Copy output to host-accessible directory
|
|
|
|
|
echo "Copying build output to ./output/..."
|
|
|
|
|
docker compose -f docker/docker-compose.yml exec kicad-wasm-builder \
|
2025-12-13 11:29:45 +01:00
|
|
|
bash -c "mkdir -p /workspace/output && cp /workspace/build-wasm/kicad-pcbnew/pcbnew/pcbnew.{js,wasm,wasm.map,worker.js} /workspace/output/ 2>/dev/null || cp /workspace/build-wasm/kicad-pcbnew/pcbnew/pcbnew.{js,wasm} /workspace/output/"
|
2025-12-08 12:07:01 +01:00
|
|
|
|
2025-12-13 22:13:31 +01:00
|
|
|
# Apply asyncify transformation on host
|
|
|
|
|
# This is done on the host because wasm-opt --asyncify needs 50GB+ RAM for KiCad,
|
|
|
|
|
# which exceeds typical Docker memory limits
|
|
|
|
|
echo ""
|
|
|
|
|
echo "Applying asyncify transformation on host..."
|
|
|
|
|
echo "This may take several minutes and use significant RAM..."
|
|
|
|
|
|
|
|
|
|
# Asyncify import patterns (functions that trigger async suspension)
|
|
|
|
|
# - env.invoke_* : Exception handling trampolines
|
|
|
|
|
# - env.__asyncjs__* : EM_ASYNC_JS functions
|
|
|
|
|
ASYNCIFY_IMPORTS="env.invoke_*,env.__asyncjs__*"
|
|
|
|
|
|
|
|
|
|
"${WASM_OPT}" --asyncify \
|
|
|
|
|
--pass-arg=asyncify-imports@${ASYNCIFY_IMPORTS} \
|
|
|
|
|
--pass-arg=asyncify-propagate-addlist \
|
|
|
|
|
output/pcbnew.wasm -o output/pcbnew.wasm
|
|
|
|
|
|
|
|
|
|
echo ""
|
2025-12-08 12:07:01 +01:00
|
|
|
echo "Build complete. Output files in ./output/"
|
2025-12-13 22:13:31 +01:00
|
|
|
ls -lh output/
|