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-wasip2
target 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
cfg
directives 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.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.