← Back to Pull requests

Emit a WASI platform tag for non-bin extension wheels #3321

Closed
unknown closed this pull request without merging on Oct 08, 2026 11:20 UTC
View on GitHub
unknown unknown commented on Oct 02, 2026 18:12 UTC
Author

Problem

maturin build --target wasm32-wasip1 tags every WASI wheel any, regardless of binding type. That's correct for bindings = "bin" (a .wasm binary behind a wasmtime launcher, genuinely host-portable, added in #1107), but wrong for PyO3/cffi/uniffi bindings: those compile straight to a .wasm extension module that only a WASI-capable Python build can load. The wasi-wheels project already works around this by manually retagging its built wheels from any to wasi_0_0_0_wasm32 after the fact.

As noted in the March 2026 status update on this issue, the actual loadability gap (no dlopen on WASI) is a CPython/WASI platform limitation outside maturin's reach. This PR addresses the one piece that is reachable from maturin: giving the wheel the tag it should have had in the first place, so downstream tooling doesn't need the manual retag step.

Fix

ProjectContext::get_platform_tag already has the bridge model in scope at its one call into target::get_platform_tag, so this threads an is_bin: bool through that single call site instead of adding a parallel dispatch path. The existing (Os::Wasi, Arch::Wasm32) arm now calls a new wasi_platform_tag(is_bin) helper: any for bin bindings (unchanged), wasi_0_0_0_wasm32 otherwise. That tag mirrors CPython's own sysconfig.get_platform() fallback behavior on WASI (no WASI special-case there either, so it falls back to os.uname(), which reports sysname=wasi, release=0.0.0, machine=wasm32) and matches what wasi-wheels already retags to by hand. There's no PEP defining a WASI wheel tag yet (unlike Emscripten's PEP 783), so this follows existing real-world convention rather than a ratified spec.

Both wasm32-wasip1 and wasm32-wasip2 resolve to the same internal Os::Wasi and get the same treatment; CPython's own WASI support (per PEP 816) is wasip1 only today, so a wasip2 extension wheel has no consumer yet — a known limitation, not something this PR tries to solve by splitting the Os enum.

This is a behavior change for non-bin WASI wheels: anyone currently installing one with only --platform any will need to add --platform wasi_0_0_0_wasm32 (wasi-wheels' own install instructions already pass both). --compatibility pypi validation is unaffected either way, since it already bails out for any WASI target via is_arch_supported_by_pypi.

Background: I ship both maturin/PyO3 wheels and separate wasm32 (wasm-bindgen, wasm32-unknown-unknown) builds from the same Rust crates across several of my own crates, which is what pointed me at this specific gap in the tag dispatch rather than the broader (and currently unsolvable) extension-loading problem.

Testing


  • cargo test --lib target::platform_tag (includes the two new tests below): pass

  • cargo clippy --tests --all-features -- -D warnings: pass

  • cargo fmt --all -- --check: pass
  • Added test_wasi_platform_tag (the bin/non-bin branch in isolation) and test_get_platform_tag_wasi (the full dispatch for both wasm32-wasip1 and wasm32-wasip2), following the existing pure-function test style in this module (e.g. test_pep783_emscripten_platform_tag) rather than requiring a WASI toolchain. I did not run the integration_wasm_hello_world end-to-end test locally — wasmtime isn't installed in my environment — but it's unaffected by this change (test-crates/hello-world uses bindings = "bin", which keeps the any tag), and CI will cover it.

    Addresses #2338.

    Diff: 447 lines (+335 / -112) across 5 files Reviewer: messense Review duration: 8227m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 447 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.365
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3321"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.4% (MEDIUM) · Higher = larger blast radius
    45.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.9% · Safe to merge
    17.9%
    Repository