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-15 11:47:50 +01:00
|
|
|
# Add -j 10 by default if no -j flag is given
|
|
|
|
|
ARGS=("$@")
|
|
|
|
|
if [[ ! " ${ARGS[*]} " =~ " -j " ]]; then
|
|
|
|
|
ARGS+=("-j" "10")
|
|
|
|
|
fi
|
|
|
|
|
|
2025-12-08 12:07:01 +01:00
|
|
|
# Start container if not running
|
|
|
|
|
docker compose -f docker/docker-compose.yml up -d
|
|
|
|
|
|
2025-12-27 01:07:44 +01:00
|
|
|
# Sync source code to container volume (fixes macOS Docker timestamp issues)
|
|
|
|
|
# This ensures timestamps are consistent within the container filesystem
|
|
|
|
|
echo "Syncing source code to container..."
|
|
|
|
|
docker compose -f docker/docker-compose.yml exec kicad-wasm-builder \
|
|
|
|
|
rsync -a --delete --exclude='build-wasm' --exclude='output' /workspace-host/ /workspace/
|
|
|
|
|
|
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 \
|
2025-12-15 11:47:50 +01:00
|
|
|
/workspace/scripts/kicad/build-pcbnew.sh "${ARGS[@]}"
|
2025-12-08 12:07:01 +01:00
|
|
|
|
|
|
|
|
# Copy output to host-accessible directory
|
2025-12-22 16:30:53 +01:00
|
|
|
# Note: pcbnew.wasm.debug.wasm contains DWARF debug info (generated with -gseparate-dwarf)
|
2025-12-08 12:07:01 +01:00
|
|
|
echo "Copying build output to ./output/..."
|
|
|
|
|
docker compose -f docker/docker-compose.yml exec kicad-wasm-builder \
|
2025-12-22 16:30:53 +01:00
|
|
|
bash -c "mkdir -p /workspace/output && cp /workspace/build-wasm/kicad-pcbnew/pcbnew/pcbnew.{js,wasm,wasm.debug.wasm,wasm.map,worker.js} /workspace/output/ 2>/dev/null || cp /workspace/build-wasm/kicad-pcbnew/pcbnew/pcbnew.{js,wasm} /workspace/output/"
|
|
|
|
|
|
|
|
|
|
# Inject dynCall shims into pcbnew.js
|
|
|
|
|
# This fixes "dynCall_* is not defined" errors in Emscripten 4.x
|
|
|
|
|
./scripts/common/inject-dyncall-shims.sh output/pcbnew.js
|
|
|
|
|
|
|
|
|
|
# Apply wasm-emscripten-finalize on host (skipped in Docker due to memory limits)
|
|
|
|
|
# This is done on the host because finalize with DWARF needs significant RAM
|
|
|
|
|
./scripts/common/apply-finalize.sh output/pcbnew.wasm output/pcbnew.wasm
|
2025-12-08 12:07:01 +01:00
|
|
|
|
2025-12-13 22:13:31 +01:00
|
|
|
# Apply asyncify transformation on host
|
2025-12-14 11:59:50 +01:00
|
|
|
# This is done on the host because wasm-opt --asyncify needs significant RAM
|
|
|
|
|
./scripts/common/apply-asyncify.sh output/pcbnew.wasm output/pcbnew.wasm
|
2025-12-13 22:13:31 +01:00
|
|
|
|
|
|
|
|
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/
|