Skip to content

CI: probe embedding the 3.15t wasm build without main (#175 step 2) - #411

Merged
b-re-w merged 1 commit into
developfrom
feat/wasm-ft-embed-probe
Nov 13, 2026
Merged

b-re-w merged 1 commit into
developfrom
feat/wasm-ft-embed-probe

Conversation

@b-re-w

@b-re-w b-re-w commented Nov 13, 2026

Copy link
Copy Markdown
Member

Refs #175 (step 2; the issue stays open).

Adds a probe step to build-ft-wasm.yml (ubuntu only) that checks what the library's wasmJs target would need from the free-threaded pthreads build:

  • a: python.mjs loaded with noInitialRun (main never called); Module.wasmMemory is a SharedArrayBuffer.
  • b: a hand-assembled module importing a non-shared memory (what Kotlin/Wasm 2.4.20-Beta2 emits) must get LinkError; one importing a shared memory with a maximum must instantiate and read Py_Version identically. Verified locally under node 22 against a JS shared memory: LinkError: mismatch in shared state of memory versus success.
  • c: Py_Initialize, PyEval_SaveThread, PyGILState_Ensure from the JS main thread, then four threads that read os.py and join, the GIL stays off, and gc.collect() runs in a worker thread.

build-wasm.sh appends wasmExports, wasmMemory and wasmTable to -sEXPORTED_RUNTIME_METHODS (asserted) and _malloc, _free, _Py_Version to -sEXPORTED_FUNCTIONS when that list exists. The probe step runs after the archive upload, so its failure does not lose the archive. Node only: node's main thread uses a real Atomics.wait, a browser busy-waits.

Agent proposal toward #175 step 2, not a decision. Investigation: Kotlin/Wasm has no shared-memory option, so the library cannot load against this build without a binary patch of the import or a compiler change (decisions recorded for the owner).

Exports wasmExports, wasmMemory and wasmTable from the free-threaded
wasm build and adds a node probe step to build-ft-wasm.yml: the shared
memory, a non-shared versus shared memory import (what Kotlin/Wasm emits
versus what a patch would emit), and Py_Initialize from the JS main
thread with four threads and gc.collect() in a worker. The step runs
after the archive upload, so a probe failure does not lose the archive.
@b-re-w

b-re-w commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

Run 43393844607 (build-ft-wasm.yml, ubuntu): success.

  • [a] PASS: wasmMemory.buffer is a SharedArrayBuffer, 320 pages
  • [b] PASS: A1 non-shared import: LinkError (mismatch in shared state of memory, declared = 0, imported = 1); A2 shared import (max 65536) instantiated; A2.load(&Py_Version=599728) = 0x30f00f0 equals HEAPU32
  • [c1] Py_Initialize returned; [c2] PyEval_SaveThread returned (main thread detached)
  • 4 threads read os.py (42893 chars each) and joined; gc.collect() in a worker thread returned 48; [c3] PASS, GIL stayed off
  • FT-WASM-EMBED-PROBE-OK

Note: emcc warns that EXPORTED_FUNCTIONS is ignored with MAIN_MODULE (all functions are exported anyway), so the _malloc/_free/_Py_Version append is a no-op on 3.15.0. Merge waits for the leader's macOS CI hold (a develop push starts the desktop/ios gates).

@b-re-w
b-re-w merged commit 2bca2c8 into develop Nov 13, 2026
1 check passed
@b-re-w
b-re-w deleted the feat/wasm-ft-embed-probe branch November 13, 2026 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant