Closed
Conversation
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>
teohhanhui
reviewed
Aug 7, 2025
| #![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))] |
There was a problem hiding this comment.
This doesn't seem like the right thing to do:
3 tasks
Contributor
Author
|
FYI, I'm planning to either reboot this PR or open a new one once tokio-rs/mio#1931 reaches a conclusion. |
Contributor
Author
|
Closing this in favor of #7933 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
This adds support for the new
wasm32-wasip2target platform, which includes more extensive support for sockets thanwasm32-wasip1(formerly known aswasm32-wasi).Solution
The bulk of the changes are in tokio-rs/mio#1836. This patch just tweaks a few
cfgdirectives to indicatewasm32-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.wasmtimeto 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
miodependency back to the upstream project.