Skip to content

wasmJs embeds free-threaded CPython 3.15t with pthreads (#175) - #542

Merged
b-re-w merged 3 commits into
developfrom
feat/175-wasm-runtime-315t
Nov 26, 2026
Merged

b-re-w merged 3 commits into
developfrom
feat/175-wasm-runtime-315t

Conversation

@b-re-w

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

Copy link
Copy Markdown
Member

Part of #175.

Feature added

  • python-multiplatform/scripts/wasm/build-cpython.sh builds CPython 3.15.0 with --disable-gil --enable-wasm-pthreads on Emscripten 5.0.3 with the pyemscripten_2026_0 ABI (leader, Decision 10 a1 and b1). It takes in the ft-wasm script's flags, trampoline patch, _pm_upcall module and Makefile and Makefile.pre patches, and adds smoke and probe steps.
  • embedsFreeThreadedPython = true on wasmJs. Every published variant that carries a CPython now states freeThreaded=true, and autoDrainInterval defaults to on for wasm.
  • cpython.mjs installs the stdlib zip at the 3.15t landmark (/lib/python315t.zip).
  • Karma serves COOP and COEP (SPEC T-8).
  • wasm.yml's test job builds the runtime itself, cached on the hashes of build-cpython.sh and _pm_upcall.c (leader, Decision 11 a). The WASM_RUNTIME_URL gate is removed.

Defect fixed

  • select.poll() raised ENOSYS because CPython 3.15 prefers ppoll(), which Emscripten links as a stub. The build now configures with ac_cv_func_ppoll=no and checks pyconfig.h.
  • readCString in cpython.mjs passed a view of shared memory to TextDecoder, which browsers reject. It now copies first.

Test added or changed

  • WasmGilBuildTest becomes WasmFreeThreadedBuildTest: t ABI flags, Py_GIL_DISABLED, and sys._is_gil_enabled() is False.
  • WasmCycleCollectionTest reads the free-threaded wasm32 refcount layout.
  • WasmBrowserRuntimeTest uses the t landmark.
  • smoke.py asserts that poll() works.
  • WasmCompiledWheelTest waits for a pypackpack-built cp315t wheel (Decision 10 c1, pypackpack Fix: Stubs list every Kotlin supertype that has a stub class #82). Until then it skips by name, and that skip fails under -PrequireWasmRuntime. So wasm.yml's test job is expected to fail on that one test until Fix: Stubs list every Kotlin supertype that has a stub class #82 ships the wheel.

Documentation corrected

SPEC T-1, ROADMAP 9.1, 9.2 and 10.1, wasm-design.md, threading-and-abi.md, free-threaded-wasm.md, python-version-acquisition.md, README, the wasmJsMain README, and the KDocs.

Verification (local, against the rebuilt runtime)

  • build-cpython.sh all: verify passes, FT-WASM-SMOKE-OK in both layouts, and the probe passes a to d.
  • wasmJsNodeTest: 599 tests, 0 failed. The red run before the fixes had 4 failures, all of which are now fixed.
  • wasmJsBrowserTest: 10 tests, 0 failed. Before the fixes, 2 failed.

Not in this PR

.github/scripts/ft-wasm/ and build-ft-wasm.yml are deleted only after wasm.yml is green on this script (Decision 10 a1).

#175)

build-cpython.sh builds CPython 3.15.0 with --disable-gil --enable-wasm-pthreads on
Emscripten 5.0.3 with the pyemscripten_2026_0 ABI (leader, Decision 10 a1 and b1), taking
in the ft-wasm script's flags, trampoline patch, _pm_upcall module and Makefile patches, and
adding smoke and probe steps. _pm_upcall.c, smoke.py and embed-probe.mjs move beside it.

embedsFreeThreadedPython is true on wasmJs, so every published variant that carries a
CPython states freeThreaded=true and autoDrainInterval defaults to on there.

Defects found on the way:
- select.poll() raised ENOSYS: 3.15 prefers ppoll(), which Emscripten links as a stub.
  Configured with ac_cv_func_ppoll=no; smoke.py asserts poll() works.
- cpython.mjs readCString decoded a view of the shared memory, which a browser's
  TextDecoder rejects; it copies first.

Tests: WasmGilBuildTest becomes WasmFreeThreadedBuildTest; WasmCycleCollectionTest reads
the free-threaded wasm32 refcount layout; WasmBrowserRuntimeTest uses the t landmark;
WasmCompiledWheelTest waits for a pypackpack cp315t wheel (Decision 10 c1, #82). Karma
serves COOP/COEP (SPEC T-8).

wasm.yml's test job builds the runtime itself, cached on the hashes of build-cpython.sh
and _pm_upcall.c (leader, Decision 11 a); the WASM_RUNTIME_URL gate is gone.

Local: wasmJsNodeTest 599 tests, 0 failed; wasmJsBrowserTest 10 tests, 0 failed.
…ain, so poll() in a pthread no longer throws SuspendError on node 24

ci.yml run 45742320989 (node 24.22.3): smoke.py's select.poll() in its pthread main threw
'SuspendError: trying to suspend without WebAssembly.promising'. Node 24 has JSPI on by default and
Python/emscripten_syscalls.c took the suspending path whenever WebAssembly.promising existed; node 22
has no JSPI, which is why it passed locally. build-cpython.sh now patches the guards to require the
promising main of this JS context.

Part of #175
…uite no longer hides the browser suite

Run 45829018834: wasmJsNodeTest failed on the expected WasmCompiledWheelTest and Gradle stopped
before wasmJsBrowserTest ran. The step still fails when either suite does.

Part of #175
@b-re-w
b-re-w merged commit b3d5391 into develop Nov 26, 2026
@b-re-w
b-re-w deleted the feat/175-wasm-runtime-315t branch November 26, 2026 18:25
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