Toolchain: emsdk 6.0.6 (versions.sh; cache-hash keys on it). Build knob PCBJAM_ASYNC_BACKEND=jspi|asyncify: build-kicad-target.sh links editors with -sJSPI + -sJSPI_EXPORTS=@scripts/common/jspi-exports.txt + --pre-js jspi-scheduler.js (no DYNCALLS, no post-link asyncify pipeline); wx build stamps the backend and forces clean on flip or unknown provenance; docker/build.sh passes the knob, seeds the emscripten ports cache from the volume every launch, jspi postprocess = patch-env-shim only. scripts/common/shims/jspi-scheduler.js: the JSPI successor scheduler — token-wait registry, resume turnstile (one armed resume between engine re-entries, SP swaps only at microtask boundaries), green-region spill stacks (16-aligned tops), S1 embind mutator FIFO lane + parker wraps, S6 shutdown, libctx integration hooks (suspend/end/quarantine + g_current arm/clear), SuspendError attributor, lost-wake + stuck-window watchdogs, __wxWaitDump observability. Embind: PARKER registrations get emscripten::async() under PCBJAM_JSPI (wasm/bindings/pcbjam_async_policy.h). nanosleep yields route via the shim. Tests: tests/asyncify -> tests/jspi successor suite (jspi-stack red/green shadow-stack battery, jspi-coroutine MiniCoro harness, suspend-races semantic scenarios + __wxWaitDump books coherence); projects jspi-firefox/ jspi-chrome (asyncify-webkit retired — no JSPI in WebKit); unconditional Firefox JSPI pref; guard-beacons -> wait-beacons (+wxScheduler/libctxJspi families); Makefile.wasm links test apps against JSPI with the shim as a tracked link prerequisite. Web: WasmTool setRo await + __wxWaitDump forensics, open-flow contained promise, scheduler-shim.test.ts retargeted (8 green). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NDeBaKKhQztd8KiVtHuyXr
93 lines
3 KiB
C++
93 lines
3 KiB
C++
/*
|
|
* GerbView embind bindings.
|
|
*
|
|
* GerbView boots without a document (it is one of `FILELESS_TOOLS`), but a
|
|
* project route CAN name a gerber: clicking `Production/gerbers/board-F_Cu.gbr`
|
|
* on the project page deep-links here. Until this TU existed the bundle had no
|
|
* embind surface at all, so the shell staged the file into MEMFS and then had
|
|
* no way to say "open it" — GerbView came up empty and the user had to walk
|
|
* File→Open themselves.
|
|
*
|
|
* A gerber is rarely useful alone (a fabrication set is a stack of layers plus
|
|
* drill files), and `GERBVIEW_FRAME::OpenProjectFiles` already takes a LIST and
|
|
* auto-routes each entry by filename to the gerber / Excellon / job / archive
|
|
* loader, then zoom-fits. So the primary entry point here is the multi-file
|
|
* one: the shell hands over every gerber+drill sibling in the clicked file's
|
|
* folder, and the whole board renders.
|
|
*/
|
|
#include <emscripten.h>
|
|
#include <emscripten/bind.h>
|
|
#include <gerbview_frame.h>
|
|
#include <kiway_player.h>
|
|
#include <nlohmann/json.hpp>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <wx/app.h>
|
|
#include <wx/string.h>
|
|
#include "open_gate.h"
|
|
#include "main_stack_runner.h"
|
|
#include "pcbjam_async_policy.h"
|
|
|
|
using namespace emscripten;
|
|
using json = nlohmann::json;
|
|
|
|
static GERBVIEW_FRAME* gerbFrame()
|
|
{
|
|
return wxTheApp ? dynamic_cast<GERBVIEW_FRAME*>( wxTheApp->GetTopWindow() ) : nullptr;
|
|
}
|
|
|
|
static bool openFileSet( const std::vector<wxString>& aFiles )
|
|
{
|
|
// Held across every Asyncify park of the load (open_gate.h): the layer load
|
|
// parks, and a wx timer dispatched into a half-built layer set traps.
|
|
pcbjam_open::BusyGuard busy;
|
|
|
|
GERBVIEW_FRAME* frame = gerbFrame();
|
|
|
|
if( !frame || aFiles.empty() )
|
|
return false;
|
|
|
|
return frame->OpenProjectFiles( aFiles, 0 );
|
|
}
|
|
|
|
/** Open ONE gerber/drill file (the generic single-file entry every app has). */
|
|
static bool kicadOpenFile( std::string path )
|
|
{
|
|
return openFileSet( { wxString::FromUTF8( path.c_str() ) } );
|
|
}
|
|
|
|
/**
|
|
* Open a whole fabrication set: a JSON array of MEMFS paths. Order is the
|
|
* caller's (the shell sorts, so layer order is stable across reloads).
|
|
* GERBVIEW_FRAME caps the set at GERBER_DRAWLAYERS_COUNT internally.
|
|
*/
|
|
static bool kicadOpenFiles( std::string pathsJson )
|
|
{
|
|
json paths = json::parse( pathsJson, nullptr, /*allow_exceptions*/ false );
|
|
|
|
if( !paths.is_array() )
|
|
return false;
|
|
|
|
std::vector<wxString> files;
|
|
|
|
for( const auto& entry : paths )
|
|
{
|
|
if( entry.is_string() )
|
|
files.push_back( wxString::FromUTF8( entry.get<std::string>().c_str() ) );
|
|
}
|
|
|
|
return openFileSet( files );
|
|
}
|
|
|
|
/** JS-pollable open-in-flight probe — same contract as the editors. */
|
|
static bool kicadOpenFileBusy()
|
|
{
|
|
return pcbjam_open::busy();
|
|
}
|
|
|
|
EMSCRIPTEN_BINDINGS( gerbview )
|
|
{
|
|
function( "kicadOpenFile", &kicadOpenFile PCBJAM_PARKER_POLICY );
|
|
function( "kicadOpenFiles", &kicadOpenFiles PCBJAM_PARKER_POLICY );
|
|
function( "kicadOpenFileBusy", &kicadOpenFileBusy );
|
|
}
|