pcbjam/scripts/kicad/audit-merged-symbols.sh
Istvan Matejcsok bbeef6d20e feat(wasm): kicad_editor — merge the pcbnew+eeschema kifaces into ONE bundle (Part 2)
All four editors (PCB / Footprint / Schematic / Symbol) are now runtime --frame
choices of a single kicad_editor.wasm (178 MB at -O1 vs 147+82 separate; shared
wx/common/boost linked once). One editor per page load, as before; frames pcb /
fpedit / sch / symedit.

- wasm/editor/: the merged executable target (single_top + both kiface library sets,
  whole-archive pcbcommon) + the safety-net focus-walk Kiface() dispatch TU. Gated by
  KICAD_WASM_MERGED_EDITOR (kicad submodule bump carries the fork side: per-engine
  Kiface/getter binding + ODR renames + dual-kiface launcher).
- wasm/bindings/: per-editor collab entries renamed pcbCollab*/schCollab* (JS names
  unchanged); duplicate kicadOpenFile/kicadCollabOnSave + shared-name registrations
  guarded behind KICAD_MERGED_EMBIND; new kicad_editor_embind.cpp registers each
  shared JS name once, dispatching on the live frame.
- Build: kicad_editor app (build wrapper, target case arms, 3-object embind compile
  with the ABI-critical flags, STUB_APP=pcbnew); docker/build.sh "all" =
  kicad_editor calculator pl_editor gerbview (pcbnew/eeschema stay as explicit debug
  apps); scripts/kicad/audit-merged-symbols.sh = repeatable ODR-collision audit (run
  on kicad bumps).
- Frontend: Bundle type (bundle ≠ tool); TOOL_BUNDLE maps all four editors to
  kicad_editor; explicit --frame tokens for pcbnew (pcb) and eeschema (sch); publish
  list = the 4 real bundles.
- Tests/CI: five harnesses load kicad_editor.js with explicit frame tokens;
  PCBNEW_FAMILY_SPECS renamed BIG_MODULE_SPECS + the 8 eeschema-family specs (they
  now boot the merged module — SpiderMonkey x86 CI OOM routing); frame-runtime spec
  covers all four frames from the one bundle.

Validated so far: frame-runtime 4/4 (each frame boots with the right title, no
aborts, no duplicate embind registration); 24-spec merged-module regression green;
3D raytracer renders. Known pre-existing failure: 3d-viewer title-bar drag deadlock,
fixed on main by 7630c7e (2N+8 pthread pre-warm) — picked up by the follow-up rebase.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-02 17:56:02 +02:00

98 lines
5.7 KiB
Shell
Executable file

#!/bin/bash
# Duplicate-symbol audit for the merged kicad_editor image (editor-unification Part 2).
#
# The pcbnew and eeschema kifaces are statically linked into one WASM image with
# --allow-multiple-definition (required for wx/KiCad dupes), so a symbol both engines
# define binds SILENTLY to the first definition — a wrong-behavior/memory-corruption
# bug, never a link error. This script intersects the two kifaces' defined symbols so
# every collision is a conscious decision (the known set is renamed per-engine via
# KICAD_WASM_PCB_SIDE_RENAMES in kicad/CMakeLists.txt).
#
# Run INSIDE the build container (needs $EMSDK llvm-nm and the per-app build trees):
# docker compose -f docker/docker-compose.yml exec kicad-wasm-builder \
# /workspace/scripts/kicad/audit-merged-symbols.sh
# Re-run whenever the kicad submodule is bumped. Expected output: EMPTY intersection
# (all known collisions renamed). Any line of output is a new upstream collision to
# add to the rename list.
#
# Method (see docs/features/editor-unification/06-part2-implementation.md):
# - strong (T/D/B/R) defined external symbols: direct first-def-wins collisions.
# - weak (W/V) symbols are only dangerous when the SAME name has DIFFERENT
# definitions per module (same-named classes with inline members). Weak symbols
# also defined by the shared libs are one shared definition — filtered out. The
# remainder is mostly benign template dedup (magic_enum etc.); review NEW entries.
set -euo pipefail
BUILD_ROOT="${BUILD_ROOT:-/workspace/build-wasm}"
P="${BUILD_ROOT}/kicad-pcbnew"
E="${BUILD_ROOT}/kicad-eeschema"
NM="${EMSDK:?EMSDK not set}/upstream/bin/llvm-nm"
OUT="${TMPDIR:-/tmp}/merged-symbol-audit"
mkdir -p "${OUT}"
if [ ! -d "${P}/pcbnew" ] || [ ! -d "${E}/eeschema" ]; then
echo "ERROR: need built kicad-pcbnew and kicad-eeschema trees under ${BUILD_ROOT}" >&2
echo " (./docker/build.sh pcbnew,eeschema --compile-only)" >&2
exit 1
fi
pcb_files() {
find "${P}/pcbnew/CMakeFiles/pcbnew_kiface_objects.dir" -name '*.o'
ls "${P}/common/libpcbcommon.a" \
"${P}/pcbnew/connectivity/libconnectivity.a" \
"${P}/pcbnew/router/libpnsrouter.a" \
"${P}/pcbnew/navlib/libpcbnew_navlib.a" \
"${P}/utils/idftools/libidf3.a" \
"${P}"/pcbnew/pcb_io/*/*.a 2>/dev/null || true
find "${P}/3d-viewer" -name '*.o' 2>/dev/null || true
}
sch_files() {
find "${E}/eeschema/CMakeFiles/eeschema_kiface_objects.dir" -name '*.o'
ls "${E}/eeschema/navlib/libeeschema_navlib.a" 2>/dev/null || true
}
# Weak symbols defined by the SHARED libs (one definition linked once — safe dedup).
shared_syms() {
${NM} --defined-only --extern-only --format=posix \
"${P}/common/libcommon.a" "${P}/common/libkicommon.a" \
"${P}/common/gal/libkigal.a" "${P}/libs/core/libcore.a" \
"${P}/libs/kimath/libkimath.a" "${P}/libs/kiplatform/libkiplatform.a" \
"${P}/scripting/libscripting.a" "${P}/api/libkiapi.a" \
"${P}/libs/sexpr/libsexpr.a" 2>/dev/null | awk '{print $1}' | sort -u
}
echo "== collecting symbols (llvm-nm)..." >&2
${NM} --defined-only --extern-only --format=posix $(pcb_files) 2>/dev/null \
| awk '$2 ~ /^[TDBR]$/ {print $1}' | sort -u > "${OUT}/pcb_strong.txt"
${NM} --defined-only --extern-only --format=posix $(sch_files) 2>/dev/null \
| awk '$2 ~ /^[TDBR]$/ {print $1}' | sort -u > "${OUT}/sch_strong.txt"
${NM} --defined-only --extern-only --format=posix $(pcb_files) 2>/dev/null \
| awk '$2 ~ /^[WVwv]$/ {print $1}' | sort -u > "${OUT}/pcb_weak.txt"
${NM} --defined-only --extern-only --format=posix $(sch_files) 2>/dev/null \
| awk '$2 ~ /^[WVwv]$/ {print $1}' | sort -u > "${OUT}/sch_weak.txt"
shared_syms > "${OUT}/shared.txt"
# Known-renamed / expected entries. In OPTION-OFF per-app trees (the normal state of
# kicad-pcbnew / kicad-eeschema) the renames are NOT applied, so the known set shows
# up here — filter it; the merged tree compiles with the renames so these cannot
# collide there. KIFACE_1/Kiface get per-engine getter/accessor names; the class/data
# names are prefixed PCB_/pcb (KICAD_WASM_PCB_SIDE_RENAMES).
KNOWN='^(KIFACE_1$|_Z6Kifacev$|_Z16checkOverwriteDb|pcbAllowedActions$|allowedActions$|g_excludedLayers$|_Z[A-Z0-9]*[0-9]+(PCB_)?(DIALOG_TEXT_PROPERTIES|DIALOG_SHAPE_PROPERTIES|DIALOG_TABLE_PROPERTIES|DIALOG_TABLECELL_PROPERTIES|DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS|PANEL_SETUP_FORMATTING|TEXT_SEARCH_HANDLER|GROUP_SEARCH_HANDLER|TEXTBOX_POINT_EDIT_BEHAVIOR|RECTANGLE_POINT_EDIT_BEHAVIOR|FILEDLG_HOOK_SAVE_PROJECT|FOOTPRINT_INFO_GENERATOR))'
# Mangled-name filter needs the raw class tokens too (ZTV/ZTI/ZTS/ZN prefixes).
CLASSES='DIALOG_TEXT_PROPERTIES|DIALOG_SHAPE_PROPERTIES|DIALOG_TABLE_PROPERTIES|DIALOG_TABLECELL_PROPERTIES|DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS|PANEL_SETUP_FORMATTING|TEXT_SEARCH_HANDLER|GROUP_SEARCH_HANDLER|TEXTBOX_POINT_EDIT_BEHAVIOR|RECTANGLE_POINT_EDIT_BEHAVIOR|FILEDLG_HOOK_SAVE_PROJECT|FOOTPRINT_INFO_GENERATOR|checkOverwriteDb|allowedActions|g_excludedLayers'
echo "== STRONG duplicates (unexpected — must be renamed or justified):"
comm -12 "${OUT}/pcb_strong.txt" "${OUT}/sch_strong.txt" \
| grep -vE "${CLASSES}" | grep -vE '^KIFACE_1$|^_Z6Kifacev$' || true
echo "== WEAK duplicates not from shared libs, mentioning NEW class tokens"
echo " (known colliding classes filtered; review anything printed):"
comm -12 "${OUT}/pcb_weak.txt" "${OUT}/sch_weak.txt" \
| comm -23 - "${OUT}/shared.txt" \
| grep -vE "${CLASSES}" \
| grep -E '_Z(TV|TI|TS|N)[0-9]+[A-Z]' \
| grep -vE 'magic_enum|wxEventFunctorMethod|wxNavigationEnabled|wxSimplebook|wxDataView|wxMenuBar|wxVector|KIFACE|COLLECTOR|RC_JSON|PARAM_SCALED|EDA_|BOX2|WX_MENUBAR|SEARCH_HANDLER' || true
echo "== audit done (details in ${OUT})"