From 9269884324e0795a35c37305379543dfb2898591 Mon Sep 17 00:00:00 2001 From: BREW <81044362+b-re-w@users.noreply.github.com> Date: Fri, 27 Nov 2026 17:43:49 +0900 Subject: [PATCH 1/3] Test: WasmCompiledWheelTest loads pypackpack's cp315t wasmdemo wheel (pypackpack #82) The 3.15t runtime cannot load the cp314 pydantic-core wheel. The test now imports wasmdemo.wmod and expects answer() 42, unwind() 7 through setjmp/longjmp (the __c_longjmp tag), and the GIL still off. Red with the wheel staged: ModuleNotFoundError for pydantic_core; green after. --- .../ffi/emscripten/WasmCompiledWheelTest.kt | 60 ++++++++----------- 1 file changed, 26 insertions(+), 34 deletions(-) diff --git a/python-multiplatform/src/wasmJsTest/kotlin/python/native/ffi/emscripten/WasmCompiledWheelTest.kt b/python-multiplatform/src/wasmJsTest/kotlin/python/native/ffi/emscripten/WasmCompiledWheelTest.kt index 9c5e55cf..241cc850 100644 --- a/python-multiplatform/src/wasmJsTest/kotlin/python/native/ffi/emscripten/WasmCompiledWheelTest.kt +++ b/python-multiplatform/src/wasmJsTest/kotlin/python/native/ffi/emscripten/WasmCompiledWheelTest.kt @@ -12,24 +12,23 @@ import python.multiplatform.ffi.PythonTestFixture * * `WasmInterpreterAbiTest` asserts the two properties of `python.wasm` that make this possible -- * the exported wasm exception tags, and the platform tag claim. This is the claim itself: a wheel - * built by someone else's toolchain against PEP 783's ABI (pydantic-core 2.48.0, Rust/PyO3, from - * PyPI) is `dlopen`ed as an Emscripten side module, links against `python.wasm`, and runs. + * built by another toolchain against that ABI is `dlopen`ed as an Emscripten side module, links + * against `python.wasm`, and runs. * - * Measured in the former `wasm-experiment/` (Test G) through CPython's own `python.sh`, with no - * Kotlin in the process. Against a stock PEP 776 build (`python-multiplatform/scripts/wasm/build-cpython.sh stock`) the same - * import fails at load: + * The wheel is `wasmdemo-0.1.0-cp315-cp315t-pyemscripten_2026_0_wasm32.whl`, built by pypackpack's + * Emscripten adapter (pypackpack #82, PR #180; handed over by toolchain 2026-11-27) with this + * repository's Emscripten 5.0.3 against the 3.15t headers, `-fwasm-exceptions -sSUPPORT_LONGJMP=wasm + * -pthread -fPIC -sSIDE_MODULE=1`. Its C module `wasmdemo.wmod` has `answer()` (returns 42) and + * `unwind()`, which returns 7 through `setjmp`/`longjmp` and so imports `python.wasm`'s `__c_longjmp` + * tag: a runtime without the pyemscripten_2026_0 unwinding ABI fails it at link time. It is C, so it + * does not exercise `__cpp_exception`. This replaces the cp314 pydantic-core wheel the 3.14.2 runtime + * loaded (Decision 10 (c) c1, leader 2026-11-26). * - * LinkError: Import #204 "env" "__cpp_exception": tag import requires a WebAssembly.Tag - * - * Decision 10 (c) c1 (leader, 2026-11-26): the runtime is now 3.15t, so the cp314 wheel below no longer - * loads; this test moves to a pypackpack-built cp315t wheel when pypackpack #82 produces one (the body is - * then rewritten for that wheel). Until then it reports a named skip, and fails under - * `-PrequireWasmRuntime=true`, never a silent pass. - * - * The wheels are not in the repository. `python-multiplatform/scripts/wasm/build-cpython.sh wheels` downloads them by URL - * with pinned sha256 into `.caches/wasm-wheels`, and the test task extracts them next to the test - * bundle. Without them this test skips with that instruction, and under `-PrequireWasmRuntime=true` - * it fails instead -- the same contract every other wasm prerequisite has. + * The wheels are not in the repository. `python-multiplatform/scripts/wasm/build-cpython.sh wheels` + * downloads the pinned ones with their sha256 into `.caches/wasm-wheels` (or `-PwasmWheelsDir`), and + * the test task extracts them next to the test bundle. Without them this test skips with that + * instruction, and under `-PrequireWasmRuntime=true` it fails instead -- the same contract every + * other wasm prerequisite has. */ class WasmCompiledWheelTest { @@ -44,9 +43,8 @@ class WasmCompiledWheelTest { val site = PMP_TEST_SITE_PACKAGES?.toString() if (site == null) { val message = "no cp315t pyemscripten_2026_0 wheel in ${PMP_TEST_WHEELS_DIR?.toString()}: " + - "waiting on a pypackpack-built cp315t wheel (pypackpack #82, Decision 10 c1, leader " + - "2026-11-26). The cp314 pydantic-core wheel the 3.14.2 runtime loaded cannot load into " + - "3.15t, and no cp315t wheel is pinned in build-cpython.sh's WHEELS yet." + "fetch the pinned wasmdemo wheel with python-multiplatform/scripts/wasm/build-cpython.sh wheels " + + "(or point -PwasmWheelsDir at a directory holding it; pypackpack #82)." if (required.toBoolean()) { fail("$message -PrequireWasmRuntime=true was passed, so this is a failure rather than a skip.") } @@ -59,19 +57,13 @@ class WasmCompiledWheelTest { "import sys as _pmp_sys\n" + "_pmp_sys.path.insert(0, ${pyStr(site)})\n" + "try:\n" + - " import pydantic_core as _pmp_pc\n" + - " from pydantic_core import SchemaValidator as _pmp_SV, core_schema as _pmp_cs\n" + - " _pmp_v = _pmp_SV(_pmp_cs.int_schema())\n" + + " import wasmdemo.wmod as _pmp_m\n" + " _pmp_wheel = [\n" + - " _pmp_pc.__version__,\n" + - " _pmp_pc._pydantic_core.__file__.rsplit('/', 1)[-1],\n" + - " repr(_pmp_v.validate_python('42')),\n" + + " _pmp_m.__file__.rsplit('/', 1)[-1],\n" + + " repr(_pmp_m.answer()),\n" + + " repr(_pmp_m.unwind()),\n" + + " repr(_pmp_sys._is_gil_enabled()),\n" + " ]\n" + - " try:\n" + - " _pmp_v.validate_python('not an int')\n" + - " _pmp_wheel.append('no exception')\n" + - " except _pmp_pc.ValidationError as e:\n" + - " _pmp_wheel.append(type(e).__name__)\n" + "except BaseException as e:\n" + " _pmp_wheel = ['FAILED ' + type(e).__name__ + ': ' + str(e)]\n" + "finally:\n" + @@ -81,11 +73,11 @@ class WasmCompiledWheelTest { val result = evalToString("' | '.join(_pmp_wheel)") runInMain("del _pmp_wheel, _pmp_sys") assertEquals( - "2.48.0 | _pydantic_core.cpython-314-wasm32-emscripten.so | 42 | ValidationError", + "wmod.cpython-315t-wasm32-emscripten.so | 42 | 7 | False", result, - "importing and calling the compiled pydantic-core wheel failed. A LinkError naming " + - "__cpp_exception or __c_longjmp means python.wasm lacks the pyemscripten_2026_0 " + - "unwinding ABI (see WasmInterpreterAbiTest).", + "importing and calling the compiled wasmdemo wheel failed. A LinkError naming " + + "__c_longjmp means python.wasm lacks the pyemscripten_2026_0 unwinding ABI " + + "(see WasmInterpreterAbiTest); 'True' at the end means the import re-enabled the GIL.", ) } } From 5d9cca288f4b3fa2b84e96bacd8e70a091203937 Mon Sep 17 00:00:00 2001 From: BREW <81044362+b-re-w@users.noreply.github.com> Date: Fri, 27 Nov 2026 17:47:15 +0900 Subject: [PATCH 2/3] Test: the wasm wheel fixtures are checked in and pinned by sha256 (leader 2026-11-27) The cp315t wasmdemo wheel lives in src/wasmJsTest/resources/wheels, the default wasmWheelsDir. theCheckedInWheelsAreTheOnesTheReadmeDescribes fails on any unpinned or altered wheel (red on a tampered copy, green on the fixture). The URL download path is deleted: build-cpython.sh wheels, fetchWasmWheels and wasm.yml's fetch step. --- .github/workflows/wasm.yml | 8 --- docs/platforms/wasm-design.md | 6 +- python-multiplatform/build.gradle.kts | 21 ++----- .../scripts/wasm/build-cpython.sh | 48 +--------------- python-multiplatform/src/wasmJsMain/README.md | 2 +- .../native/ffi/emscripten/TestWheelConfig.kt | 2 +- .../ffi/emscripten/WasmCompiledWheelTest.kt | 52 +++++++++++++++--- ...p315-cp315t-pyemscripten_2026_0_wasm32.whl | Bin 0 -> 1892 bytes 8 files changed, 58 insertions(+), 81 deletions(-) create mode 100644 python-multiplatform/src/wasmJsTest/resources/wheels/wasmdemo-0.1.0-cp315-cp315t-pyemscripten_2026_0_wasm32.whl diff --git a/.github/workflows/wasm.yml b/.github/workflows/wasm.yml index 47e2d973..c6317c1f 100644 --- a/.github/workflows/wasm.yml +++ b/.github/workflows/wasm.yml @@ -129,14 +129,6 @@ jobs: done ls -l "$WASM_RUNTIME_DIR" - # `WasmCompiledWheelTest` imports a real compiled pyemscripten_2026_0 wheel. Under - # `-PrequireWasmRuntime` a missing wheel is a failure, not a skip, so fetch them first: by URL, - # each accepted only against the sha256 the script pins. The script pins none today: the - # wheel has to be a pypackpack-built cp315t one (leader, Decision 10 (c) c1, 2026-11-26), and - # until pypackpack #82 produces it this job fails on that one test, by name, by design. - - name: Fetch the pinned wasm wheels - run: bash python-multiplatform/scripts/wasm/build-cpython.sh wheels - # `-PrequireWasmRuntime` is the second half of the guard, and it is what makes this job unable # to repeat the original defect: if either task would skip -- no interpreter, or no # Chromium-family browser for karma -- the build fails naming what was missing, instead of diff --git a/docs/platforms/wasm-design.md b/docs/platforms/wasm-design.md index 368ee3c9..36960cef 100644 --- a/docs/platforms/wasm-design.md +++ b/docs/platforms/wasm-design.md @@ -121,9 +121,9 @@ Evidence, from the 3.14.2 GIL build this replaced: a real PyPI wheel, `pydantic_ and ran on that build (`validate_python(42) -> 42`, a `ValidationError` raised and caught, the exception exercises the unwinding ABI), and fails with `tag import requires a WebAssembly.Tag` on the stock build. This is one wheel and one code path; it does not show that every compiled extension -loads. A cp314 wheel does not load in 3.15t, so `WasmCompiledWheelTest` now waits for a pypackpack-built -cp315t wheel (leader, Decision 10 (c) c1, 2026-11-26; pypackpack #82) and until then reports a named -skip that fails under `-PrequireWasmRuntime` (`python-multiplatform/scripts/wasm/build-cpython.sh wheels` pins none yet); +loads. A cp314 wheel does not load in 3.15t, so `WasmCompiledWheelTest` now loads pypackpack-built +cp315t wheels (leader, Decision 10 (c) c1, 2026-11-26; pypackpack #82), checked in as test fixtures +under `python-multiplatform/src/wasmJsTest/resources/wheels/` with their provenance (leader, 2026-11-27); `WasmInterpreterAbiTest` checks the claims, with `python-multiplatform/scripts/wasm/build-cpython.sh stock` as the negative control. Emscripten is pinned to 5.0.3 because that is what the platform specifies, and installing it replaces `~/emsdk/upstream` in place (a global setting). diff --git a/python-multiplatform/build.gradle.kts b/python-multiplatform/build.gradle.kts index 10897236..c5215ed1 100644 --- a/python-multiplatform/build.gradle.kts +++ b/python-multiplatform/build.gradle.kts @@ -2080,22 +2080,13 @@ val buildWasmPython by tasks.registering(Exec::class) { } /** - * Where `python-multiplatform/scripts/wasm/build-cpython.sh wheels` puts the pinned compiled wheels the wasm suite loads - * (`wasmJsTest/.../WasmCompiledWheelTest`). Not checked in: they are downloaded by URL and accepted - * only against the sha256 the script pins. + * The compiled wheels the wasm suite loads (`wasmJsTest/.../WasmCompiledWheelTest`): test fixtures + * checked in under `src/wasmJsTest/resources/wheels/`, built by pypackpack (#82) and pinned by sha256 + * in the test and the README beside them (leader, 2026-11-27). `-PwasmWheelsDir` overrides it. */ val wasmWheelsDir: String = (project.findProperty("wasmWheelsDir")?.toString() ?: System.getenv("PMP_WASM_WHEELS_DIR") - ?: rootProject.layout.projectDirectory.dir(".caches/wasm-wheels").asFile.absolutePath) - -/** Downloads the pinned wheels into [wasmWheelsDir]. Network, a few MB; nothing depends on it. */ -val fetchWasmWheels by tasks.registering(Exec::class) { - group = "python" - description = "Downloads the pinned pyemscripten_2026_0 wheels the wasm suite loads into .caches/" - val script = rootProject.layout.projectDirectory.file("python-multiplatform/scripts/wasm/build-cpython.sh").asFile - environment("WASM_WHEELS_DIR", wasmWheelsDir) - commandLine("bash", script.absolutePath, "wheels") -} + ?: layout.projectDirectory.dir("src/wasmJsTest/resources/wheels").asFile.absolutePath) /** * The test-only tail of the test bundle's `cpython-config.mjs`: where the wheels were extracted, and @@ -2666,7 +2657,7 @@ tasks.withType().co onlyIf { wasmRuntimePresent(pythonDir.resolve("python.mjs")) } - // Fetching the wheels changes what WasmCompiledWheelTest can prove, so it re-runs the suite. + // Changing the wheels changes what WasmCompiledWheelTest can prove, so it re-runs the suite. inputs.files(fileTree(wasmWheelsDir) { include("*.whl") }) .withPropertyName("wasmWheels").optional() @@ -2704,7 +2695,7 @@ tasks.withType().co logger.lifecycle( "No wheels in $wasmWheelsDir -- WasmCompiledWheelTest will " + (if (requireWasmRuntime) "FAIL (-PrequireWasmRuntime)" else "skip") + - ". Fetch them with python-multiplatform/scripts/wasm/build-cpython.sh wheels (or :python-multiplatform:fetchWasmWheels)." + ". The fixtures live in python-multiplatform/src/wasmJsTest/resources/wheels (see its README)." ) } dir.resolve("cpython-config.mjs").appendText( diff --git a/python-multiplatform/scripts/wasm/build-cpython.sh b/python-multiplatform/scripts/wasm/build-cpython.sh index a02591f3..b4078334 100755 --- a/python-multiplatform/scripts/wasm/build-cpython.sh +++ b/python-multiplatform/scripts/wasm/build-cpython.sh @@ -9,7 +9,6 @@ # python-multiplatform/scripts/wasm/build-cpython.sh smoke run smoke.py (threads, upcalls, proxy slots) under the build tree's python.sh # python-multiplatform/scripts/wasm/build-cpython.sh stage copy python.wasm, python.mjs and the zip to the runtime dir # python-multiplatform/scripts/wasm/build-cpython.sh probe run embed-probe.mjs against the staged runtime (Python without main, as the library runs it) -# python-multiplatform/scripts/wasm/build-cpython.sh wheels download the pinned compiled wheels the wasm suite loads (none yet, see below) # python-multiplatform/scripts/wasm/build-cpython.sh stock build a STOCK interpreter (CPython's own driver defaults) as a negative control # # Which CPython, and why. Owner, 2026-10-04, on #175: "The wasm interpreter is also 3.15t, built by us @@ -27,7 +26,6 @@ # .caches/emsdk emsdk, pinned to 5.0.3 (override: EMSDK) # .caches/wasm-build/cpython315t CPython checkout + cross build (override: CPYTHON_CHECKOUT) # .caches/wasm-runtime the three files the library needs (override: WASM_RUNTIME_DIR) -# .caches/wasm-wheels pinned wheels (override: WASM_WHEELS_DIR) # .caches/wasm-build/cpython315-stock, .caches/wasm-runtime-stock the `stock` control # # `.caches/wasm-runtime` is the default `wasmPythonDir` in python-multiplatform/build.gradle.kts, so @@ -105,15 +103,6 @@ ABI_FLAGS="-fwasm-exceptions -sSUPPORT_LONGJMP=wasm" HOST_CFLAGS="-DPY_CALL_TRAMPOLINE -sUSE_BZIP2 $ABI_FLAGS -pthread" HOST_LDFLAGS="$ABI_FLAGS -pthread -sPTHREAD_POOL_SIZE=8 -sMAXIMUM_MEMORY=2GB" -# --- the wheels the suite loads ----------------------------------------------------------------------- -# `wasmJsTest/.../WasmCompiledWheelTest` imports a real compiled wheel and calls into it. Decision 10 -# (c) c1 (leader, 2026-11-26): it moves to a pypackpack-built cp315t wheel when pypackpack #82 produces -# one; until then the list is empty and the test reports a named skip, which fails under -# -PrequireWasmRuntime (never a silent pass). The cp314 pydantic-core wheel pinned for the 3.14.2 build -# cannot load into 3.15t. Format: " ", one per line. -WHEELS_DIR="${WASM_WHEELS_DIR:-$CACHES/wasm-wheels}" -WHEELS=() - die() { echo "build-cpython: $*" >&2; exit 1; } # --- toolchain -------------------------------------------------------------------------------------- @@ -492,38 +481,6 @@ do_stage() { echo "staged into $RUNTIME_DIR" } -# --- wheels ------------------------------------------------------------------------------------------ -sha256_of() { - if command -v sha256sum > /dev/null 2>&1; then sha256sum "$1" | cut -d' ' -f1 - else shasum -a 256 "$1" | cut -d' ' -f1; fi -} - -do_wheels() { - mkdir -p "$WHEELS_DIR" - local entry name url sha dest got - if [ "${#WHEELS[@]}" -eq 0 ]; then - echo "no wasm wheels pinned: WasmCompiledWheelTest waits on a pypackpack-built cp315t wheel (pypackpack #82, Decision 10 c1)" - return 0 - fi - for entry in "${WHEELS[@]}"; do - read -r name url sha <<< "$entry" - dest="$WHEELS_DIR/$name" - if [ -f "$dest" ] && [ "$(sha256_of "$dest")" = "$sha" ]; then - echo "wheel present: $name" - continue - fi - rm -f "$dest.part" - curl -fsSL --retry 3 "$url" -o "$dest.part" - got="$(sha256_of "$dest.part")" - if [ "$got" != "$sha" ]; then - rm -f "$dest.part" - die "$name: downloaded sha256 $got, pinned $sha -- refusing it" - fi - mv "$dest.part" "$dest" - echo "fetched $name" - done -} - # --- stock: the negative control --------------------------------------------------------------------- # CPython 3.15.0 built by its own driver's defaults (GIL, no pthreads), with exactly one addition: the # runtime methods the library binds through (patch_makefile_reachability). No unwinding ABI, no @@ -568,14 +525,13 @@ do_stock() { } case "${1:-all}" in - all) do_build; do_zip; do_verify; do_smoke; do_stage; do_probe; do_wheels ;; + all) do_build; do_zip; do_verify; do_smoke; do_stage; do_probe ;; build) do_build ;; zip) do_zip ;; verify) do_verify ;; smoke) do_smoke ;; stage) do_stage ;; probe) do_probe ;; - wheels) do_wheels ;; stock) do_stock ;; - *) die "unknown command '$1' (all | build | zip | verify | smoke | stage | probe | wheels | stock)" ;; + *) die "unknown command '$1' (all | build | zip | verify | smoke | stage | probe | stock)" ;; esac diff --git a/python-multiplatform/src/wasmJsMain/README.md b/python-multiplatform/src/wasmJsMain/README.md index 474a34e6..b4b59cfc 100644 --- a/python-multiplatform/src/wasmJsMain/README.md +++ b/python-multiplatform/src/wasmJsMain/README.md @@ -22,7 +22,7 @@ stands on is now a test in `wasmJsTest/.../emscripten/`, run against the real in | the shared memory survives CPython growing it | `WasmSharedMemoryGrowthTest` | | Kotlin-only work neither grows nor writes that memory | `WasmKotlinLeavesLinearMemoryAloneTest` | | the interpreter carries the `pyemscripten_2026_0` ABI | `WasmInterpreterAbiTest` | -| ... and a real compiled wheel loads and runs in it | `WasmCompiledWheelTest` (wheels: `python-multiplatform/scripts/wasm/build-cpython.sh wheels`) | +| ... and a real compiled wheel loads and runs in it | `WasmCompiledWheelTest` (wheels: `src/wasmJsTest/resources/wheels/`) | | direct calls beat a JS frame; hoisting beats a shim; strings and bulk reads | `WasmCrossingOverheadTest` | | `Table.set` beats `addFunction` + a JS closure for upcalls | `WasmUpcallRouteOverheadTest` | | `PY_CALL_TRAMPOLINE`'s JS fallback is live; `pmp_invoke` survives the wasm one | `WasmCallTrampolineTest` | diff --git a/python-multiplatform/src/wasmJsTest/kotlin/python/native/ffi/emscripten/TestWheelConfig.kt b/python-multiplatform/src/wasmJsTest/kotlin/python/native/ffi/emscripten/TestWheelConfig.kt index b53f2f7d..a48ef9ec 100644 --- a/python-multiplatform/src/wasmJsTest/kotlin/python/native/ffi/emscripten/TestWheelConfig.kt +++ b/python-multiplatform/src/wasmJsTest/kotlin/python/native/ffi/emscripten/TestWheelConfig.kt @@ -4,7 +4,7 @@ package python.native.ffi.emscripten /** * Where the `KotlinJsTest` `doFirst` in `python-multiplatform/build.gradle.kts` extracted the - * pinned wheels `python-multiplatform/scripts/wasm/build-cpython.sh wheels` downloads, or `null` when none were found. + * wheel fixtures in `src/wasmJsTest/resources/wheels/`, or `null` when none were found. * Test-only: appended to the test bundle's `cpython-config.mjs`, never to a consumer's. */ external val PMP_TEST_SITE_PACKAGES: JsString? diff --git a/python-multiplatform/src/wasmJsTest/kotlin/python/native/ffi/emscripten/WasmCompiledWheelTest.kt b/python-multiplatform/src/wasmJsTest/kotlin/python/native/ffi/emscripten/WasmCompiledWheelTest.kt index 241cc850..a31bffe5 100644 --- a/python-multiplatform/src/wasmJsTest/kotlin/python/native/ffi/emscripten/WasmCompiledWheelTest.kt +++ b/python-multiplatform/src/wasmJsTest/kotlin/python/native/ffi/emscripten/WasmCompiledWheelTest.kt @@ -24,11 +24,11 @@ import python.multiplatform.ffi.PythonTestFixture * does not exercise `__cpp_exception`. This replaces the cp314 pydantic-core wheel the 3.14.2 runtime * loaded (Decision 10 (c) c1, leader 2026-11-26). * - * The wheels are not in the repository. `python-multiplatform/scripts/wasm/build-cpython.sh wheels` - * downloads the pinned ones with their sha256 into `.caches/wasm-wheels` (or `-PwasmWheelsDir`), and - * the test task extracts them next to the test bundle. Without them this test skips with that - * instruction, and under `-PrequireWasmRuntime=true` it fails instead -- the same contract every - * other wasm prerequisite has. + * The wheels are test fixtures checked in under `python-multiplatform/src/wasmJsTest/resources/wheels/` + * (leader, 2026-11-27), whose README records how each was built; [PINNED_WHEELS] pins their sha256 and + * [theCheckedInWheelsAreTheOnesTheReadmeDescribes] checks it. The test task extracts them next to the + * test bundle (`-PwasmWheelsDir` overrides the directory). Without them this test skips, and under + * `-PrequireWasmRuntime=true` it fails instead -- the same contract every other wasm prerequisite has. */ class WasmCompiledWheelTest { @@ -43,8 +43,7 @@ class WasmCompiledWheelTest { val site = PMP_TEST_SITE_PACKAGES?.toString() if (site == null) { val message = "no cp315t pyemscripten_2026_0 wheel in ${PMP_TEST_WHEELS_DIR?.toString()}: " + - "fetch the pinned wasmdemo wheel with python-multiplatform/scripts/wasm/build-cpython.sh wheels " + - "(or point -PwasmWheelsDir at a directory holding it; pypackpack #82)." + "the fixtures live in python-multiplatform/src/wasmJsTest/resources/wheels (pypackpack #82)." if (required.toBoolean()) { fail("$message -PrequireWasmRuntime=true was passed, so this is a failure rather than a skip.") } @@ -83,6 +82,45 @@ class WasmCompiledWheelTest { } } + /** + * The fixtures are what their README says they are: every pinned wheel is present with its + * sha256, and nothing unpinned sits beside them. A rebuilt wheel (new emsdk or ABI) changes the + * hash, so this fails until the README and [PINNED_WHEELS] are updated with the new provenance. + */ + @Test + fun theCheckedInWheelsAreTheOnesTheReadmeDescribes() { + val dir = PMP_TEST_WHEELS_DIR?.toString() ?: fail("the test bundle's cpython-config.mjs carries no PMP_TEST_WHEELS_DIR") + PythonTestFixture.withInterpreter { + Python3.withPython { + assertEquals( + 0, + runInMain( + "import hashlib as _pmp_h, os as _pmp_os\n" + + "_pmp_d = ${pyStr(dir)}\n" + + "_pmp_found = sorted(n + ' ' + _pmp_h.sha256(open(_pmp_os.path.join(_pmp_d, n), 'rb').read()).hexdigest()\n" + + " for n in _pmp_os.listdir(_pmp_d) if n.endswith('.whl'))\n", + ), + ) + val found = evalToString("'\\n'.join(_pmp_found)") + runInMain("del _pmp_h, _pmp_os, _pmp_d, _pmp_found") + assertEquals( + PINNED_WHEELS.entries.sortedBy { it.key }.joinToString("\n") { "${it.key} ${it.value}" }, + found, + "the wheels in $dir are not the pinned fixtures; update resources/wheels/README.md and " + + "PINNED_WHEELS together when a fixture is rebuilt", + ) + } + } + } + private fun pyStr(value: String): String = "'" + value.replace("\\", "\\\\").replace("'", "\\'") + "'" + + private companion object { + /** File name to sha256; the same values as `resources/wheels/README.md`. */ + val PINNED_WHEELS = mapOf( + "wasmdemo-0.1.0-cp315-cp315t-pyemscripten_2026_0_wasm32.whl" to + "df57a28e3a61f4eb8bc5fe84e4a09bdc76e8e720bd6c348345c3fb86c772298a", + ) + } } diff --git a/python-multiplatform/src/wasmJsTest/resources/wheels/wasmdemo-0.1.0-cp315-cp315t-pyemscripten_2026_0_wasm32.whl b/python-multiplatform/src/wasmJsTest/resources/wheels/wasmdemo-0.1.0-cp315-cp315t-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jpgIt~cgIr24oGxlIU}$}~_xz*; zCG*&lMhVs<+#E@}6B}F>a&7s$>3DzbEo@f$ng9IN_H=E;3NzjRj|r~0p`6F=XX@iYFKzH3sjrto>Q z=b}?K-a2&OQ_eBWEHbuZT4>PWc=eg(Ul$$zWMpsq!RvR*GU3-1zJhC}wz>xWUDc|$ zsiko)U&0cN_trm--1%Y5z-A9hm`>l0UlV0yU}ys30B=Sn5eC$P99BGo3UX8cOQ^`j zI=TtS$sUvd5x@n=gquKIp^k1ia;iqHb@Z4KhU3gf=*A(ZHBeSSfHnAx17{3$vyej- ilsXY06<7ek{Egu>NLmf>W@Q6uU Date: Fri, 27 Nov 2026 21:34:44 +0900 Subject: [PATCH 3/3] Test added: a C++ wasm wheel throws and catches inside the interpreter (__cpp_exception) wasmcpp-0.1.0-cp315-cp315t-pyemscripten_2026_0_wasm32.whl (toolchain, pypackpack 2f3ddd0, sha256 6a41eb2a...) joins the checked-in fixtures. wasmcpp.wcpp.catch_it() throws std::runtime_error("boom 3") in the side module and returns the caught message, so it imports python.wasm's __cpp_exception tag, which the C fixture never touched. Red (node, -PrequireWasmRuntime=true, fixture absent): 3 tests, 1 failed, "No module named 'wasmcpp'". Green with the wheel pinned: 3 tests, 0 failed. Documentation corrected: resources/wheels/README.md records both wheels, their hashes and the pypackpack commit and command that built them. --- .../ffi/emscripten/WasmCompiledWheelTest.kt | 56 +++++++++++++++++- .../src/wasmJsTest/resources/wheels/README.md | 36 +++++++++++ ...p315-cp315t-pyemscripten_2026_0_wasm32.whl | Bin 0 -> 2213 bytes 3 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 python-multiplatform/src/wasmJsTest/resources/wheels/README.md create mode 100644 python-multiplatform/src/wasmJsTest/resources/wheels/wasmcpp-0.1.0-cp315-cp315t-pyemscripten_2026_0_wasm32.whl diff --git a/python-multiplatform/src/wasmJsTest/kotlin/python/native/ffi/emscripten/WasmCompiledWheelTest.kt b/python-multiplatform/src/wasmJsTest/kotlin/python/native/ffi/emscripten/WasmCompiledWheelTest.kt index a31bffe5..4c76a75a 100644 --- a/python-multiplatform/src/wasmJsTest/kotlin/python/native/ffi/emscripten/WasmCompiledWheelTest.kt +++ b/python-multiplatform/src/wasmJsTest/kotlin/python/native/ffi/emscripten/WasmCompiledWheelTest.kt @@ -20,8 +20,9 @@ import python.multiplatform.ffi.PythonTestFixture * repository's Emscripten 5.0.3 against the 3.15t headers, `-fwasm-exceptions -sSUPPORT_LONGJMP=wasm * -pthread -fPIC -sSIDE_MODULE=1`. Its C module `wasmdemo.wmod` has `answer()` (returns 42) and * `unwind()`, which returns 7 through `setjmp`/`longjmp` and so imports `python.wasm`'s `__c_longjmp` - * tag: a runtime without the pyemscripten_2026_0 unwinding ABI fails it at link time. It is C, so it - * does not exercise `__cpp_exception`. This replaces the cp314 pydantic-core wheel the 3.14.2 runtime + * tag: a runtime without the pyemscripten_2026_0 unwinding ABI fails it at link time. It is C, so + * `__cpp_exception` is covered by the second fixture, `wasmcpp` ([aCompiledCppWheelThrowsAndCatchesInsideTheInterpreter]). + * This replaces the cp314 pydantic-core wheel the 3.14.2 runtime * loaded (Decision 10 (c) c1, leader 2026-11-26). * * The wheels are test fixtures checked in under `python-multiplatform/src/wasmJsTest/resources/wheels/` @@ -82,6 +83,55 @@ class WasmCompiledWheelTest { } } + /** + * The C++ fixture: `wasmcpp.wcpp.catch_it()` throws `std::runtime_error("boom 3")` inside the + * side module and returns the message it caught. That imports `python.wasm`'s `__cpp_exception` + * tag and libc++abi's `__cxa_throw` / `__cxa_allocate_exception`, which the C fixture above never + * touches: a runtime built without `-fwasm-exceptions`, or one whose tag the side module cannot + * link against, fails here (a LinkError at import, or an abort at the throw) while `wasmdemo` + * still passes. Built by toolchain with the same adapter and flags (pypackpack 2f3ddd0, 2026-11-27). + */ + @Test + fun aCompiledCppWheelThrowsAndCatchesInsideTheInterpreter() { + val site = PMP_TEST_SITE_PACKAGES?.toString() + if (site == null) { + if (PMP_TEST_WHEELS_REQUIRED?.toBoolean() == true) { + fail("no wheels were staged although -PrequireWasmRuntime=true was passed") + } + println("SKIPPING aCompiledCppWheelThrowsAndCatchesInsideTheInterpreter: no wheels staged") + return + } + PythonTestFixture.withInterpreter { + Python3.withPython { + val status = runInMain( + "import sys as _pmp_sys\n" + + "_pmp_sys.path.insert(0, ${pyStr(site)})\n" + + "try:\n" + + " import wasmcpp.wcpp as _pmp_m\n" + + " _pmp_wheel = [\n" + + " _pmp_m.__file__.rsplit('/', 1)[-1],\n" + + " _pmp_m.catch_it(),\n" + + " repr(_pmp_sys._is_gil_enabled()),\n" + + " ]\n" + + "except BaseException as e:\n" + + " _pmp_wheel = ['FAILED ' + type(e).__name__ + ': ' + str(e)]\n" + + "finally:\n" + + " _pmp_sys.path.remove(${pyStr(site)})\n", + ) + assertEquals(0, status) + val result = evalToString("' | '.join(_pmp_wheel)") + runInMain("del _pmp_wheel, _pmp_sys") + assertEquals( + "wcpp.cpython-315t-wasm32-emscripten.so | boom 3 | False", + result, + "importing the compiled wasmcpp wheel or catching its C++ exception failed. A LinkError " + + "naming __cpp_exception means python.wasm does not export the C++ exception tag " + + "(see WasmInterpreterAbiTest).", + ) + } + } + } + /** * The fixtures are what their README says they are: every pinned wheel is present with its * sha256, and nothing unpinned sits beside them. A rebuilt wheel (new emsdk or ABI) changes the @@ -121,6 +171,8 @@ class WasmCompiledWheelTest { val PINNED_WHEELS = mapOf( "wasmdemo-0.1.0-cp315-cp315t-pyemscripten_2026_0_wasm32.whl" to "df57a28e3a61f4eb8bc5fe84e4a09bdc76e8e720bd6c348345c3fb86c772298a", + "wasmcpp-0.1.0-cp315-cp315t-pyemscripten_2026_0_wasm32.whl" to + "6a41eb2a1be0421fcf35c862aefeacb11bbdbfc80f34ac2881d739df9a3c96ef", ) } } diff --git a/python-multiplatform/src/wasmJsTest/resources/wheels/README.md b/python-multiplatform/src/wasmJsTest/resources/wheels/README.md new file mode 100644 index 00000000..09462fca --- /dev/null +++ b/python-multiplatform/src/wasmJsTest/resources/wheels/README.md @@ -0,0 +1,36 @@ +# Compiled wasm wheel fixtures + +`WasmCompiledWheelTest` loads these wheels into the wasm interpreter (CPython 3.15t, Emscripten) +to prove that a wheel another toolchain compiled for `pyemscripten_2026_0` links against +`python.wasm` and runs. They are test fixtures, checked in so the test needs no download (leader, +2026-11-27). The test task extracts every `.whl` here into one `site-packages` next to the test +bundle; `-PwasmWheelsDir=` points it at another directory. + +| Wheel | sha256 | Module | Expected | +|---|---|---|---| +| `wasmdemo-0.1.0-cp315-cp315t-pyemscripten_2026_0_wasm32.whl` (1892 bytes) | `df57a28e3a61f4eb8bc5fe84e4a09bdc76e8e720bd6c348345c3fb86c772298a` | `wasmdemo.wmod` (C) | `answer()` is 42; `unwind()` is 7 through `setjmp`/`longjmp`, so it imports the `__c_longjmp` tag | +| `wasmcpp-0.1.0-cp315-cp315t-pyemscripten_2026_0_wasm32.whl` (2213 bytes) | `6a41eb2a1be0421fcf35c862aefeacb11bbdbfc80f34ac2881d739df9a3c96ef` | `wasmcpp.wcpp` (C++) | `catch_it()` throws `std::runtime_error("boom 3")` inside the module and returns `"boom 3"`, so it imports the `__cpp_exception` tag and libc++abi's `__cxa_throw` | + +`theCheckedInWheelsAreTheOnesTheReadmeDescribes` fails when a wheel here is not in the table above +(through `PINNED_WHEELS` in the test) or its hash differs. Update this table and `PINNED_WHEELS` +together. + +## How they were built + +Both by pypackpack's Emscripten adapter (pypackpack #82, PR #180), at pypackpack commit `2f3ddd0` +(branch `feat/82-wasm-compile`), built and handed over by the toolchain teammate on 2026-11-27: + +```bash +PPP_WASM_REAL_BUILD=1 \ +EMSDK= \ +PPP_WASM_RUNTIME_MANIFEST= \ +PPP_WASM_WHEEL_OUT= \ +./gradlew :packpack:test --tests '*EmscriptenRealBuildTest*' +``` + +- Emscripten 5.0.3, this repository's pin. +- Against the 3.15t headers of this repository's wasm build at `e5c4a058` (CPython `d220409a`). +- Flags: `-fwasm-exceptions -sSUPPORT_LONGJMP=wasm -pthread -fPIC -sSIDE_MODULE=1`. + +Rebuilding the C wheel at that commit gave a byte-identical file. A new Emscripten or ABI changes +the hashes; ask for a rebuild with the same command and update the table. diff --git a/python-multiplatform/src/wasmJsTest/resources/wheels/wasmcpp-0.1.0-cp315-cp315t-pyemscripten_2026_0_wasm32.whl b/python-multiplatform/src/wasmJsTest/resources/wheels/wasmcpp-0.1.0-cp315-cp315t-pyemscripten_2026_0_wasm32.whl new file mode 100644 index 0000000000000000000000000000000000000000..f93625ad8fbb1ec690720f151f3cf1a4e719f5ed GIT binary patch literal 2213 zcmWIWW@Zs#;Nak3VDM06KnB7&ryk0>iGedwkJ5V(P0~1tr z08S(Hkc=n?nxmIoP+5|ZpQmeVXj-BRGThimH#N67xhS)sBsEX3IKMRHY~F1*fq9WZ zBBG~0?kW_xsmb;C#{>q~EXxL_`$u+oCGGHS)v`OHv1{4Nt-dprB8&bm7Os7}w%yJ# ze#!bv?k|>_AAYH$xx;PsI)!&1ey2T~Ju{YbPfnLZ_wC1#5-#cbW*a|g&*J!T$1bI^ z@2BD`_5+F{W*H)Uy?Y*fVS95c$~dLuVEg9$#~&*-j{0fYs%~d6xg&Az+hU(ecb79i zCx+yg@1J?u=|}jy4~GoCX?mQ{j#ty_Pu3H z%3q&2%~XHx{jc}#i*A4Q-y5>x3U|o1*ZgcPx#vS4g)leA38Wf@Hoq)5&+eW6CnDv| zKA-c-qCP8UnDkzr`|iQ-z5hjT#VpzKGk>My%{9ShtNkwj5LzX*va7k!V$Y0evTLXP zDb#w;f9T2;;f?aKY!@Tm1Uy^lv)SU)A&0Z44A)L+bpNE%!E*A~a@BpS+U0+IjOa4Y zw2>7}oqnZAQb{va@_^TugeBXi`Yd;JIbImJ=xdADw0jXLMmB8D&i+qLK3`S{G!k-u z?zqCELTh=*WzP^ZZ>Ewr|7LnTQdrdE7WYDr^R4)DW5>l)+~R&*Yt_gw_ zKUO|57n^(H`rU)9sjIWpPq~&qIsC4E&O1vRp+}SQc5w)29qeB@L)&z{o4=yxKgn&8 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