feat(wasm): unify editor builds — footprint/symbol editors via runtime --frame

The footprint and symbol editors are no longer separate WASM bundles: the frontend loads the parent pcbnew/eeschema bundle and passes --frame=fpedit / --frame=symedit (TOOL_BUNDLE + TOOL_FRAME -> Module.arguments in boot). Drops the two duplicate build+deploy targets and their wrapper scripts + vestigial embind; adds low-level harnesses (footprint_editor.html, symbol_editor.html) and a runtime-frame spec. Bumps the kicad submodule to the runtime --frame launcher.

The frame-runtime spec is listed in PCBNEW_FAMILY_SPECS so CI routes it to the chromium-ci (V8) project — its footprint case boots the pcbnew module, which OOMs SpiderMonkey on x86 CI. Includes the editor-unification dossier (research docs 01-04 + the as-built implementation record 05).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Istvan Matejcsok 2026-07-01 17:39:42 +02:00
commit c6716e6b60
22 changed files with 1066 additions and 103 deletions

View file

@ -0,0 +1,153 @@
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>KiCad Footprint Editor WASM</title>
<style>
.emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; }
div.emscripten { text-align: center; }
/* the canvas *must not* have any border or padding, or mouse coords will be wrong */
canvas.emscripten { border: 0px none; }
#status {
position: fixed;
bottom: 10px;
left: 10px;
color: #fff;
font-family: monospace;
z-index: 1000;
background: rgba(0,0,0,0.7);
padding: 10px;
border-radius: 5px;
}
#progress { width: 300px; height: 20px; background: #333; margin-top: 5px; }
#progress-bar { height: 100%; background: #4CAF50; width: 0%; transition: width 0.3s; }
</style>
</head>
<body style="margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; background: #1a1a2e;">
<div id="main-window" style="width: 100vw; height: 100vh; position: absolute; top: 0; left: 0;"></div>
<div id="status">
<div id="status-text">Initializing...</div>
<div id="progress"><div id="progress-bar"></div></div>
</div>
<div id="window-container"></div>
<script>
var mainWindow = document.getElementById('main-window');
var statusText = document.getElementById('status-text');
var progressBar = document.getElementById('progress-bar');
var showError = function(msg) {
console.error('[KICAD_ERROR] ' + msg);
statusText.textContent = 'Error: ' + msg;
statusText.style.color = 'red';
};
var createCanvas = function() {
var canvas = document.createElement('canvas');
canvas.id = 'canvas';
canvas.style.display = 'none';
var width = window.innerWidth;
var height = window.innerHeight;
canvas.style.width = width + 'px';
canvas.style.height = height + 'px';
canvas.oncontextmenu = function() { event.preventDefault(); };
canvas.addEventListener("webglcontextlost", function(e) {
showError('WebGL context lost. You will need to reload the page.');
e.preventDefault();
}, false);
mainWindow.appendChild(canvas);
Module.canvas = canvas;
console.log('[KICAD] preRun complete, canvas created: ' + width + 'x' + height);
};
var onRuntimeInitialized = function() {
console.log('[KICAD] Runtime initialized');
var canvas = Module.canvas;
canvas.style.display = 'block';
document.getElementById('status').style.display = 'none';
};
var resourceData = null;
fetch('images.tar.gz')
.then(function(response) { if (!response.ok) throw new Error('HTTP ' + response.status); return response.arrayBuffer(); })
.then(function(buffer) { resourceData = new Uint8Array(buffer); console.log('[KICAD] Prefetched images.tar.gz (' + resourceData.length + ' bytes)'); })
.catch(function(err) { console.warn('[KICAD] Could not prefetch images.tar.gz:', err.message); });
var writeResources = function() {
var resourcePath = '/workspace/build-wasm/sysroot/share/kicad/resources';
FS.mkdirTree(resourcePath);
if (resourceData) { FS.writeFile(resourcePath + '/images.tar.gz', resourceData); console.log('[KICAD] Wrote images.tar.gz to ' + resourcePath); }
else { console.warn('[KICAD] images.tar.gz not ready yet (WASM loaded faster than fetch)'); }
};
// Seed a minimal default config before main() so STARTWIZARD is skipped (see
// symbol_editor.html / eeschema.html). Version dir 10.0 for the KiCad 10.0.4 build.
var seedKicadConfig = function() {
var cfgDir = '/home/kicad/.config/kicad/kicad/10.0';
FS.mkdirTree(cfgDir);
var writeIfAbsent = function(path, contents) {
try { FS.stat(path); return; } catch (e) { /* absent — seed it */ }
FS.writeFile(path, contents);
console.log('[KICAD] Seeded ' + path);
};
writeIfAbsent(cfgDir + '/kicad_common.json', JSON.stringify({
do_not_show_again: { update_check_prompt: true, data_collection_prompt: true }
}, null, 2));
writeIfAbsent(cfgDir + '/sym-lib-table', '(sym_lib_table\n (version 7)\n)\n');
writeIfAbsent(cfgDir + '/fp-lib-table', '(fp_lib_table\n (version 7)\n)\n');
writeIfAbsent(cfgDir + '/design-block-lib-table', '(design_block_lib_table\n (version 7)\n)\n');
};
var Module = {
thisProgram: '/usr/bin/footprint_editor', // argv[0] for KiCad's DEBUG check
// The footprint editor is served by the pcbnew bundle (editor-unification):
// load pcbnew.js below and select FRAME_FOOTPRINT_EDITOR at runtime.
arguments: ['--frame=fpedit'],
preRun: [createCanvas, writeResources, seedKicadConfig],
postRun: [],
print: function(text) { if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' '); console.log('[KICAD_OUT] ' + text); },
printErr: function(text) { if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' '); console.error('[KICAD_ERR] ' + text); },
setStatus: function(text) {
console.log('[KICAD_STATUS] ' + text);
statusText.textContent = text;
var match = text.match(/(\d+)\/(\d+)/);
if (match) { var pct = (parseInt(match[1]) / parseInt(match[2])) * 100; progressBar.style.width = pct + '%'; }
},
totalDependencies: 0,
monitorRunDependencies: function(left) {
this.totalDependencies = Math.max(this.totalDependencies, left);
Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.');
},
onRuntimeInitialized: onRuntimeInitialized,
locateFile: function(path) { return path; }
};
Module.setStatus('Downloading...');
window.onerror = function(msg, url, line) {
showError(msg + ' at ' + url + ':' + line);
Module.setStatus = function(text) { if (text) Module.printErr('[post-exception status] ' + text); };
return false;
};
</script>
<!-- wxWidgets WASM glue code (defines getConfigEntryLength, etc.) -->
<script src="wx.js"></script>
<script src="wx-dom.js"></script>
<!-- Footprint editor = pcbnew bundle + --frame=fpedit (editor-unification). -->
<script async src="pcbnew.js"></script>
</body>
</html>

View file

@ -127,7 +127,7 @@
// before main() so every provider reports NeedsUserInput()==false and the
// wizard never opens — same as eeschema.html and the web app's boot.ts.
var seedKicadConfig = function() {
var cfgDir = '/home/kicad/.config/kicad/kicad/9.99';
var cfgDir = '/home/kicad/.config/kicad/kicad/10.0';
FS.mkdirTree(cfgDir);
var writeIfAbsent = function(path, contents) {
@ -147,6 +147,10 @@
var Module = {
thisProgram: '/usr/bin/symbol_editor', // Fake absolute path for argv[0] (KiCad DEBUG check)
// The symbol editor is served by the eeschema bundle (editor-unification):
// load eeschema.js below and select FRAME_SCH_SYMBOL_EDITOR at runtime.
arguments: ['--frame=symedit'],
preRun: [createCanvas, writeResources, seedKicadConfig],
postRun: [],
@ -202,6 +206,7 @@
<!-- wxWidgets WASM glue code (defines getConfigEntryLength, etc.) -->
<script src="wx.js"></script>
<script src="wx-dom.js"></script>
<script async src="symbol_editor.js"></script>
<!-- Symbol editor = eeschema bundle + --frame=symedit (editor-unification). -->
<script async src="eeschema.js"></script>
</body>
</html>

View file

@ -0,0 +1,67 @@
import { test, expect } from '@playwright/test';
/**
* Editor-unification runtime-frame validation.
*
* After unification the library editors are no longer separate .wasm bundles:
* - the Symbol Editor is the eeschema bundle booted with --frame=symedit
* - the Footprint Editor is the pcbnew bundle booted with --frame=fpedit
* The frame token is threaded through Module.arguments and parsed in
* kicad/common/single_top.cpp (mirroring kicad/kicad.cpp's --frame parser).
*
* This asserts the decisive fact the launch-smoke specs don't: that the shared
* bundle actually opens the LIBRARY editor frame, not its parent editor. The
* window title is the discriminator — the parent bundle's default frame would
* title itself "Schematic Editor" / "PCB Editor".
*/
interface FrameCase {
harness: string;
/** title the library-editor frame settles on */
titleRe: RegExp;
/** the parent editor's title — must NOT appear (would mean --frame was ignored) */
parentRe: RegExp;
}
const CASES: FrameCase[] = [
{ harness: 'symbol_editor.html', titleRe: /Symbol Editor/i, parentRe: /Schematic Editor/i },
{ harness: 'footprint_editor.html', titleRe: /Footprint Editor/i, parentRe: /PCB Editor/i },
];
test.describe('editor-unification runtime frame (--frame)', () => {
for (const tc of CASES) {
test(`${tc.harness} opens the library editor frame from its parent bundle`, async ({ page }) => {
const consoleLines: string[] = [];
page.on('console', (m) => consoleLines.push(m.text()));
page.on('pageerror', (e) => consoleLines.push(`pageerror: ${e.message}`));
await page.goto(`/kicad/${tc.harness}`);
// The runtime came up.
await expect(page.locator('#canvas')).toBeVisible({ timeout: 120000 });
// The frame sets the document title once it is up; poll until it settles.
await expect
.poll(() => page.title(), {
message: `${tc.harness}: never reached the expected library-editor title`,
timeout: 120000,
intervals: [1000],
})
.toMatch(tc.titleRe);
const title = await page.title();
// eslint-disable-next-line no-console
console.log(`[frame-runtime] ${tc.harness} -> title=${JSON.stringify(title)}`);
// The runtime --frame flag actually switched frames: the parent editor's
// title must not be what we ended up on.
expect(title, `${tc.harness}: opened the library editor, not its parent`).not.toMatch(tc.parentRe);
// No WASM abort during load.
const aborted = consoleLines.some((l) => /Aborted\(/.test(l));
expect(aborted, 'no WASM abort during load').toBe(false);
await page.screenshot({ path: `test-results/frame-runtime-${tc.harness}.png`, scale: 'device' });
});
}
});

View file

@ -94,6 +94,9 @@ const PCBNEW_FAMILY_SPECS = [
"**/3d-viewer-deadlock.spec.ts",
"**/3d-viewer-models.spec.ts",
"**/footprint-3d-preview.spec.ts",
// Parametrized over both library editors; the footprint case boots the pcbnew
// module (footprint_editor.html loads pcbnew.js) — same V8 routing, whole file.
"**/frame-runtime.spec.ts",
];
// Runtime-perf specs run ONLY on the Chromium 'perf' project below: they need

View file

@ -39,8 +39,6 @@ kicad_subdir_for() {
case "$1" in
calculator) echo "pcb_calculator" ;;
pl_editor) echo "pagelayout_editor" ;;
symbol_editor) echo "eeschema" ;;
footprint_editor) echo "pcbnew" ;;
*) echo "$1" ;;
esac
}
@ -81,16 +79,17 @@ copy_app() {
}
found_any=0
# symbol_editor / footprint_editor are NOT separate bundles: their harness HTMLs
# (symbol_editor.html / footprint_editor.html) load the eeschema / pcbnew bundle
# and select the frame at runtime via --frame (editor-unification).
copy_app pcbnew && found_any=1
copy_app eeschema && found_any=1
copy_app calculator && found_any=1
copy_app pl_editor && found_any=1
copy_app symbol_editor && found_any=1
copy_app footprint_editor && found_any=1
copy_app gerbview && found_any=1
if [ "$found_any" -eq 0 ]; then
echo "Error: no pcbnew/eeschema/calculator/pl_editor/symbol_editor/footprint_editor/gerbview artifacts found in output/ or docker volume" >&2
echo "Error: no pcbnew/eeschema/calculator/pl_editor/gerbview artifacts found in output/ or docker volume" >&2
exit 1
fi