Skip to content

add wasm32-wasip2 support#6893

Closed
dicej wants to merge 1 commit intotokio-rs:masterfrom
dicej:wasip2
Closed

add wasm32-wasip2 support#6893
dicej wants to merge 1 commit intotokio-rs:masterfrom
dicej:wasip2

Conversation

@dicej
Copy link
Copy Markdown
Contributor

@dicej dicej commented Oct 9, 2024

Motivation

This adds support for the new wasm32-wasip2 target platform, which includes more extensive support for sockets than wasm32-wasip1 (formerly known as wasm32-wasi).

Solution

The bulk of the changes are in tokio-rs/mio#1836. This patch just tweaks a few cfg directives to indicate wasm32-wasip2's additional capabilities.

In the future, we could consider adding support for tokio::net::lookup_host. WASIp2 natively supports asynchronous DNS lookups and is single threaded, whereas Tokio currently assumes DNS lookups are blocking and require multithreading to emulate async lookups. A WASIp2-specific implementation could do the lookup directly without multithreading.

I've tested this end-to-end using https://github.com/dicej/wasi-sockets-tests, which includes smoke tests for mio, tokio, tokio-postgres, etc. I'd also be happy to add tests to this repo if appropriate; it would require adding a dev-dependency on e.g. wasmtime to actually run the test cases.

Note that this is a draft PR until tokio-rs/mio#1836 is merged, at which point I'll switch the mio dependency back to the upstream project.

@dicej dicej mentioned this pull request Oct 9, 2024
6 tasks
@Darksonn Darksonn added A-tokio Area: The main tokio crate T-wasm Topic: Web Assembly labels Oct 10, 2024
@Darksonn
Copy link
Copy Markdown
Member

Looks ok, but let's wait for the mio PR.

This adds support for the new `wasm32-wasip2` target platform, which includes
more extensive support for sockets than `wasm32-wasip1` (formerly known as
`wasm32-wasi`).

The bulk of the changes are in tokio-rs/mio#1836.  This
patch just tweaks a few `cfg` directives to indicate `wasm32-wasip2`'s
additional capabilities.

In the future, we could consider adding support for `ToSocketAddrs`.  WASIp2
natively supports asynchronous DNS lookups and is single threaded, whereas Tokio
currently assumes DNS lookups are blocking and require multithreading to emulate
async lookups.  A WASIp2-specific implementation could do the lookup directly
without multithreading.

I've tested this end-to-end using https://github.com/dicej/wasi-sockets-tests,
which includes smoke tests for `mio`, `tokio`, `tokio-postgres`, etc.  I'd also
be happy to add tests to this repo if appropriate; it would require adding a
dev-dependency on e.g. `wasmtime` to actually run the test cases.

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
#![cfg_attr(docsrs, allow(unused_attributes))]
#![cfg_attr(loom, allow(dead_code, unreachable_pub))]
#![cfg_attr(windows, allow(rustdoc::broken_intra_doc_links))]
#![cfg_attr(all(target_os = "wasi", target_env = "p2"), feature(wasip2))]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This doesn't seem like the right thing to do:

rust-lang/rust#130323 (comment)

@dicej
Copy link
Copy Markdown
Contributor Author

dicej commented Feb 20, 2026

FYI, I'm planning to either reboot this PR or open a new one once tokio-rs/mio#1931 reaches a conclusion.

@dicej
Copy link
Copy Markdown
Contributor Author

dicej commented Feb 24, 2026

Closing this in favor of #7933

@dicej dicej closed this Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-tokio Area: The main tokio crate T-wasm Topic: Web Assembly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants