2025-12-12 15:34:15 +01:00
|
|
|
#!/bin/bash
|
2025-12-13 22:13:31 +01:00
|
|
|
# Copies KiCad WASM build output to test directory
|
|
|
|
|
#
|
|
|
|
|
# Priority: Use local output/ directory (populated by docker/build.sh)
|
|
|
|
|
# Fallback: Copy from Docker volume directly
|
2026-05-29 06:39:23 +02:00
|
|
|
#
|
2026-05-29 12:01:44 +02:00
|
|
|
# Copies whichever apps are present (pcbnew, eeschema, calculator).
|
2025-12-12 15:34:15 +01:00
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
|
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
2026-06-11 00:19:53 +02:00
|
|
|
|
2026-06-12 10:18:16 +02:00
|
|
|
KICAD_TEST="$PROJECT_ROOT/tests/apps/kicad"
|
|
|
|
|
OUTPUT_DIR="$PROJECT_ROOT/output"
|
2025-12-12 15:34:15 +01:00
|
|
|
|
|
|
|
|
mkdir -p "$KICAD_TEST"
|
|
|
|
|
|
2026-06-01 16:30:29 +02:00
|
|
|
# Smart copy: skip when the destination already exists and is byte-identical to
|
|
|
|
|
# the source (cmp -s is portable across macOS/Linux). Makes this a real sync —
|
|
|
|
|
# re-running does not rewrite unchanged multi-hundred-MB .wasm files.
|
|
|
|
|
smart_cp() {
|
|
|
|
|
local src="$1" destdir="$2"
|
|
|
|
|
[ -f "$src" ] || return 0
|
|
|
|
|
local dst="$destdir/$(basename "$src")"
|
|
|
|
|
if [ -f "$dst" ] && cmp -s "$src" "$dst"; then
|
|
|
|
|
echo " = $(basename "$src") (up-to-date)"
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
cp "$src" "$dst"
|
|
|
|
|
echo " + $(basename "$src")"
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-29 12:01:44 +02:00
|
|
|
# Map an app name to its inner CMake build subdirectory. Most apps share their
|
|
|
|
|
# subdir name with the app name; pcb_calculator emits OUTPUT_NAME=calculator
|
feat: pl_editor WASM port + browser file dialog fixes
Brings up KiCad's pagelayout_editor (drawing-sheet editor) in the
browser, to roughly the same "boots, canvas visible, partially usable
in-session" level as the existing pcbnew/eeschema/calculator ports.
Build:
- docker/build.sh: add pl_editor to the unified app dispatch (case,
subdir map, all-loop).
- scripts/kicad/build-kicad-target.sh: add pl_editor to the case;
upstream target name pl_editor under source subdir pagelayout_editor.
- scripts/kicad/build-pl_editor.sh: 7-line thin wrapper matching the
pcbnew/eeschema/calculator pattern.
- tests/scripts/setup-kicad-wasm.sh: copy_app pl_editor.
App glue:
- wasm/stubs/nl_pl_editor_plugin_stub.cpp: no-op SpaceMouse plugin so
pl_editor_frame.cpp's NL_PL_EDITOR_PLUGIN symbols resolve. Mirrors
nl_pcbnew_plugin_stub.cpp.
- tests/apps/kicad/pl_editor.html: browser shell. preRun creates
/home/kicad and FS.chdir there so file dialogs land somewhere
friendly instead of MEMFS root (/dev/, /proc/, etc.).
E2E coverage:
- tests/kicad/pl_editor.spec.ts: 5 tests — smoke (canvas, no abort),
wizard, File menu has Open/Save As, file-dialog folder-navigation
regression, canvas + toolbar metrics.
- tests/e2e/filedialog-folder-nav.spec.ts: wxWidgets-level twin of
the regression test (exercises the underlying widget directly via
the standalone filedialog_test app).
Submodule bumps:
- kicad → feature/pl-editor (WASM gating in pagelayout_editor's
CMakeLists + navlib stub).
- wxwidgets → feature/pl-editor (wxGenericFileDialog::OnOk navigates
into selected directories; wasm/mouse.cpp emits wxEVT_LEFT_DCLICK
via timestamp-based double-click detection — the latter benefits
every wxWidgets-WASM app).
See features/pl-editor/ for the design doc + per-repo diff patches.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-01 10:30:56 +02:00
|
|
|
# but lives under the pcb_calculator/ subtree of the build dir, and pl_editor's
|
|
|
|
|
# source lives under pagelayout_editor/.
|
2026-05-29 12:01:44 +02:00
|
|
|
kicad_subdir_for() {
|
|
|
|
|
case "$1" in
|
2026-06-14 06:22:40 +02:00
|
|
|
calculator) echo "pcb_calculator" ;;
|
|
|
|
|
pl_editor) echo "pagelayout_editor" ;;
|
|
|
|
|
*) echo "$1" ;;
|
2026-05-29 12:01:44 +02:00
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Copy one app's artifacts (js, wasm, optional debug/map/worker). Returns 0
|
|
|
|
|
# if the app was present, 1 if neither output/ nor the docker volume has it.
|
2026-05-29 06:39:23 +02:00
|
|
|
copy_app() {
|
|
|
|
|
local app="$1"
|
2026-05-29 12:01:44 +02:00
|
|
|
local subdir
|
|
|
|
|
subdir=$(kicad_subdir_for "$app")
|
2026-05-29 06:39:23 +02:00
|
|
|
|
|
|
|
|
if [ -f "$OUTPUT_DIR/${app}.js" ] && [ -f "$OUTPUT_DIR/${app}.wasm" ]; then
|
2026-06-01 16:30:29 +02:00
|
|
|
echo "Syncing ${app} WASM files from output directory..."
|
|
|
|
|
smart_cp "$OUTPUT_DIR/${app}.js" "$KICAD_TEST"
|
|
|
|
|
smart_cp "$OUTPUT_DIR/${app}.wasm" "$KICAD_TEST"
|
|
|
|
|
smart_cp "$OUTPUT_DIR/${app}.wasm.map" "$KICAD_TEST"
|
|
|
|
|
smart_cp "$OUTPUT_DIR/${app}.worker.js" "$KICAD_TEST"
|
|
|
|
|
smart_cp "$OUTPUT_DIR/images.tar.gz" "$KICAD_TEST"
|
2026-05-29 06:39:23 +02:00
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "Output ${app} not found locally, trying Docker volume..."
|
|
|
|
|
if docker compose -f "$PROJECT_ROOT/docker/docker-compose.yml" cp \
|
2026-06-12 10:18:16 +02:00
|
|
|
kicad-wasm-builder:/workspace/build-wasm/kicad-${app}/${subdir}/${app}.js "$KICAD_TEST/" 2>/dev/null \
|
2026-05-29 06:39:23 +02:00
|
|
|
&& docker compose -f "$PROJECT_ROOT/docker/docker-compose.yml" cp \
|
2026-06-12 10:18:16 +02:00
|
|
|
kicad-wasm-builder:/workspace/build-wasm/kicad-${app}/${subdir}/${app}.wasm "$KICAD_TEST/" 2>/dev/null; then
|
2026-05-29 06:39:23 +02:00
|
|
|
docker compose -f "$PROJECT_ROOT/docker/docker-compose.yml" cp \
|
2026-06-12 10:18:16 +02:00
|
|
|
kicad-wasm-builder:/workspace/build-wasm/kicad-${app}/${subdir}/${app}.wasm.map "$KICAD_TEST/" 2>/dev/null || true
|
2026-05-29 06:39:23 +02:00
|
|
|
docker compose -f "$PROJECT_ROOT/docker/docker-compose.yml" cp \
|
2026-06-12 10:18:16 +02:00
|
|
|
kicad-wasm-builder:/workspace/build-wasm/kicad-${app}/${subdir}/${app}.worker.js "$KICAD_TEST/" 2>/dev/null || true
|
2026-05-29 06:39:23 +02:00
|
|
|
docker compose -f "$PROJECT_ROOT/docker/docker-compose.yml" cp \
|
2026-06-12 10:18:16 +02:00
|
|
|
kicad-wasm-builder:/workspace/build-wasm/kicad-${app}/resources/images.tar.gz "$KICAD_TEST/" 2>/dev/null || true
|
2026-05-29 06:39:23 +02:00
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo " (no ${app} artifacts found — skipping)"
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
found_any=0
|
2026-07-02 14:48:11 +02:00
|
|
|
# The four editors (pcbnew / eeschema / footprint_editor / symbol_editor) are ALL
|
|
|
|
|
# served by the ONE merged kicad_editor bundle: their harness HTMLs load
|
|
|
|
|
# kicad_editor.js and select the frame at runtime via --frame (editor-unification
|
|
|
|
|
# Part 2).
|
|
|
|
|
copy_app kicad_editor && found_any=1
|
2026-06-14 06:22:40 +02:00
|
|
|
copy_app calculator && found_any=1
|
|
|
|
|
copy_app pl_editor && found_any=1
|
|
|
|
|
copy_app gerbview && found_any=1
|
feat(wasm): occ-split — lazy occ_service worker; kicad_editor drops OCC (−31%)
Move OpenCASCADE out of the merged editor image into occ_service: a separate
emscripten module (-sASYNCIFY=0, MODULARIZE, in-container -Oz finalize, 2N+8
pre-warmed pthread pool) booted lazily in a dedicated Web Worker on the first
STEP export or STEP/IGES model parse. kicad_editor.wasm ~190 MB -> 130 MB;
sessions that never touch OCC never fetch its 57 MB. STEP export works in the
browser for the first time: the unchanged desktop dialog runs EXPORTER_STEP,
whose wasm shadow suspends into globalThis.occService and the export bytes go
straight to a browser download (never entering the editor heap). STEP/IGES 3D
models parse in the worker via the oce shadow (S3D WriteCache/ReadCache wire).
- wasm/occ-service/: service CMake target (hooked from the kicad fork's
top-level CMakeLists, wasm/editor pattern), embind entry
(occExport/occLoadModel), wxConfig pre-js.
- wasm/stubs/{exporter_step,oce_plugin}_stub.cpp: EM_ASYNC_JS worker bridges
(callee-shadowing; no caller #ifdefs).
- web/standalone: provider installed whenever the kicad_editor bundle boots
(cross-face safe); ONE shared worker-boot source occ-worker.js (vite ?raw;
the e2e stub reads the same file) — blob worker with locateFile absolutized
against the glue URL; export download-name guard.
- deps: OCC builds with RapidJSON so its glTF/GLB writer exists — pinned to
the vcpkg master snapshot 2025-02-26 (24b5e7a8b27f), the same code official
KiCad consumes via vcpkg.json's opencascade[rapidjson]; rapidjson's latest
tag (v1.1.0, 2016) is ill-formed under modern clang.
- tests: occ-export dialog e2e (lazy-fetch boundary + STEP download bytes),
occ-probe incl. a 9-format matrix (step/stpz/brep/xao/ply/stl/glb/u3d/pdf),
3d-viewer-models hard-asserts the worker parse; occ provider stub installed
ambiently by the kicad fixtures.
Validated against desktop kicad-cli 10.0.4: geometric exact equality (bbox
delta 0 um, volume delta 0.0000%) for STEP/GLB/STL/BREP/STPZ across three
boards and option sweeps — with desktop OCC 7.9 vs wasm OCC 7.8; PLY/XAO/PDF
structurally equal; U3D same-size (quantizer float LSBs differ). Full kicad
e2e green on Firefox and Chromium; standalone verified end to end (lazy fetch
only on the Export click; export.step 60,628 B ISO-10303-21; loadModel 700 KB
STEP -> 569 KB scenegraph cache).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 12:39:58 +02:00
|
|
|
# OCC 3D service (lazy worker module; pcbnew's STEP export + model parsing)
|
|
|
|
|
copy_app occ_service || true
|
2026-07-19 15:59:21 +02:00
|
|
|
# ngspice simulation service (lazy worker module; eeschema's simulator)
|
|
|
|
|
copy_app ngspice_service || true
|
2026-05-29 06:39:23 +02:00
|
|
|
|
|
|
|
|
if [ "$found_any" -eq 0 ]; then
|
2026-07-02 14:48:11 +02:00
|
|
|
echo "Error: no kicad_editor/calculator/pl_editor/gerbview artifacts found in output/ or docker volume" >&2
|
2026-05-29 06:39:23 +02:00
|
|
|
exit 1
|
2025-12-13 22:13:31 +01:00
|
|
|
fi
|
2025-12-12 15:34:15 +01:00
|
|
|
|
|
|
|
|
# wxWidgets WASM JavaScript glue code (defines JS functions called from WASM)
|
2026-06-01 16:30:29 +02:00
|
|
|
echo "Syncing wxWidgets WASM glue code..."
|
2026-03-22 12:48:05 +01:00
|
|
|
if [ -f "$OUTPUT_DIR/wx.js" ]; then
|
2026-06-01 16:30:29 +02:00
|
|
|
smart_cp "$OUTPUT_DIR/wx.js" "$KICAD_TEST"
|
2026-03-22 12:48:05 +01:00
|
|
|
else
|
|
|
|
|
if docker compose -f "$PROJECT_ROOT/docker/docker-compose.yml" cp \
|
2026-06-12 10:18:16 +02:00
|
|
|
kicad-wasm-builder:/workspace/wxwidgets/build/wasm/wx.js "$KICAD_TEST/" 2>/dev/null; then
|
2026-03-22 12:48:05 +01:00
|
|
|
:
|
|
|
|
|
else
|
2026-06-01 16:30:29 +02:00
|
|
|
smart_cp "$PROJECT_ROOT/wxwidgets/build/wasm/wx.js" "$KICAD_TEST"
|
2026-03-22 12:48:05 +01:00
|
|
|
fi
|
|
|
|
|
fi
|
2025-12-12 15:34:15 +01:00
|
|
|
|
2026-06-12 10:18:16 +02:00
|
|
|
# The control-layer shim loads after wx.js (the checked-in kicad pages
|
|
|
|
|
# reference both via <script> tags).
|
|
|
|
|
if [ -f "$OUTPUT_DIR/wx-dom.js" ]; then
|
|
|
|
|
smart_cp "$OUTPUT_DIR/wx-dom.js" "$KICAD_TEST"
|
|
|
|
|
else
|
|
|
|
|
smart_cp "$PROJECT_ROOT/wxwidgets/build/wasm/wx-dom.js" "$KICAD_TEST"
|
2026-06-11 00:19:53 +02:00
|
|
|
fi
|
|
|
|
|
|
2026-06-19 10:24:41 +02:00
|
|
|
# Demo board for the gerbview print test (tests/apps/kicad/gerbview-print.html).
|
|
|
|
|
# Provisioned (not committed; gitignored) from the canonical demo board, same
|
|
|
|
|
# pattern as the wasm artifacts above. gerbview-print.html fetches the subset of
|
|
|
|
|
# layers it needs from ./board/, so copying the whole set is harmless.
|
|
|
|
|
BOARD_SRC="$PROJECT_ROOT/site/public/gerber-demo/board"
|
|
|
|
|
if [ -d "$BOARD_SRC" ]; then
|
|
|
|
|
echo "Provisioning gerbview demo board..."
|
|
|
|
|
mkdir -p "$KICAD_TEST/board"
|
|
|
|
|
for f in "$BOARD_SRC"/tinytapeout-demo-*; do
|
|
|
|
|
smart_cp "$f" "$KICAD_TEST/board"
|
|
|
|
|
done
|
|
|
|
|
else
|
|
|
|
|
echo " (demo board source $BOARD_SRC not found — skipping)"
|
|
|
|
|
fi
|
|
|
|
|
|
2026-06-01 16:30:29 +02:00
|
|
|
echo "KiCad WASM files synced to $KICAD_TEST"
|
2025-12-12 15:34:15 +01:00
|
|
|
ls -lh "$KICAD_TEST"
|