The runtime is JSPI-only; this removes everything that still pretended otherwise. Three exhaustive sweeps (C++/JS+build+CI/tests+docs) drove the inventory; every deletion verified by grep closure + full gates. Broken-right-now fixes: - deploy-staging.yml passed the retired opt_level input — the workflow could not even start. Removed. - env.sh carried dead exports with a live -sASYNCIFY=1 inside (WASM_LDFLAGS/PTHREAD_LDFLAGS, zero consumers). Removed; the WASM_LEGACY_EXCEPTIONS rationale rewritten to the real reason. - docker/build.sh exported PCBJAM_ASYNC_BACKEND (read nowhere). Gone. Dead weight removed: - binaryen submodule (nothing builds or invokes it), wasm-opt-bench workflow + scripts/bench/, get-wasm-opt.sh, diagnostics.js (242 lines of Asyncify-API-only code), the KICAD_PIPELINE background-postprocess scaffolding (existed to parallelize the deleted wasm-opt phase; the postprocess is a seconds-long node script and now runs inline), build-monitor's dead asyncify rows, sched-context orphan build output, dead .gitignore entries, the .jspi-assets spike dir (the two wf-result research JSONs moved to docs/features/async/migration-evidence/). - bindings: fiber_park.h + its 12 embind registrations (broken-if- called under JSPI), the kicadOpenFileStart/OPEN_JOB starter route, main_stack_runner.h + 5 includes, the always-null context-sleep weak hook in nanosleep_yield.c. - shim: the backend field (installed-flag idempotency instead), noteContextWait (dead both sides), the __wxAsyncifyDump alias (+ the WasmTool fallback and string-dump normalize branch). - web: the emscripten-6-ignored mainScriptUrlOrBlob option in boot.ts (gerber-demo keeps it: it loads the deployed CDN release, which predates emscripten 6 — noted inline). Conditionals: all 'backend === jspi' checks reduced to scheduler- presence checks; races_quiescent re-keyed from Asyncify.state (vacuous) to real backlog quiescence (resumeReady/mutatorQueue — NOT _windowLive, which is the probing activation's own window by definition). Renames (identifiers only, no file renames): ASYNC_LINK_FLAGS→ JSPI_LINK_FLAGS and Makefile ASYNC_LDFLAGS→JSPI_LDFLAGS, kicadCollabFiberBusy→kicadCollabBusy (embind + web + tests), collab_common.h fiber*→apply*/coroutine naming, asyncifySignatures→ wasmTrapSignatures (lists byte-identical). Tests: the two remaining vacuous [wx-asyncify]/fiber-resume-refused asserts re-keyed to live JSPI beacons; eeschema-load's failure message no longer sends the developer to a deleted script; wait-beacons' dead families/parser deleted; lane-0 legacy-glue guards removed (lane 0 is unconstructible); the embind test.fail re-gated with the JSPI reason (plain embind invokers cannot suspend — verified still failing); lint-determinism now scans tests/jspi (166 files clean); eeschema-collab local-move gated to chromium (~50% flaky on FF even solo; pcbnew twin covers both engines). Docs: DEBUG.md rewritten as the JSPI debugging guide; build.md describes the single-phase build; docs/features/async/README.md banner-marked historical and repointed at the NEW 23-jspi-runtime.md (current architecture: export census, turnstile, libcontext ownership + refusal contract, embind call shapes, the em-pthread service-wrapper trick, exception policy, known gaps). Gates on the cleaned tree: test:e2e 725 passed / 0 failed (after the quiescence-probe fix; the 3 other reds were verified contention flakes solo-green or the documented FF gate), web 76/0, jspi 18/18 both engines, vitest 295/295 + 17/17, all lints green, live-app census clean. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016X9eh1s5sTx1o9Em9KBuwR
79 lines
4.1 KiB
CMake
79 lines
4.1 KiB
CMake
# ngspice_service — ngspice's sharedspice engine as a standalone emscripten
|
|
# module run in a dedicated Web Worker (the SPICE analog of wasm/occ-service).
|
|
# The eeschema simulator drives it over postMessage RPC via the sharedspice
|
|
# client stub (wasm/stubs/sharedspice_client.cpp); the editor bundle links no
|
|
# ngspice code at all.
|
|
#
|
|
# Unlike occ_service this module contains NO KiCad or wxWidgets code, so it is
|
|
# NOT hooked into the kicad CMake tree: it configures standalone against the
|
|
# sysroot artifacts produced by scripts/deps/build-ngspice.sh (see
|
|
# scripts/kicad/build-ngspice_service.sh).
|
|
#
|
|
# Threading: ngspice's bg_run spawns its own pthread; the module main thread
|
|
# stays free to service RPC (bg_halt, status, vector reads) mid-simulation.
|
|
# The 4MB/2MB stacks are load-bearing: ngspice's parser overflows emscripten's
|
|
# default 64KB stack (found by the Gate-1 smoke; the CIDER deck died parsing
|
|
# spinit). Nothing in the service suspends, so no JSPI.
|
|
# PTHREAD_POOL_DELAY_LOAD: boot must not block on the pool — Firefox stalls
|
|
# nested-worker spawning under multi-page pressure (the SECOND simulator
|
|
# session in an e2e run hung forever in module boot without it); bg_run's
|
|
# thread starts as soon as a pool worker lands.
|
|
|
|
cmake_minimum_required( VERSION 3.20 )
|
|
project( ngspice_service CXX )
|
|
|
|
if( NOT EMSCRIPTEN )
|
|
message( FATAL_ERROR "ngspice_service is an emscripten-only target (use emcmake)" )
|
|
endif()
|
|
|
|
if( NOT NGSPICE_SYSROOT )
|
|
message( FATAL_ERROR "pass -DNGSPICE_SYSROOT=<build-wasm/sysroot> (run scripts/deps/build-ngspice.sh first)" )
|
|
endif()
|
|
|
|
# The exception model must match the objects in libngspice.a (DEPS_EH_FLAGS
|
|
# from scripts/common/env.sh: wasm EH + wasm setjmp/longjmp — sharedspice's
|
|
# error recovery longjmps through errbufm/errbufc). Passed by
|
|
# scripts/kicad/build-ngspice_service.sh.
|
|
if( NOT NGSPICE_EH_FLAGS )
|
|
message( FATAL_ERROR "pass -DNGSPICE_EH_FLAGS=\"\${DEPS_EH_FLAGS}\" (see scripts/common/env.sh)" )
|
|
endif()
|
|
separate_arguments( NGSPICE_EH_FLAGS_LIST UNIX_COMMAND "${NGSPICE_EH_FLAGS}" )
|
|
|
|
set( NGSPICE_LIB_DIR "${NGSPICE_SYSROOT}/lib" )
|
|
set( NGSPICE_CM_DIR "${NGSPICE_SYSROOT}/lib/ngspice" )
|
|
|
|
add_executable( ngspice_service ngspice_service_main.cpp )
|
|
|
|
target_include_directories( ngspice_service PRIVATE "${NGSPICE_SYSROOT}/include" )
|
|
|
|
# The sysroot libngspice.a is built with XSPICE; sharedspice.h guards the
|
|
# XSPICE-only declarations (ngCM_Input_Path & co.) behind this define.
|
|
target_compile_definitions( ngspice_service PRIVATE XSPICE )
|
|
|
|
# -pthread at COMPILE stage too (atomics/bulk-memory object features must
|
|
# match --shared-memory at link).
|
|
target_compile_options( ngspice_service PRIVATE -pthread ${NGSPICE_EH_FLAGS_LIST} )
|
|
|
|
# The .cm archives resolve through the static code-model registry appended to
|
|
# dev.c (its extern table references pull each archive's tables member, which
|
|
# pulls that model's cfunc/ifspec objects); ngcm_common.a carries the shared
|
|
# dlmain utility tail + tline commons. lld's implicit group semantics handle
|
|
# the cm -> core back-references.
|
|
target_link_libraries( ngspice_service PRIVATE
|
|
"${NGSPICE_LIB_DIR}/libngspice.a"
|
|
"${NGSPICE_CM_DIR}/analog.cm"
|
|
"${NGSPICE_CM_DIR}/digital.cm"
|
|
"${NGSPICE_CM_DIR}/spice2poly.cm"
|
|
"${NGSPICE_CM_DIR}/table.cm"
|
|
"${NGSPICE_CM_DIR}/tlines.cm"
|
|
"${NGSPICE_CM_DIR}/xtradev.cm"
|
|
"${NGSPICE_CM_DIR}/xtraevt.cm"
|
|
"${NGSPICE_CM_DIR}/ngcm_common.a"
|
|
)
|
|
|
|
# spinit is embedded at the path main() points SPICE_LIB_DIR at, so ngspice's
|
|
# own init (incl. the `codemodel .../<cm>.cm` lines the registry resolves by
|
|
# basename) runs identically to a native install regardless of the prefix the
|
|
# dep build happened to use.
|
|
set_target_properties( ngspice_service PROPERTIES
|
|
LINK_FLAGS "-O2 -g0 --bind -pthread ${NGSPICE_EH_FLAGS} -sMODULARIZE=1 -sEXPORT_NAME=NgspiceService -sENVIRONMENT=worker,node -sEXIT_RUNTIME=0 -sALLOW_MEMORY_GROWTH=1 -sINITIAL_MEMORY=256MB -sMAXIMUM_MEMORY=4GB -sPTHREAD_POOL_SIZE=4 -sPTHREAD_POOL_SIZE_STRICT=0 -sPTHREAD_POOL_DELAY_LOAD=1 -sSTACK_SIZE=4MB -sDEFAULT_PTHREAD_STACK_SIZE=2MB --embed-file ${NGSPICE_SYSROOT}/share/ngspice/scripts/spinit@/ngspice/scripts/spinit" )
|