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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tokio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ pin-project-lite = "0.2.11"

# Everything else is optional...
bytes = { version = "1.0.0", optional = true }
mio = { version = "1.0.1", optional = true, default-features = false }
# TODO dicej: switch to upstream once WASIp2 support is merged:
mio = { git = "https://github.com/dicej/mio", branch = "wasip2", optional = true, default-features = false }
parking_lot = { version = "0.12.0", optional = true }

[target.'cfg(not(target_family = "wasm"))'.dependencies]
Expand Down
1 change: 1 addition & 0 deletions tokio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, allow(unused_attributes))]
#![cfg_attr(loom, allow(dead_code, unreachable_pub))]
#![cfg_attr(all(target_os = "wasi", target_env = "p2"), feature(wasip2))]

//! A runtime for writing reliable network applications without compromising speed.
//!
Expand Down
9 changes: 9 additions & 0 deletions tokio/src/macros/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,15 @@ macro_rules! cfg_not_wasi {
}
}

macro_rules! cfg_not_wasip1 {
($($item:item)*) => {
$(
#[cfg(any(not(target_os = "wasi"), target_env = "p2"))]
$item
)*
}
}

macro_rules! cfg_is_wasm_not_wasi {
($($item:item)*) => {
$(
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
//! [`AsyncFd`]: crate::io::unix::AsyncFd

mod addr;
cfg_not_wasi! {
cfg_not_wasip1! {
#[cfg(feature = "net")]
pub(crate) use addr::to_socket_addrs;
}
Expand Down
7 changes: 5 additions & 2 deletions tokio/src/net/tcp/stream.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
cfg_not_wasi! {
use std::time::Duration;
}

cfg_not_wasip1! {
use crate::net::{to_socket_addrs, ToSocketAddrs};
use std::future::poll_fn;
use std::time::Duration;
}

use crate::io::{AsyncRead, AsyncWrite, Interest, PollEvented, ReadBuf, Ready};
Expand Down Expand Up @@ -72,7 +75,7 @@ cfg_net! {
}

impl TcpStream {
cfg_not_wasi! {
cfg_not_wasip1! {
/// Opens a TCP connection to a remote host.
///
/// `addr` is an address of the remote host. Anything which implements the
Expand Down
Loading