pcbjam/wasm
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Gergő Törcsvári ab6e44e57f
docs 22 + wx bump: DOM entries on the dispatch context; canvas tools green at D-on
The increment doc 22 ordered last round. Every entry that can reach a tool
coroutine - the four DOM callbacks and the mailbox tick - now goes through the
scheduler, so a coroutine is never entered by a star transfer from one path and
a direct symmetric swap from another. At D-on all four canvas-tool specs are
GREEN and the KiCad suite is 136/3 (was 135/5 before the sleep work, with the
tools red throughout).

context_sleep's wake learned the mirror lesson: now that the mailbox runs ON a
context, it must NOT call drain_all from there (drain refuses re-entry, and
should) - it marks ready and lets the outer drain_all perform the entry, with
an armed pump as a backstop.

Recorded honestly, not papered over: two of the three remaining D-on failures
are the timer-park and quasimodal-strand levers, each failing ONE assertion -
"scheduler shim observed the concurrent-park window", expected >0, got 0 -
while fired/done/parked/errors all pass. That counter needs TWO concurrent
in-place Asyncify parks, and the lever stages "timer park x MAIN-LOOP YIELD
PARK"; D5 removed the main loop's Asyncify park, so the overlap cannot occur.
Re-pinning those levers to the post-migration invariant is a Phase F decision
alongside fiber-resume-park's red->green flip, NOT an assert to relax now.

Landing state: STAR_DISPATCH=0, kicad 139 passed / 1 (pre-existing occ-probe).
Next: Phase E - the K1-K7 bridges are the only in-place parks left under a
context, and are exactly what the current()!=0 fallback still tolerates.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LBjomQfKyRa3jBdeAKpmTw
2026-08-10 10:14:19 +02:00
..
bindings design-b D3: fix the doc-19 hang — quasi-modals off the coroutine stack 2026-08-10 10:14:17 +02:00
cli plugins 0002: kicad_tools --ipc356 + --fab-components fab exporters 2026-07-27 14:01:30 +02:00
cmake eeschema simulator: lazy ngspice_service worker — static sharedspice (XSPICE registry + CIDER), init_dll ifdef, e2e both engines 2026-07-19 15:59:21 +02:00
editor cvpcb-wasm: link CvPcb as third kiface — eeschema Assign Footprints opens in WASM; serial-inline footprint list load fixes pool-task-vs-JS-bridge deadlock 2026-07-17 18:00:13 +02:00
gl1 feat(3d): gl1 shim M4+M6+M7 — GLU quadrics, production link, stub retired; 47/47 parity 2026-07-03 15:45:58 +02:00
kiplatform fix(wasm): KiCad 10 kiplatform/libgit2 stubs, e2e fixtures, asyncify -g hook 2026-06-24 10:30:25 +02:00
ngspice-service eeschema simulator: lazy ngspice_service worker — static sharedspice (XSPICE registry + CIDER), init_dll ifdef, e2e both engines 2026-07-19 15:59:21 +02:00
occ-service feat(occ): ship board 3D model bodies with STEP/GLB exports (3d-models 0007) 2026-07-10 09:26:07 +02:00
shims docs 22 + wx bump: DOM entries on the dispatch context; canvas tools green at D-on 2026-08-10 10:14:19 +02:00
stubs eeschema simulator: lazy ngspice_service worker — static sharedspice (XSPICE registry + CIDER), init_dll ifdef, e2e both engines 2026-07-19 15:59:21 +02:00
tools feat: kicad_tools headless CLI 2026-07-10 19:09:01 +02:00
README.md refactor: 💡 remove orphaned files 2026-06-05 13:18:24 +02:00

WASM Compatibility Layer

This directory contains WASM-specific implementations that allow KiCad to run in a web browser while keeping our KiCad fork as close to upstream as possible.

Principle

Instead of patching KiCad source files, we:

  1. Provide alternative implementations for platform-specific code (kiplatform)
  2. Stub out libraries/features that can't work in the browser (libgit2, curl, nng, scripting, 3D viewer, ...)
  3. Expose KiCad to JavaScript via Embind bindings
  4. Override host package detection during cross-compilation (cmake find-modules)

The KiCad-side hooks for this are small if(EMSCRIPTEN) branches in KiCad's own CMakeLists that pull sources from this directory — see "How it's wired" below.

Directory Structure

wasm/
├── README.md               # This file
├── kiplatform/             # Platform abstraction implementations (compiled into KiCad)
│   ├── app.cpp             # App lifecycle (paths, startup)
│   ├── drivers.cpp         # GPU detection (returns "WebGL")
│   ├── environment.cpp     # Environment variables
│   ├── io.cpp              # File I/O (WASM virtual filesystem)
│   ├── policy.cpp          # Security policy (always permissive)
│   ├── secrets.cpp         # Credential storage
│   ├── sysinfo.cpp         # System information
│   ├── printing.cpp        # Print support (browser print())
│   └── ui.cpp              # UI helpers
├── bindings/               # Embind bindings exposing each app to JavaScript
│   ├── pcbnew_embind.cpp
│   ├── eeschema_embind.cpp
│   ├── pl_editor_embind.cpp
│   └── calculator_embind.cpp
├── stubs/                  # Stub implementations + header shims for unavailable deps
│   ├── *.c / *.cpp         # libgit2, curl, nng, scripting, 3D viewer, frame stubs, ...
│   ├── char_traits_uint16_workaround.h
│   └── GL/ nng/ ngspice/   # Header stubs found via include paths
└── cmake/                  # CMake find-module overrides for cross-compilation
    └── Find*.cmake / Use*.cmake

How it's wired

kiplatform — compiled into KiCad

The kiplatform/*.cpp files are added directly to KiCad's kiplatform library by an if(EMSCRIPTEN) branch in kicad/libs/kiplatform/CMakeLists.txt, which references them as ${PROJECT_SOURCE_DIR}/../wasm/kiplatform/*.cpp. There is no separate libkiplatform_wasm.a.

stubs — compiled by the build script and KiCad CMakeLists

scripts/kicad/build-kicad-target.sh compiles the C stubs (libgit2_stub.c, curl_stub.c, nng_stub.c) and force-includes char_traits_uint16_workaround.h. App-specific *_frame_stub.cpp / *_scripting_stub.cpp are picked up per app, and the remaining *_stub.cpp files are pulled in by if(EMSCRIPTEN) branches in the KiCad fork's own CMakeLists. Header stubs under GL/, nng/, ngspice/ are resolved via include paths.

bindings — per app

build-kicad-target.sh compiles wasm/bindings/<app>_embind.cpp for the app being built (apps without an embind file get an empty placeholder object).

cmake — module path

build-kicad-target.sh passes -DCMAKE_MODULE_PATH="${PROJECT_ROOT}/wasm/cmake" so the WASM find-module stubs override host package detection.

Coroutine/fiber support is not in this directory — it comes from the KiCad fork's kicad/thirdparty/libcontext/libcontext.cpp (LIBCONTEXT_PLATFORM_wasm32). The GLU tesselator comes from kicad/libs/kimath/glu_tess/glu_tess_impl.cpp.

Adding New Implementations

  1. Create the implementation file in the appropriate directory (kiplatform/, stubs/, bindings/).
  2. Wire it in: a stub C file goes in build-kicad-target.sh; a kiplatform/app source goes in the relevant if(EMSCRIPTEN) branch of the KiCad-side CMakeLists.
  3. Ensure the header interface matches KiCad's expected interface.
  4. Test with a minimal build before full integration.