Commit graph pcbjam/scripts
Author SHA1 Message Date
Istvan Matejcsok
c148443b7b refactor: 💡 remove orphaned files 2026-06-05 13:18:24 +02:00
Istvan Matejcsok
8e413f89ec docs: ✏️ cleanup and organize docs 2026-06-05 12:16:13 +02:00
Balint Ipkovich
4467bcd2c4 feat: gerbview WASM port 2026-06-03 14:23:57 +02:00
Gergő Törcsvári
18a9de0449
fix(wasm): self-heal fiber trampoline so schematic load doesn't hang
The emscripten fiber glue gates Fibers.trampoline() on Fibers.trampolineRunning
and resets it at the end of its loop. At startup emscripten_set_main_loop(...,1)
throws "unwind" to establish the main loop, and KiCad does so from inside a tool
coroutine, so the throw propagates THROUGH the trampoline and skips the reset —
leaving the flag stuck true. Every fiber swap after startup then becomes a silent
no-op, so opening a schematic (SetScreen -> RunAction(selectionClear) -> fiber
swap) hangs forever with the editor stuck on "untitled".

Wrap the trampoline loop in try/finally (inject-dyncall-shims.sh section "3c") so
the flag is always reset. Add tests/kicad/eeschema-load.spec.ts, which opens a
small wires/junctions schematic via Module.kicadOpenFile and asserts the editor
title switches away from "untitled": it times out (RED) without the shim and
passes (GREEN) with it. Also add features/web-init/0002-url-regex-modal-followup.md
capturing the unrelated URL-detection wxRegEx modal surfaced once loading works.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-02 20:32:25 +02:00
Gergő Törcsvári
ddd959fbc2
fix(web): eeschema schematic open path — Asyncify/dynCall fixes + bump submodules
- inject-dyncall-shims.sh: add a dynCallLegacy -> wasmExports fallback so embind's
  generic dynCall path finds the DYNCALLS=1 trampolines. Without it, an Asyncify
  unwind/rewind through an embind call (kicadOpenFile -> OpenProjectFiles) died
  with "f is not a function".
- open-flow.ts: kicadOpenFile runs OpenProjectFiles under Asyncify, so its sync
  return is a falsy placeholder. Invoke it and poll the frame title for the load
  instead of trusting the return value, and never fall back to UI automation
  while the hook is in flight (it would re-enter the suspended Asyncify call).
- .gitignore: ignore .playwright-mcp scratch.
- bump kicad + wxwidgets submodules to the wasm schematic-open fixes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-02 20:32:24 +02:00
Balint Ipkovich
e28f473040 feat: symbol_editor WASM port 2026-06-02 13:37:26 +02:00
Istvan Matejcsok
c7a71ff2a7 chore: 🤖 add build monitor 2026-06-01 17:37:00 +02:00
Balint Ipkovich
9ab7158057 fix(skills): make git-workflow script paths portable
All four git-feature-* skills hardcoded /Users/torcsi/dev/kicad-wasm/ for
the helper-script invocations and one documentation example. That path
only resolved on the original author's machine — anyone else picking up
/git-feature-{start,commit,sync,finish} would hit "No such file or
directory" before the first pre-flight check ran.

Replaces the absolute paths with relative ones (`bash scripts/...`) and
rewrites the rebase-conflict handoff message in git-feature-sync.md to use
`git -C kicad ...` style instead of a hardcoded cd.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-01 14:59:09 +02:00
Balint Ipkovich
d735779e23 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
Viktor Vaczi
b5be072461 asyncify: add wasm-opt -O2 pass + bump wxwidgets (modal promise fix)
Two related fixes for Chrome-specific WASM-runtime issues reported when
running a manually-loaded session (line tool wouldn't even toggle on click;
log filled with 'Uncaught (in promise) unwind' and stderr-tagged
[WASM_FCONTEXT]/[DIAG_*] spam):

1) scripts/common/apply-asyncify.sh — run 'wasm-opt -O2' as a separate
   pass after '--asyncify'.  Without this, large asyncify-instrumented
   coroutine-entry trampolines (notably libcontext's wasm_fcontext_entry
   and COROUTINE<int,TOOL_EVENT const&>::callerStub) exceed V8's
   per-function locals limit and silently stall on first fiber entry,
   leaving the toolbar click dispatched in C++ but the tool never
   activating its 'running=1'/[checked] state in the user's Chrome.
   Firefox tolerates the unoptimised version, so tests on Firefox passed
   while real Chrome stalled.  The -O2 pass shrinks every instrumented
   function back under the threshold, fixing the family of stalls
   systemically (no more per-function removelist whack-a-mole).
   The removelist still contains setupUIConditions() etc. as a safety
   net — they're now redundant under -O2 but harmless.
   Bundle: 338 MB -> 187 MB raw (~45% smaller); test runtime nearly
   halves because parse is faster.  See DEBUG.md §7 and
   memory/bundle-size-asyncify-optimization.md.

2) wxwidgets submodule bump (d1d1627 -> a998a8d) — wasm/dialog.cpp:
   startModal()'s setTimeout-based runEventLoop now awaits
   ccall('ProcessEvents', ..., {async:true}) so the Promise rejection
   from an asyncify-suspended ProcessEvents is caught by the existing
   try/catch instead of escaping as an 'Uncaught (in promise) unwind'
   page error.

Verified: npm run test:kicad:chrome and test:kicad:firefox both pass on
the rebuilt wasm; zero pageerror events; user-reported manual flow now
selects the Draw Lines tool and draws successfully.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-01 08:32:32 +02:00
Gergő Törcsvári
d6d743340d
refactor(build): fold calculator into unified docker/build.sh dispatch
Convert the calculator port (commit 0464470) from the parallel/copy-paste
pattern to the dispatch pattern used by pcbnew + eeschema.

- docker/build.sh: <app> is now required (no pcbnew default); missing,
  unknown, and --help paths all print "pcbnew | eeschema | calculator | all".
  Adds calculator to build_app() via kicad_subdir_for() (pcb_calculator
  inner subdir, calculator.* output basename). Also fixes the
  EMSDK=/emsdkkicad-wasm-builder typo that snuck in during the calc merge.
- scripts/kicad/build-kicad-target.sh: accepts calculator; introduces
  KICAD_TARGET (pcb_calculator for calc, == APP_NAME otherwise) used for
  the make target, embind include path, and final-log line.
- scripts/kicad/build-calculator.sh: 305-line copy of build-pcbnew.sh
  collapsed to a 7-line wrapper around build-kicad-target.sh.
- tests/scripts/setup-kicad-wasm.sh: copy_app calculator added with the
  same pcb_calculator subdir mapping for the docker-volume fallback path.
- tests/package.json: test:calculator* routed through the shared
  playwright-kicad.config.ts kicad/calculator.spec.ts (mirrors eeschema).
- Delete: docker/build-calculator.sh, tests/scripts/setup-calculator-wasm.sh,
  tests/playwright-calculator.config.ts.

Bumps wxwidgets d1d1627 -> 6fb2eac (origin/wasm-port). The new sha includes
"unic/combobox: add GetCurrentSelection() inline default" which calc's
kicad/pcb_calculator/widgets/unit_selector.cpp needs to compile. Without
this bump the unified dispatch would expose calc as a buildable target but
the build itself would fail. Verified: build.sh all completes clean across
all three apps; pcbnew/eeschema e2e pass; calc compiles and launches (test
stability separate from this refactor).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-29 16:01:18 +02:00
Gergő Törcsvári
645f89b816
chore(git-workflow): add 3-repo feature branch skills + helper scripts 2026-05-29 16:01:17 +02:00
Gergő Törcsvári
730147d690
feat(schematic): eeschema WASM build + e2e harness 2026-05-29 16:01:17 +02:00
Istvan Matejcsok
0464470733 add calculator build 2026-05-28 17:28:17 +02:00
Viktor Vaczi
7331619404 diagnostics: configurable --diag logging flags + asyncify setupUIConditions fix
- build-pcbnew.sh: add --diag=<gal,coroutine,ctor,all> -> -DKICAD_DIAG_*,
  off by default (forwarded by docker/build.sh)
- diagnostics.js: emit at console.log level (no longer error/warn); still
  gated by SHIM_DIAGNOSTICS=1
- apply-asyncify.sh: exclude PCB_EDIT_FRAME::setupUIConditions() from
  asyncify instrumentation (V8 cannot run the instrumented huge function
  on the rewound ctor stack -> Chrome startup stall; Firefox unaffected)
- DEBUG.md: reusable WASM/asyncify/browser debugging guide, diagnostic
  flag docs, and a production-build (release + -O2 asyncify) recipe
- tests: standalone coroutine vcall/gl repro probes
- bump kicad + wxwidgets submodules (diagnostic gating / debug cleanup)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-27 16:14:03 +02:00
Viktor Vaczi
01dce40dc9 test(wasm): coroutine crash reproduction harness + per-engine runner
Investigation scaffolding for the Chrome-only KiCad coroutine renderer crash.
Adds isolated reproduction probes exercising the coroutine/Asyncify/fiber layer
under KiCad-like conditions, runnable in BOTH Firefox and system Chrome.

- tests/playwright-coroutine.config.ts + test:coroutine:firefox|chrome npm
  scripts: run the coroutine specs in Firefox AND system Chrome (the old e2e
  config only used bundled Chromium, which never reproduced the crash).
- tests/apps/standalone/coroutine-pthread/: no-wx + pthreads reproduction probes
  (fiber-in-main, nested invoke_/dynCall boundaries, RunMainStack, embind,
  main-loop/rAF activation) + worker_dom_stub.js for wx+pthreads builds.
- tests/apps/Makefile.wasm: coroutine-pthread{,-main,-nested,-nested-ex,-wx,
  -embind,-mainloop} targets.
- scripts/common/shims/diagnostics.js: add EM_ASYNC_JS handleSleep enter/wake
  tracking (DIAG_SLEEP) to detect nested-async at the crash.

Findings (details in research notes): every isolated factor so far — direct /
nested / RunMainStack fiber, wx event loop + all 13 scenarios incl EM_ASYNC_JS,
pthreads, and main-loop/rAF activation — runs CLEAN in system Chrome. The
coroutine/Asyncify layer is exonerated; GL/WebGL is the remaining untested factor
(next). The reliable FF-pass/Chrome-fail repro is still the KiCad pcbnew e2e.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 18:44:12 +02:00
Viktor Vaczi
a4ad69412e fix(wasm): bind dynCall_* to real DYNCALLS=1 exports; refactor shim into files
The shim bound bare dynCall_* names to JS getWasmTableEntry() calls, bypassing
the asyncify-instrumented dynCall_* wasm trampolines that -sDYNCALLS=1 provides.
That broke Asyncify unwind/rewind through indirect calls -> "indirect call
signature mismatch" (caught every frame in Firefox; fatal renderer crash in
Chrome). Bind the bare names to wasmExports["dynCall_<sig>"] instead.

Result: the PCBnew "select draw lines" e2e is green in Firefox (tool selects and
draws, zero page errors). Dropped the fiber-stabilization block, the shipped
diagnostic block, and the exportCallStack JS hack (all compensated for the wrong
binding); shim shrank 521 -> ~250 lines.

- scripts/common/inject-dyncall-shims.sh: orchestrator only; injected JS extracted
  to scripts/common/shims/
- scripts/common/shims/dyncall-binding.js.tmpl: per-signature binding template
- scripts/common/shims/handlesleep.js: nested-Asyncify handleSleep fix (#9153)
- scripts/common/shims/diagnostics.js: logging-only, opt-in via SHIM_DIAGNOSTICS=1
- tests/package.json: add test:kicad:firefox / test:kicad:chrome scripts

Known issue (tracked separately): Chrome still renderer-crashes on the first
coroutine resume. Asyncify.doRewind replays the deep main-context call stack and
exceeds V8's execution-stack limit (Firefox tolerates the same wasm). Proper fix
is JSPI.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 15:07:10 +02:00
Viktor Vaczi
9a04217788 wip: nested-asyncify fix, wxAuiToolBar registration, tests, research docs
Main-repo side of a multi-part WIP covering the KiCad WASM tool-selection
and nested-Asyncify work. Submodule commits are in kicad@f6e9239aaa
(libcontext hygiene) and wxwidgets@bb80f91e8b (auibar registration +
dialog diagnostics).

## scripts/common/inject-dyncall-shims.sh

Wrap Asyncify.handleSleep / allocateData to save-and-restore Asyncify.currData
around each EM_ASYNC_JS sleep. This fixes the nested Asyncify collision where
a fiber swap that fired during a modal's event loop clobbered currData, and
the modal's later doRewind used the fiber's buffer and hit "RuntimeError:
index out of bounds". Root cause documented as Emscripten Issue #9153
(wontfix upstream).

Diagnostic-rewind logging (forcedBottomOfCallStack, callStack traces) is
retained to help future debugging of Asyncify state corruption.

## tests/

- tests/playwright-kicad.config.ts: add `channel: 'chrome'` for the
  chromium project so --project=chromium --headed uses system Chrome
  (real GPU) instead of SwiftShader on ARM Mac. Also switch trace to
  retain-on-failure + screenshot on-failure for easier E2E debugging.
- tests/kicad/pcbnew.spec.ts: replace `tool.checked` assertions with a
  label-suffix check (`[checked]`) since our auibar registration encodes
  checked state in the label (no schema change to the registry).
- tests/apps/Makefile.wasm: add `coroutine-nested` build target + include
  it in the all: list.
- tests/apps/standalone/coroutine/: kicad_coroutine_harness.h + test app
  reproducing KiCad COROUTINE semantics against real libcontext.
- tests/apps/standalone/coroutine-nested/: nested_test.cpp reproduces the
  EM_ASYNC_JS-modal + fiber-swap nesting bug in isolation. 8 scenarios
  from baseline_modal_alone through nested_fibers_inside_modal.
- tests/e2e/coroutine.spec.ts + coroutine-nested.spec.ts: Playwright specs
  that load the standalone apps and assert all case cases pass via
  [COROUTINE_TEST] SUMMARY log parsing.

## research/ and features/browser-tools/

Three background docs capturing the investigation trajectory:

- features/browser-tools/0001-kicad-wasm-tool-activation-investigation.md
  Early investigation: why tools don't activate; initial dynCall-empty-
  callback hypothesis.
- features/browser-tools/0002-wasm-coroutine-deep-dive.md
  Deep dive on Asyncify internals, fiber API, QEMU's coroutine-wasm
  reference implementation.
- features/browser-tools/0003-wxauitoolbar-registration-fix.md
  The narrow fix: why wxAuiToolBar needs a registration block, where to
  add it, what the fallback plan is.
- research/threading_1.md: corrected root-cause analysis after reading
  runtime logs — nested-Asyncify currData collision, Emscripten #9153.
- research/threading_2.md: extended research on alternative approaches
  (JSPI/WasmFX/state-machines) and why they don't help here.

## Submodule pointer updates

kicad: f6e9239aaa (wip: libcontext WASM hygiene cleanup)
wxwidgets: bb80f91e8b (wip: wxAuiToolBar element-registry registration +
            dialog diagnostics)

## Open threads not yet in scope

- Firefox/Chrome divergent behavior: "indirect call signature mismatch"
  traps in Firefox vs renderer crash in system Chrome (tracked in
  plans/peaceful-hugging-pnueli.md and the research docs).
- E2E pixel-diff for Draw Lines fails because the test's diff region does
  not cover where the line is actually drawn; tool activation works, the
  line is visible in test-results/pcbnew-draw-lines-02-after-drawing.png.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 13:58:16 +02:00
Viktor Vaczi
6fa6c9207f feat(webgl): Migrate to pure WebGL 2.0 and fix GL canvas layering
Update submodules and build config for pure WebGL 2.0 (drop -sFULL_ES3):
- kicad: VBO-based drawing, compositor FBO rewrite, shader conversion
- wxwidgets: Fix z-index layering so GL canvas renders above 2D UI canvas
- Build: Remove FULL_ES3 from linker flags
- GAL tests: White background, opaque alpha, shared shader converter,
  updated baseline screenshots

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-20 12:38:24 +01:00
Viktor Vaczi
d557b21eac fix(docker): Replace emsdk image with Ubuntu + emsdk from source
The Docker build used emscripten/emsdk:4.0.2-arm64 as base image but
env.sh couldn't find emsdk there, installing a second copy. The build
then applied wasm-opt/finalize stubs to the wrong emsdk (hardcoded
/emsdk/), so the real wasm-emscripten-finalize ran in Docker and got
OOM-killed.

- Use ubuntu:22.04 base with emsdk installed from source at /emsdk/
- Make stub paths dynamic via $EMSDK instead of hardcoded /emsdk/
- Skip local emsdk install in env.sh when $EMSDK is already active

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 12:44:26 +01:00
Viktor Vaczi
b46b4b69f1 fix(wasm): Fix asyncify rewind with asyncify-aware dynCall shims
Emscripten 4.x removed dynCall_* WASM exports, breaking asyncify
rewind through indirect calls (modal dialogs, event handlers).
Generate JS shims that track Asyncify.exportCallStack and register
in wasmExports so doRewind can find them.

Also fixes empty callback functions ((() => {})) generated by
Emscripten 4.x + pthreads for HTML5 events, pthread entry,
sighandler, async timer, and main loop callbacks.

Build pipeline improvements:
- Stub wasm-opt/finalize in Docker (RAM limits), run on host
- Add setup-emsdk.sh for reproducible Emscripten setup
- Simplify env.sh and version management

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 12:26:48 +01:00
Viktor Vaczi
014816b7a5 fix(wasm): Fix Emscripten empty callback functions for pthreads builds
Emscripten with pthreads generates empty arrow functions `{}` for callback
paths it assumes won't be used. However, when registering HTML5 events from
the main browser thread, targetThread is 0 and the direct call path IS taken.

This fix post-processes the generated JS to replace empty callbacks with
actual dynCall invocations for:
- HTML5 event callbacks (dynCall_iiii) - 7 instances
- pthread entry points (dynCall_ii) - 1 instance
- Signal handlers (dynCall_vi) - 1 instance
- Async timers (dynCall_vi) - 1 instance

Also improves build logging to show completion status and exit code.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 14:19:13 +01:00
Viktor Vaczi
f5f81b2137 fix(build): Source env.sh in build-wasm-test.sh for Python 3.10+
Emscripten 4.0.22+ requires Python 3.10+ (uses match statement).
The env.sh script sets EMSDK_PYTHON to use Homebrew's Python
instead of the system Python 3.9.6.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 21:24:51 +01:00
Viktor Vaczi
71d2444729 feat(wasm): Disable 3D viewer with comprehensive stubs
- Set KICAD_BUILD_3D_VIEWER_WASM=OFF in build script
- Add comprehensive 3D canvas stubs (~500 lines) including:
  - EDA_3D_CANVAS with wxWidgets event table
  - BOARD_ADAPTER, EDA_3D_VIEWER_SETTINGS
  - PANEL_PREVIEW_3D_MODEL with all event handlers
  - DIALOG_SELECT_3DMODEL
  - TRACK_BALL camera
  - BBOX_2D, BBOX_3D, BVH_CONTAINER_2D
  - OGL_ATT_LIST::GetAttributesList
- Add 3D scenegraph stubs for VRML export
- Update KiCad submodule with WASM guards
- Update WebGL GAL implementation plan to COMPLETE status

All 4 phases of the WebGL GAL implementation are now complete:
- Phase 1: Native test harness (28 scenarios)
- Phase 2: WebGL GAL implementation (~27,800 lines)
- Phase 3: Complete API coverage
- Phase 4: KiCad integration with 3D viewer stubs

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 15:15:50 +01:00
Viktor Vaczi
37d973f064 refactor(webgl): Move WebGL GAL from test harness to KiCad source tree
Migrate WebGL GAL implementation from tests/gal-regression/wasm/webgl/
to kicad/common/gal/webgl/ and kicad/include/gal/webgl/.

This integrates the WebGL GAL properly into KiCad's build system:
- Update test Makefile to use sources from kicad/ instead of local copies
- Update build scripts for new source locations
- Add test-gal-webgl.sh script for running WebGL regression tests
- Update Docker to Emscripten 4.0.22

The WebGL GAL passes all 28 regression tests (matching baseline).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 13:15:58 +01:00
Viktor Vaczi
1b1a9d1633 fix(test): Exclude transform-api from comparison and add diagnostics
Changes:
- Exclude gal-transform-api.png from native/WebGL comparison since
  Transform() is dead code in KiCad (never called, has no effect)
- Add verbose diagnostic output showing pixel difference details,
  content bounds, and sample pixels for failing scenarios
- Update README to document that Transform() is dead code in both
  native and WebGL implementations

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-09 14:48:23 +01:00
Viktor Vaczi
51bdcffacb fix(build): Source common env.sh in wxuniversal build script
Ensures EMSDK_PYTHON is set correctly for Emscripten 4.0.22+ which
requires explicit Python path configuration.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-09 14:48:23 +01:00
Viktor Vaczi
92466d728c fix(webgl): Add ClearTarget and always rebuild in test script
1. gal_webgl_test.cpp: Add ClearTarget(TARGET_NONCACHED) before ClearScreen()
   - Matches native test harness behavior
   - Fixes accumulated content from previous scenarios
   - arc-segments now 10% different (was 86% due to content accumulation)

2. test-gal-regression.sh: Remove "skip if already built" check
   - Always rebuild to pick up code changes
   - Single script is the source of truth for full test cycle

Current results:
- 3 scenarios MATCH (<1%): basic-lines, arcs, transforms
- Many scenarios close (~10%): arc-segments, circles, hole-walls, etc.
- Some features not implemented (97-100%): glyphs, text-attrs, bitmap

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-08 11:37:41 +01:00
Viktor Vaczi
8f803b45ea fix(test): Fix WebGL screenshot capture and comparison
1. Fix gal-webgl.spec.ts sequential test:
   - Wait for isReady() not just module existence
   - Use .gl-canvas selector (same as individual tests)
   - Increase timeout from 50ms to 100ms
   - This fixes blank screenshots in full test runs

2. Fix test-gal-regression.sh comparison:
   - Normalize PNG format before comparing (flatten + sRGB TrueColor)
   - This handles RGBA vs RGB and palette differences
   - gal-basic-lines now passes comparison (0.34% different)

Results after fixes:
- Native vs Baseline: PASSED (28/28)
- WebGL screenshots now capture actual rendered content
- gal-basic-lines matches native (first successful scenario!)
- Other scenarios have rendering differences to investigate

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-08 11:32:39 +01:00
Viktor Vaczi
d0e2500048 feat(webgl): Enable all 28 scenarios for WebGL test harness
- Update wasm/Makefile to compile ALL scenario files using wildcard
- Add conditional compilation to scenario_bitmap.cpp (#ifdef __EMSCRIPTEN__)
  to handle OpenGL-specific shader workaround code for native only
- Change canvas dimensions to 1600x1200 to match native baseline (2x Retina)
- Set white background color to match native screenshots
- Update gal-webgl.spec.ts to hide UI overlay before taking screenshots
- Improve test-gal-regression.sh with better ImageMagick comparison

All 28 scenarios now compile and run on both native and WebGL backends.
Native vs baseline: PASSED (28/28 matching)
WebGL rendering: In progress (primitives not yet visible)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-08 11:11:03 +01:00
Viktor Vaczi
d2f1a496f5 feat(webgl): Replace legacy GL with modern OpenGL ES 3.0
Major refactoring to remove ALL legacy OpenGL immediate mode calls from
WEBGL_GAL and replace them with WebGL 2.0/OpenGL ES 3.0 compatible code.

Key changes:
- Add MVP matrix uniform support (replaces glMatrixMode/glOrtho/glLoadMatrix)
- Add matrix math helpers (computeOrthoMatrix, multiplyMatrix4x4, etc.)
- Replace glBegin/glEnd/glVertex with vertex manager pattern
- Rewrite DrawCursor to use vertex manager and DrawLine() calls
- Rewrite DrawBitmap to use vertex manager with SHADER_FONT mode
- Replace glEnableClientState with glVertexAttribPointer
- Replace glDrawBuffer with glDrawBuffers (WebGL 2.0 API)
- Add fullscreen_quad.cpp/h for compositor Present()
- Update SHADER class with mat4 uniform support
- Add MultiplyMatrix() to vertex_manager for Transform()
- Remove all legacy GL stubs from wasm_stubs.cpp

Build now completes with FULL_ES3 mode (no LEGACY_GL_EMULATION).
Remaining issue: wxWidgets GL library calls glColor3f internally.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-07 23:33:49 +01:00
Viktor Vaczi
6c2cf85177 feat(webgl): Fix GL initialization and add GLSL ES shader conversion
Progress on WEBGL_GAL rendering:

- Fix GLImmediateShim initialization by adding GL function dependencies
  (glBegin, glEnd, glVertex2f, etc.) to $GLImmediateShim__deps
- Add COLOR4D(EDA_COLOR_T) constructor stub to wasm_stubs.cpp
- Fix GAL context locking - add LockContext/UnlockContext calls
- Add exception catching to build (-sNO_DISABLE_EXCEPTION_CATCHING)
- Create GLSL ES 1.00 shader converter in generate_shaders.py:
  - Remove #version 120 directive (ES 1.00 default)
  - Add precision highp float/int qualifiers
  - Convert int * float to float literals (2 * x -> 2.0 * x)
- Update build script to clean output files for linker flag changes
- Add console capture to test spec for debugging

Current status:
- WASM builds and loads successfully
- GLImmediateShim initializes correctly
- WEBGL_GAL creates successfully
- Shader compilation fails due to Emscripten LEGACY_GL_EMULATION
  prepending code that conflicts with custom shader precision

Next: Investigate shader compilation with LEGACY_GL_EMULATION or
consider alternative approaches for GL compatibility.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-07 21:59:21 +01:00
Viktor Vaczi
a4f444fea8 feat(webgl): Add WebGL GAL test infrastructure (Phase 1)
Add complete test infrastructure for WebGL GAL visual regression testing:

- scripts/test-gal-regression.sh: Master script that builds both backends,
  runs tests, and performs two-level comparison (native vs baseline,
  webgl vs native)
- scripts/build-gal-webgl-test.sh: WASM build using Makefile with em++
- tests/gal-regression/wasm/: WebGL test harness (stub WEBGL_GAL)
- tests/e2e/gal-webgl.spec.ts: Playwright test for screenshot capture

Fix Homebrew Emscripten environment in scripts/common/env.sh:
- Set EMSDK_PYTHON for Python 3.10+ (em++ reads this, not $PYTHON)
- Add bundled LLVM to PATH (Emscripten needs its clang with WASM backend)

Verified: Native vs Baseline passes (28/28), WebGL generates blank
screenshots as expected (WEBGL_GAL implementation is Phase 2).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-07 16:11:31 +01:00
Viktor Vaczi
650109e10f feat(webgl): Add 4 new GAL test scenarios for expanded coverage
Expand test coverage from ~19% to ~25% of GAL API with modular scenario files:
- bezier-curves: Tests DrawCurve() with S-curves, waves, hearts, and control points
- arc-segments: Tests DrawArcSegment() with thick arc strokes (PCB trace style)
- segment-chain: Tests DrawSegmentChain() with zigzags, spirals, sharp corners
- group-caching: Tests BeginGroup/EndGroup/DrawGroup for cached geometry

Architecture:
- New scenarios in separate files under scenarios/
- Forward declarations in main gal_test_scenarios.cpp
- CMakeLists.txt updated to compile new scenario modules

Also:
- Remove unused build-wxwidgets-native.sh (using system wxWidgets)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-07 09:58:52 +01:00
Viktor Vaczi
490f531521 feat(webgl): Add GAL native test harness for visual regression testing
Add a standalone test application that compiles KiCad's actual OPENGL_GAL
against system wxWidgets to generate baseline screenshots for comparing
native OpenGL rendering against WebGL rendering in the browser.

Architecture:
- Compiles 18 KiCad GAL source files from the kicad submodule
- Uses template-based private member accessor (safer than #define private public)
- Generates shader C++ files from GLSL (10 shader pairs for SMAA AA)
- Minimal stubs for KiCad dependencies (PGM_BASE, ADVANCED_CFG, etc.)

Test coverage:
- 11 scenarios testing ~19% of GAL API
- basic-lines, line-widths, circles, arcs, rectangles, polygons
- alpha-blending, transforms, grid-cursor, segments, complex-scene

Key insights documented:
- GAL uses world-to-screen transformation requiring 1:1 pixel mapping
- FBO reading required for clean screenshots on macOS
- Layer depth needed for proper z-ordering in complex scenes

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-07 09:42:31 +01:00
Viktor Vaczi
5147917ea7 Add feature branch patch management system
Rename docs/ to features/ with per-feature folders. Add script to generate
patches for root repo and submodules.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-06 16:17:52 +01:00
Viktor Vaczi
e89a54dcb2 Merge branch 'fix-kicad-tests' 2026-01-05 16:32:14 +01:00
Viktor Vaczi
5d93e11358 Fix indirect call to null error and logging.sh worktree support
wxwidgets submodule:
- Add m_isCreated flag to skip UpdateElementRegistry() during construction
- Prevents virtual method calls on partially constructed objects

scripts/common/logging.sh:
- Change -d to -e for .git check to support git worktrees

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-05 16:25:11 +01:00
Viktor Vaczi
85e0f2f59a Reduce KiCad fork divergence with CMake cleanup
- Update kicad submodule: reverted 12 Find*.cmake to upstream,
  deleted FindCURL.cmake (-284 lines, -13 files changed)
- Add GLM_VERSION to build-pcbnew.sh (workaround for KiCad
  overwriting CMAKE_MODULE_PATH)
- Update kicad-diff-stats.sh to compare working tree vs upstream

Fork diff reduced from 81 to 68 files.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-05 14:03:03 +01:00
Viktor Vaczi
c2a69cf9db Add KiCad fork diff statistics script
- scripts/kicad-diff-stats.sh: Shows how far our KiCad fork has diverged
  from upstream (last non-our commit)
- Outputs: commit count, files changed, lines added/deleted, file list
- Logs to logs/kicad-diff/ with timestamps
- Update CLAUDE.md with script reference

Current status: 5 commits, 81 files, +1536/-395 lines on top of upstream

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-05 11:16:46 +01:00
Viktor Vaczi
ea5dc26a96 Restore elementtracker.h and add build logging
- Restore missing elementtracker.h in wxWidgets (required for E2E tests)
- Add automatic log file redirection for build scripts

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-03 11:55:54 +01:00
Viktor Vaczi
cb58b43bd1 Enable OpenGL GAL and 3D viewer stubs for WASM
Changes:
- Add glu_wasm_impl.cpp: GLU tesselator using KiCad's earcut triangulation
- Add GL/glu.h: GLU header for WASM builds
- Add 3D viewer stubs for KICAD_BUILD_3D_VIEWER_WASM=ON
- Remove obsolete gl_canvas_stub.cpp (OpenGL now uses real impl)
- Remove obsolete glu_stub.c (replaced by glu_wasm_impl.cpp)
- Update build-pcbnew.sh comment about GLU implementation

The OpenGL GAL now works in WASM using WebGL with LEGACY_GL_EMULATION.
3D viewer is stubbed out but builds successfully.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-03 08:19:40 +01:00
Viktor Vaczi
b5d379fe70 Add runtime resource loading and fix Docker incremental builds
- Build images.tar.gz bitmap archive for KiCad icons
- Fetch resources at runtime via HTTP instead of bundling in WASM
- Write to Emscripten virtual FS at compile-time KICAD_DATA path
- Fix rsync timestamp handling for correct make change detection
- Update kicad submodule with WASM settings manager fix

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 20:09:26 +01:00
Viktor Vaczi
98b523c2bc Fix clean build issues
- Add autoreconf step for bundled PCRE in wxWidgets build script
  (fixes automake version mismatch between 1.16.1 and 1.16.5)
- Fix apply-finalize.sh to use get-wasm-opt.sh for consistent tool paths
  (tools moved to build-wasm/tools/ in previous commit)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 15:28:20 +01:00
Viktor Vaczi
9cd5965b2c Move tools/ to build-wasm/tools/
Groups cached build tools (binaryen) with other build artifacts.
The build-wasm/ directory is already gitignored via build-*/ pattern.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 14:08:47 +01:00
Viktor Vaczi
a26b40c063 Reorganize project structure for clarity
- Rename tests/wasm-app/ to tests/apps/ for brevity
- Move lib/gl_immediate_shim.js to wasm/shims/ (consolidates WASM files)
- Delete docs/ directory (outdated Nov 2024 research docs)
- Delete patches/ directory (already applied to fork submodules)
- Delete wasm/patches/ and wasm/config/ (empty/unused)
- Update all file references in scripts, configs, and documentation
- Update .gitignore for new tests/apps/ paths

Verified both build workflows pass:
- wxWidgets tests: 255 passed
- Docker KiCad build: completed successfully

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 14:06:23 +01:00
Viktor Vaczi
c4cd69f28d Make build scripts use incremental builds by default
- build-wxuniversal-wasm.sh: Default to incremental, add --clean flag
- build-wasm-test.sh: Remove automatic clean, add --clean flag

Performance:
- No changes: ~0.3s (was full rebuild)
- Single file change: ~5s (just that file)
- Clean rebuild: use --clean flag

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 11:26:25 +01:00
Viktor Vaczi
a88652279b Remove unused legacy build scripts and directories
Clean up obsolete files that are not part of the current build workflows:

Deleted:
- cmake/ - Old native build CMake modules
- core/ - Old core extraction from Nov 2024
- stubs/ - Old stubs for native build
- scripts/build.sh - Old native build script
- scripts/build-core-wasm.sh - Old core library build
- scripts/build-wxbase-wasm.sh - Old CMake-based wxBase
- scripts/build-kicad-wasm.sh - Old standalone kicad build
- scripts/build-wxwidgets-wasm-clean.sh - Patch testing script
- scripts/generate-wxwidgets-patches.sh - Patch generation
- scripts/prepare.sh - Old patch apply script
- scripts/update-kicad.sh - Old kicad update script
- CMakeLists.txt - Old native build root
- wxWidgets-wasm-reference submodule - Unused reference clone

Both workflows verified working after cleanup:
1. KiCad: docker/build.sh → tests/scripts/setup-kicad-wasm.sh → npm test
2. wxWidgets: scripts/build-wxuniversal-wasm.sh → scripts/build-wasm-test.sh → npm test

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 11:07:54 +01:00
Viktor Vaczi
768d33339a Remove .git from meson subprojects to keep IDE clean
Meson clones subprojects (like freetype) as full git repos and creates
.meson-subproject-wrap-hash.txt which shows as untracked. IDEs detect
these nested repos and show dirty status in commit sidebar.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 09:37:20 +01:00
Viktor Vaczi
23a23fd7a6 Add autom4te wrapper to keep submodules clean
Disable autom4te cache creation during autoconf runs by setting AUTOM4TE
to a wrapper that passes --no-cache. This prevents autom4te.cache directories
from appearing in submodules (pcre, etc.) and making them show as dirty.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 09:21:31 +01:00