Commit graph pcbjam/scripts
Author SHA1 Message Date
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
Viktor Vaczi
dafef9c0a1 Fix Docker macOS timestamp issues and improve build reproducibility
- Add rsync-based source sync for Docker builds to fix macOS VirtioFS
  timestamp inconsistencies that caused autoconf sanity checks to fail
- Add config.sub wrapper (SHELL/CONFIG_SHELL) to support emscripten/wasm32
  targets without modifying submodule files
- Fix protobuf build to use native gcc/g++ for protoc instead of Emscripten
- Add python PATH fix for macOS (Homebrew's python3 symlink) in wxWidgets build

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 01:07:44 +01:00
Viktor Vaczi
5b919ef66f Add ccache and incremental build system for faster development
- Add ccache to Docker image for compiled object caching
- Change build defaults: incremental by default, skip deps by default
- Add new flags: --full, --clean-kicad, --build-deps
- Skip wxWidgets configure if already configured (check Makefile timestamps)
- Remove unused source hash stamp functions (make handles dependencies)
- Update build.md with new build system documentation

Performance improvements:
- Single file change: 7:35 → 1:34 (4.8x faster)
- No-change rebuild: 7:35 → 1:31 (5x faster)
- Asyncify post-processing (~1 min) is now the bottleneck

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-26 20:51:58 +01:00
Viktor Vaczi
9c271996c2 Fix KiCad WASM build and runtime errors
Build improvements:
- Change -O0 to -O1 to fix "local count too large" asyncify error
- Add wasm-emscripten-finalize to host (Docker OOMs on large WASM)
- Use -gseparate-dwarf for smaller main binary with debug info
- Build native protoc for code generation
- Add more functions to asyncify removelist

Runtime fixes:
- Add inject-dyncall-shims.sh to fix "dynCall_* is not defined" in Emscripten 4.x
- Update wxwidgets with browserInfo.name fix

New stubs and bindings:
- Add Embind bindings for JavaScript interop
- Add stubs for scripting, API plugin, PCB frame, navlib

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-22 16:30:53 +01:00
Viktor Vaczi
898e079ef2 Enable 3D viewer in KiCad WASM build
Build the 3D viewer code for WASM instead of stubbing it out.
This is simpler to maintain than complex header stubs.

Changes:
- Enable KICAD_BUILD_3D_VIEWER_WASM=ON in build script
- Remove -gsource-map to avoid OOM in wasm-emscripten-finalize
- Add OpenGL stubs for fixed-function pipeline (WebGL ES 2.0 only)
- Add GLU stub for gluErrorString
- Add NNG stub for IPC API (sockets don't work in WASM)
- Add PCBnew scripting stub
- Expand curl and libgit2 stubs

The 3D viewer code compiles but won't render at runtime since
OpenGL GAL is disabled and Cairo GAL is used instead.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-21 14:21:29 +01:00
Viktor Vaczi
74a2dc2c0f Use all available cores for wxWidgets build by default
Change JOBS default from 1 to auto-detect using nproc/sysctl.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-15 15:59:23 +01:00
Viktor Vaczi
ad5c4f6772 Fix pthread deadlock by using dynamic PTHREAD_POOL_SIZE
The KiCad WASM build was freezing during initialization due to a pthread
deadlock. When hardware_concurrency() > PTHREAD_POOL_SIZE, new Web Worker
creation requires the event loop, but the main thread busy-waits blocking it.

Changes:
- Use navigator.hardwareConcurrency for PTHREAD_POOL_SIZE in KiCad build
- Add threadpool test to reproduce and verify the fix
- Add single-target build support to build-wasm-test.sh
- Default docker/build.sh to -j 10 for faster builds

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-15 11:47:50 +01:00
Viktor Vaczi
a3445575db Fix KiCad WASM startup issues
- Increase thread pool size from 4 to 8 with STRICT=0 to prevent
  "thread pool exhausted" errors when KiCad creates worker threads
- Add thisProgram='/usr/bin/pcbnew' to provide absolute path for
  argv[0], fixing "No meaningful argv[0]" DEBUG check in KiCad

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 16:09:04 +01:00
Viktor Vaczi
4a9c23bbcb Fix wxWidgets build for portable zlib and window sizing
Build script changes:
- Use embuilder to build zlib port (works in Docker and on host)
- Use em-config CACHE for portable sysroot path
- Fix symlink creation to avoid "same file" errors on re-runs

wxWidgets submodule update:
- Fix toplevel window sizing to return 1280x720 instead of 20x20
- Handle default size like GTK/MSW ports before passing to base class

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 15:33:54 +01:00
Viktor Vaczi
8453f9681e Add stamp source hashing and maximize test infrastructure
- Add source hashing to stamp system (functions.sh) for detecting
  when dependencies need rebuild based on source file changes
- Update build-pcbnew.sh to use source stamps for wxWidgets
- Add global-setup.ts to clean logs before test runs
- Add maximize_test standalone test to verify wxFrame::Maximize()
  works correctly in WASM (it does - window is 1280x720)
- Update Makefile.wasm with maximize test build rules

The maximize_test proves wxWidgets display detection works fine.
KiCad's 20x20 window bug is KiCad-specific, not a wxWidgets issue.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 13:28:43 +01:00
Viktor Vaczi
6771e7de74 Fix Asyncify and improve build process
Build system improvements:
- Add wasm-opt stub for Docker build to bypass asyncify in container
- Add apply-asyncify.sh script for host-side asyncify transformation
- Update build-pcbnew.sh to install wasm-opt stub and add EXPORTED_RUNTIME_METHODS
- Add --with-zlib=sys to wxWidgets configure for proper zlib linking
- Improve update-baseline-screenshots.sh to only copy new/significantly changed files

wxWidgets submodule update:
- Fix EM_JS to EM_ASYNC_JS for proper Asyncify registration

Test updates:
- Add new baseline screenshots for bitmapbuttons, dnd, gridrenderers, printpreview, specialized tests
- Add kicad-pcbnew initial screenshot
- Fix wxgrid-controls.png and wxgrid-dedicated-page.png (were showing errors)

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 11:59:50 +01:00
Viktor Vaczi
b70f098ae2 Add two-phase build with host asyncify transformation
- Move asyncify from Docker to host to avoid memory issues
- Auto-download Binaryen v121 (v125 has regression bug)
- Use -O1 for debug builds (V8 local count limit)
- Remove asyncify flags from linker (handled by wasm-opt)
- Document two-phase build in build.md

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-13 22:13:31 +01:00
Viktor Vaczi
d8d934ffca Enable exceptions and pthreads atomics for KiCad WASM build
Build fixes:
- Enable C++ exceptions in wxWidgets (--enable-exceptions, -fexceptions)
  Required for KiCad's OnExceptionInMainLoop override in debug builds
- Add -matomics -mbulk-memory to all dependency builds for shared memory
  Required for pthreads support with Emscripten
- Fix docker/build.sh output copy path (pcbnew/ not bin/)
- Make workspace mount read-only in docker-compose.yml

Updated dependency scripts:
- build-freetype.sh, build-harfbuzz.sh, build-protobuf.sh
- build-zstd.sh, build-opencascade.sh, build-boost.sh
- build-pixman.sh, build-cairo.sh (meson cross-file)
- build-wxuniversal-wasm.sh, build-pcbnew.sh

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-13 11:29:45 +01:00