Repository navigation
wasmJs embeds free-threaded CPython 3.15t with pthreads (#175) - #542
Merged
Merged
Conversation
#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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #175.
Feature added
python-multiplatform/scripts/wasm/build-cpython.shbuilds CPython 3.15.0 with--disable-gil --enable-wasm-pthreadson 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_upcallmodule and Makefile and Makefile.pre patches, and addssmokeandprobesteps.embedsFreeThreadedPython = trueon wasmJs. Every published variant that carries a CPython now statesfreeThreaded=true, andautoDrainIntervaldefaults to on for wasm.cpython.mjsinstalls the stdlib zip at the 3.15t landmark (/lib/python315t.zip).wasm.yml's test job builds the runtime itself, cached on the hashes ofbuild-cpython.shand_pm_upcall.c(leader, Decision 11 a). TheWASM_RUNTIME_URLgate is removed.Defect fixed
select.poll()raised ENOSYS because CPython 3.15 prefersppoll(), which Emscripten links as a stub. The build now configures withac_cv_func_ppoll=noand checkspyconfig.h.readCStringincpython.mjspassed a view of shared memory toTextDecoder, which browsers reject. It now copies first.Test added or changed
WasmGilBuildTestbecomesWasmFreeThreadedBuildTest:tABI flags,Py_GIL_DISABLED, andsys._is_gil_enabled()is False.WasmCycleCollectionTestreads the free-threaded wasm32 refcount layout.WasmBrowserRuntimeTestuses thetlandmark.smoke.pyasserts thatpoll()works.WasmCompiledWheelTestwaits 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. Sowasm.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-OKin 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/andbuild-ft-wasm.ymlare deleted only afterwasm.ymlis green on this script (Decision 10 a1).