Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add wasm32-wasip2 support #6893

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

add wasm32-wasip2 support #6893

wants to merge 1 commit into from

Conversation

dicej
Copy link

@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.

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>
@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
Contributor

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

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.

2 participants