Skip to content

Add wasm32-wasip2 target support#639

Merged
Thomasdezeeuw merged 2 commits intorust-lang:masterfrom
ricochet:wasip2-support
Feb 13, 2026
Merged

Add wasm32-wasip2 target support#639
Thomasdezeeuw merged 2 commits intorust-lang:masterfrom
ricochet:wasip2-support

Conversation

@ricochet
Copy link
Contributor

Rework of #532 by @nickrum, addressing review feedback from @Darksonn
and @Thomasdezeeuw:

  • Reuses sys/unix.rs instead of creating sys/wasi.rs (per @Thomasdezeeuw's
    code review feedback)
  • MaybeUninitSlice stays unconditional since libc::iovec is available on WASI,
    eliminating 11+ scattered cfg gates (per @Darksonn's concern)
  • Internal cfg changes concentrated in the sys module

Opt-in cfg patterns use all(target_os = "wasi", not(target_env = "p1"))
to match how the libc crate gates WASI p2 socket support. Opt-out
patterns use bare target_os = "wasi" for features unavailable on any
WASI version.

WASI tests run in CI with wasmtime (27/27 pass). Tests for unsupported
socket options are gated out with references to the relevant WASI spec
issues (SO_BROADCAST, SO_LINGER, IPV6_V6ONLY).

export CARGO_TARGET_WASM32_WASIP2_RUNNER="wasmtime --wasi inherit-network"
# Doc-tests are excluded because the SockRef example spawns threads, which
# WASI does not yet support.
cargo test --target wasm32-wasip2 --lib --tests

Closes #268

Based-on: #532
Co-authored-by: Nicola Krumschmidt git@nkcom.de

Rework of rust-lang#532 by @nickrum, addressing review feedback from @Darksonn
and @Thomasdezeeuw:

- Reuses sys/unix.rs instead of creating sys/wasi.rs (per @Thomasdezeeuw's
  code review feedback)
- MaybeUninitSlice stays unconditional since libc::iovec is available on WASI,
  eliminating 11+ scattered cfg gates (per @Darksonn's concern)
- Internal cfg changes concentrated in the sys module

Opt-in cfg patterns use `all(target_os = "wasi", not(target_env = "p1"))`
to match how the libc crate gates WASI p2 socket support. Opt-out
patterns use bare `target_os = "wasi"` for features unavailable on any
WASI version.

WASI tests run in CI with wasmtime (27/27 pass). Tests for unsupported
socket options are gated out with references to the relevant WASI spec
issues (SO_BROADCAST, SO_LINGER, IPV6_V6ONLY).

```bash
export CARGO_TARGET_WASM32_WASIP2_RUNNER="wasmtime --wasi inherit-network"
cargo test --target wasm32-wasip2 --lib --tests
```

Closes rust-lang#268

Based-on: rust-lang#532
Co-authored-by: Nicola Krumschmidt <git@nkcom.de>
Copy link
Member

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cfgs appear to be as stated


[target."cfg(unix)".dependencies]
[target.'cfg(any(unix, target_os = "wasi"))'.dependencies]
libc = "0.2.172"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What libc versions is required as a minimum?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The minimum libc version for the WASI socket2-specific types is 0.2.162 (added in libc PR #3981, which was created specifically for socket2's wasip2 support). The version wasn't changed by this PR — it was already 0.2.172 on master.

Copy link
Collaborator

@Thomasdezeeuw Thomasdezeeuw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

- Restore vita comment on connect_timeout_unbound test
- Move all(target_os = "wasi", ...) after target_os = "cygwin" in cfg lists for consistent ordering
@Thomasdezeeuw
Copy link
Collaborator

Thanks @ricochet

I'm merging this now. @Darksonn if you want any changes regarding #639 (comment) let me know.

@Darksonn
Copy link
Member

No it sounds ok.

@Thomasdezeeuw Thomasdezeeuw merged commit 0955c52 into rust-lang:master Feb 13, 2026
49 of 50 checks passed
@ricochet ricochet deleted the wasip2-support branch February 13, 2026 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support wasm (in some form)

3 participants