Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .github/workflows/wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions docs/platforms/wasm-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
21 changes: 6 additions & 15 deletions python-multiplatform/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -2666,7 +2657,7 @@ tasks.withType<org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest>().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()

Expand Down Expand Up @@ -2704,7 +2695,7 @@ tasks.withType<org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest>().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(
Expand Down
48 changes: 2 additions & 46 deletions python-multiplatform/scripts/wasm/build-cpython.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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: "<file name> <url> <sha256>", one per line.
WHEELS_DIR="${WASM_WHEELS_DIR:-$CACHES/wasm-wheels}"
WHEELS=()

die() { echo "build-cpython: $*" >&2; exit 1; }

# --- toolchain --------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion python-multiplatform/src/wasmJsMain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
Loading