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>
This commit is contained in:
Istvan Matejcsok 2026-07-02 14:48:11 +02:00
commit bbeef6d20e
23 changed files with 691 additions and 149 deletions

View file

@ -55,6 +55,13 @@ using json = nlohmann::json;
// the editor frame is the app's top window and is a KIWAY_PLAYER. Returns the
// result of OpenProjectFiles, or false if no frame is available — letting the
// JS caller fall back to driving File→Open.
//
// KICAD_MERGED_EMBIND (kicad_editor, editor-unification Part 2): eeschema_embind.cpp
// defines the identical function and registers the same JS names — in the merged image
// the frame-agnostic duplicates (this + kicadCollabOnSave) and the shared-name
// registrations live once in kicad_editor_embind.cpp, which dispatches the per-editor
// entries (renamed pcbCollab*/schCollab* below; JS-facing names are unchanged).
#ifndef KICAD_MERGED_EMBIND
bool kicadOpenFile( std::string path )
{
KIWAY_PLAYER* frame =
@ -69,6 +76,7 @@ bool kicadOpenFile( std::string path )
return frame->OpenProjectFiles(
std::vector<wxString>( 1, wxString::FromUTF8( path.c_str() ) ) );
}
#endif // !KICAD_MERGED_EMBIND
// ───────────────────────────── Yjs collaborative bridge ─────────────────────────────
//
@ -912,7 +920,7 @@ void collabTestMove( PCB_EDIT_FRAME* aFrame, BOARD_ITEM* aItem, int aDx, int aDy
// fiber stack: BOARD_COMMIT::Push's CHT_ADD of a freshly-built item dispatches GAL virtuals
// (view->Add → ViewGetLayers) through asyncify-instrumented invoke_*; off the fiber stack those
// mis-dispatch and trap inside KiCad core, on it they dispatch correctly (eeschema 0007).
void kicadCollabApply( std::string aJson )
void pcbCollabApply( std::string aJson )
{
json delta = json::parse( aJson, nullptr, /*allow_exceptions*/ false );
@ -937,7 +945,7 @@ void kicadCollabApply( std::string aJson )
// JS → C++, v2 items wire. Same CallAfter + COROUTINE context as kicadCollabApply
// (the blob parse + commit must run where native edits run — see above).
void kicadCollabApplyItems( std::string aJson )
void pcbCollabApplyItems( std::string aJson )
{
json wire = json::parse( aJson, nullptr, /*allow_exceptions*/ false );
@ -962,7 +970,7 @@ void kicadCollabApplyItems( std::string aJson )
// JS pull of the full current model as an all-"added" delta (seed/baseline). Also registers the
// change listener on first call.
std::string kicadCollabSnapshot()
std::string pcbCollabSnapshot()
{
BOARD* board = ensureBridge();
@ -985,7 +993,7 @@ std::string kicadCollabSnapshot()
// JS pull of the full current model as an all-"added" v2 items wire: one blob per ROOT
// item (a footprint's blob embeds its children — the TS side flattens). Registers the
// listener + rebaselines exactly like kicadCollabSnapshot.
std::string kicadCollabSnapshotItems()
std::string pcbCollabSnapshotItems()
{
BOARD* board = ensureBridge();
@ -1020,6 +1028,9 @@ std::string kicadCollabSnapshotItems()
// kicad fork's save chokepoint (PCB_EDIT_FRAME::SavePcbFile) after a successful
// write to MEMFS, so the web app can route the saved bytes onward (API upload,
// local-disk write-back, download). No-op without a JS listener.
// KICAD_MERGED_EMBIND: identical definition in eeschema_embind.cpp; the merged image
// gets the one in kicad_editor_embind.cpp (both fork save chokepoints call it).
#ifndef KICAD_MERGED_EMBIND
extern "C" void kicadCollabOnSave( const char* aPath )
{
EM_ASM( {
@ -1027,6 +1038,15 @@ extern "C" void kicadCollabOnSave( const char* aPath )
window.kicadCollab.onSave( UTF8ToString( $0 ) );
}, aPath );
}
#endif // !KICAD_MERGED_EMBIND
// Merged-image dispatch probe (kicad_editor_embind.cpp): is the active top window the
// PCB editor? Each shared JS entry routes to the pcb*/sch* implementation whose frame
// is live — exactly the null-check its body starts with anyway.
bool pcbEditorActive()
{
return pcbFrame() != nullptr;
}
void kicadSaveBoard( std::string path )
@ -1057,7 +1077,7 @@ void kicadSaveBoard( std::string path )
// Test/PoC helper: move the first top-level board item by (dx,dy) IU via a real BOARD_COMMIT,
// firing the listener — a deterministic local edit for the two-tab demo / e2e. Returns the
// moved item's uuid.
std::string kicadCollabTestMoveFirst( int aDx, int aDy )
std::string pcbCollabTestMoveFirst( int aDx, int aDy )
{
PCB_EDIT_FRAME* fr = pcbFrame();
@ -1090,7 +1110,7 @@ std::string kicadCollabTestMoveFirst( int aDx, int aDy )
// Test helper: read an item's position by uuid as "x,y" (internal units).
std::string kicadCollabGetPos( std::string aId )
std::string pcbCollabGetPos( std::string aId )
{
PCB_EDIT_FRAME* fr = pcbFrame();
@ -1194,19 +1214,24 @@ EMSCRIPTEN_BINDINGS(pcbnew) {
function("Pad_GetNumber", &Pad_GetNumber, allow_raw_pointers());
function("Pad_GetPinFunction", &Pad_GetPinFunction, allow_raw_pointers());
// Programmatic file open (preferred over UI automation from the web app).
function("kicadOpenFile", &kicadOpenFile);
// Programmatic save of the in-memory board (round-trip tests, README §A).
function("kicadSaveBoard", &kicadSaveBoard);
// Yjs collaborative bridge entry points (same contract as pl_editor / eeschema).
function("kicadCollabApply", &kicadCollabApply);
function("kicadCollabSnapshot", &kicadCollabSnapshot);
// v2 items bridge: per-item s-expr payloads (ysync 0008).
function("kicadCollabApplyItems", &kicadCollabApplyItems);
function("kicadCollabSnapshotItems", &kicadCollabSnapshotItems);
function("kicadCollabTestMoveFirst", &kicadCollabTestMoveFirst);
function("kicadCollabGetPos", &kicadCollabGetPos);
// pcbnew-only test helper (no eeschema counterpart — name is not shared).
function("kicadCollabTestItemBlob", &kicadCollabTestItemBlob);
#ifndef KICAD_MERGED_EMBIND
// JS names ALSO registered by eeschema_embind.cpp — in the merged image these are
// registered once by kicad_editor_embind.cpp, dispatching on the active frame.
// Programmatic file open (preferred over UI automation from the web app).
function("kicadOpenFile", &kicadOpenFile);
// Yjs collaborative bridge entry points (same contract as pl_editor / eeschema).
function("kicadCollabApply", &pcbCollabApply);
function("kicadCollabSnapshot", &pcbCollabSnapshot);
// v2 items bridge: per-item s-expr payloads (ysync 0008).
function("kicadCollabApplyItems", &pcbCollabApplyItems);
function("kicadCollabSnapshotItems", &pcbCollabSnapshotItems);
function("kicadCollabTestMoveFirst", &pcbCollabTestMoveFirst);
function("kicadCollabGetPos", &pcbCollabGetPos);
#endif // !KICAD_MERGED_EMBIND
}
#endif