Pyodide / Emscripten support (PEP 783 pyemscripten wheels)
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Da chiarire
- Stato di attività
- Tranquilla
- Ambito
- backend-api-design, build-system, ci-cd
Direzione di ricerca
Inizia con python/src/reader.rs e src/reader.rs, quindi esegui la matrice delle feature documentata di cargo check --target wasm32-unknown-emscripten per comprendere i limiti attuali. Confronta gli approcci proposti di un core sans-IO, di un executor wasm e di un approccio ibrido, utilizzando gli entry point esistenti Tile::decode e tile-byte-range; il lavoro è completato quando è stato concordato un percorso di implementazione che preservi la Python API e supporti un wheel Pyodide testato a runtime.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Written by claude:
tl;dr: compiling async Rust to Python for emscripten is still really hard
Goal
Make async-tiff usable from Pyodide (Python-in-the-browser, wasm32-unknown-emscripten), shipping PEP 783 pyemscripten_* wheels to PyPI — while keeping the Python API unchanged: TIFF.open(store) stays async and keeps accepting any generic ObspecInput (GetRangeAsync + GetRangesAsync protocol), so a jsfetch-backed store can be swapped in at runtime without user code changes.
Packaging is solved upstream (PEP 783 accepted; maturin ≥ ~1.13 emits pyemscripten tags; pydantic-core and arro3 already ship these wheels). Async runtimes are not: Pyodide is single-threaded, tokio's reactor doesn't exist on emscripten, and pyo3-async-runtimes spawns an OS thread to drive tokio — it panics at init on this target.
Compile experiment results (2026-06-11, validated locally)
Targeted the Python 3.14 line (pyemscripten_2026_0, Emscripten 5.0.3, stable Rust 1.93 — no nightly). Toolchain: Pyodide's patched emsdk via pyodide xbuildenv install-emscripten (not stock emsdk), config from pyodide config get.
Everything compiles, links, and runs. A throwaway pyo3 wheel depending on async-tiff --no-default-features --features lerc,jpeg2k,webp,lzma,tokio built with uvx maturin build --release --target wasm32-unknown-emscripten -i python3.14, then imported and ran inside Pyodide (node, via pyodide venv), constructing DecoderRegistry::default() with all codecs registered. All four C/C++ sys crates compiled and linked: zstd-sys, openjpeg-sys, libwebp-sys, lerc-sys.
cargo check --target wasm32-unknown-emscripten feature matrix on the core crate:
| Config | Result |
|---|---|
--no-default-features (zstd, flate2, weezl, jpeg baked in) |
✅ |
tokio (only tokio/sync + io-util — runtime-independent) |
✅ |
jpeg2k (OpenJPEG C), webp, lzma, ndarray, object_store |
✅ |
lerc |
✅ with 2 env vars (below) |
reqwest |
❌ genuinely incompatible |
| default features | ❌ (via reqwest) |
Required env (beyond pyodide's canonical rustflags/cflags):
export CARGO_TARGET_WASM32_UNKNOWN_EMSCRIPTEN_RUSTFLAGS="-C link-arg=-sSIDE_MODULE=2"
export CFLAGS_wasm32_unknown_emscripten="-O2 -g0 -fPIC -fwasm-exceptions -sSUPPORT_LONGJMP=wasm -Oz"
export CXXFLAGS_wasm32_unknown_emscripten="-O2 -g0 -fPIC -fexceptions -fwasm-exceptions -sSUPPORT_LONGJMP=wasm -Oz"
export BINDGEN_EXTRA_CLANG_ARGS_wasm32_unknown_emscripten="-fvisibility=default"
export MATURIN_PYEMSCRIPTEN_PLATFORM_VERSION=2026_0
Findings worth remembering:
- lerc needs two env-var workarounds (no upstream patches): (1) the
cccrate injects-fno-exceptionsfor emscripten C++ but LERC usestry/catch— an explicit-fexceptionsinCXXFLAGS_wasm32_unknown_emscriptenfixes it (-fwasm-exceptionsalone does not re-enable exceptions); (2) bindgen on wasm emits constants but zero functions (clang hidden-visibility default) →BINDGEN_EXTRA_CLANG_ARGS_wasm32_unknown_emscripten="-fvisibility=default". - reqwest can't work: on wasm32 it switches to its wasm-bindgen backend whose futures are
!Send, conflicting withAsyncFileReader: Send + Sync(src/reader.rs); wasm-bindgen JS glue isn't present in an emscripten module anyway. wasm builds use--no-default-features. - emcc is required even for
cargo check— zstd-sys (non-optional via corezstd) compiles C in its build script. - py-async-tiff is blocked as-is: tokio's own guard fires (
Only features sync,macros,io-util,rt,time are supported on wasm), pulled in bypyo3-async-runtimes+pyo3-object_store(rt-multi-thread) and reqwest/hyper (net) via object_store cloud features.rayon/tokio-rayonthread pools also can't run (no threads in Pyodide). - Not yet exercised: actually decoding a tile inside Pyodide (esp. LERC C++ exception handling under wasm EH). Good first runtime test once bindings exist.
The design question (open)
The breakage is not the ObspecInput protocol — it's where it gets consumed. Today python/src/reader.rs wraps store.get_range(...) coroutines via pyo3_async_runtimes::tokio::into_future and tokio drives the futures on a background thread. Options to keep the public API identical:
A — Python-async facade over a sync sans-IO Rust core. Rust gains sync entry points: restartable metadata parse over a sparse buffer (NeedsBytes {range} error → host fetches → retry, precedent: arrow-rs ParquetMetaDataReader::try_parse_sized / NeedMoreData), tile_byte_ranges, decode-from-bytes. A thin pure-Python async wrapper implements today's API on top, calling await store.get_ranges(...) directly in Python — works on any event loop including Pyodide's. ~100–200 lines of Python.
B — Keep Rust async everywhere, swap the executor on wasm. PyO3 experimental-async (Coroutine polls Rust futures inline on the Python event loop — the right model for Pyodide, no threads) + a hand-rolled "await a Python awaitable from Rust" via asyncio.ensure_future + done-callback waker. Single Rust codebase, but unstable PyO3 API, untested on emscripten.
C — Hybrid (was leaning this way): build the sync sans-IO core (useful regardless — free sync API, future wasm-bindgen/JS build), use the Python facade from A as the wasm implementation selected at import time (try/except ImportError, arro3 pattern), leave the native tokio path untouched. If PyO3 native async stabilizes, B becomes a unification path later. Bonus: the facade works with any obspec store on native too, so unifying downward (dropping pyo3-async-runtimes entirely) stays an option pending benchmarks.
Either way the py-async-tiff crate needs the arro3-io structural pattern: a default-on async cargo feature gating the entire async stack (pyo3-async-runtimes, pyo3-object_store, object_store, reqwest, rayon/tokio-rayon, all future_into_py methods), with the wasm wheel built --no-default-features.
Suggested staging (when resumed)
- Sync sans-IO core: sparse-buffer restartable metadata parse + bytes→
Tiledecode path (TileByteRange/TilesByteRangesandTile::decodeare already public and sync) asyncfeature split in py-async-tiff + sync#[pyfunction]s- Python async facade implementing the existing API over the sync core; jsfetch/
pyodide.http.pyfetchobspec store impl - CI: copy arro3's
wheels.ymlemscripten job (xbuildenv install,pyodide config getoutputs, maturin-action) + the two lerc env vars; runtime-test withpyodide venvunder node - Runtime decode tests in Pyodide (all codecs, esp. LERC)
References
- arro3 shipped this end-to-end: kylebarron/arro3#502, kylebarron/arro3#504 (working CI:
.github/workflows/wheels.ymlemscripten job,DEVELOP.md) - https://pydantic.dev/articles/emscripten-wheels-pydantic — maturin + PyEmscripten CI guide
- https://peps.python.org/pep-0783/ · https://blog.pyodide.org/posts/314-release/
- https://pyo3.rs/latest/async-await — PyO3
experimental-async· https://github.com/PyO3/pyo3/issues/1632 - https://blog.pyodide.org/posts/jspi/ — JSPI /
run_syncescape hatch (out of scope for first pass) - arrow-rs
ParquetMetaDataReader::try_parse_sized— sans-IO restartable-parse precedent
- Lingua principale
- Rust
- Stelle
- 125
- Fork
- 17
- Merge medio
- 7h 33m
- PR unite (30g)
- 8
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di developmentseed/async-tiff
-
Panic on TIFFs that omit the SamplesPerPixel tag (spec default is 1)Forse già presa @TomNicholas l’ha presa 130 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
developmentseed/async-tiff#318 ·
-
duplicate
Difficoltà 3/5 1-2 giorni Idoneità per principianti 57/100
developmentseed/async-tiff#376 · 1 commento ·
-
Difficoltà 3/5 Mezza giornata Idoneità per principianti 58/100
developmentseed/async-tiff#354 ·
-
Claude suggestions for performance focusForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 8/100
developmentseed/async-tiff#352 · 1 commento · 2 reazioni ·
-
Make abi3t wheelsAperta
Difficoltà 3/5 Mezza giornata Idoneità per principianti 22/100
developmentseed/async-tiff#350 ·
Tutte le issue di developmentseed/async-tiff
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
storytold/craft-anything#2472 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
getsotto/sotto-authenticator#68 ·
I maintainer di solito rispondono entro 1 giorno
-
Project submission: AegisAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
slavakurilyak/awesome-ai-agents#1046 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
nowledge-co/hawdb#1995 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
swc-project/swc-next-issues#984 ·