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 #1836

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ features = [
"Win32_System_WindowsProgramming", # General future used for various types/funcs
]

[target.'cfg(target_os = "wasi")'.dependencies]
[target.'cfg(all(target_os = "wasi", not(target_env = "p2")))'.dependencies]
wasi = "0.11.0"

[target.'cfg(all(target_os = "wasi", target_env = "p2"))'.dependencies]
wasi = "0.13.3"
Comment on lines +68 to +72
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this really the correct way to go about this? Only 0.11 supports p1?

Copy link

Choose a reason for hiding this comment

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

Looking at https://docs.rs/wasi/latest/wasi/
I would say yes, the last mention I see of p1 is on 0.11

Copy link
Author

Choose a reason for hiding this comment

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


[target.'cfg(target_os = "wasi")'.dependencies]
libc = "0.2.159"

[dev-dependencies]
Expand All @@ -79,7 +84,8 @@ rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"]
targets = [
"aarch64-apple-ios",
"aarch64-linux-android",
"wasm32-wasi",
"wasm32-wasip1",
"wasm32-wasip2",
"x86_64-apple-darwin",
"x86_64-pc-windows-gnu",
"x86_64-pc-windows-msvc",
Expand Down
4 changes: 2 additions & 2 deletions src/io_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl<T> DerefMut for IoSource<T> {
}
}

#[cfg(any(unix, target_os = "hermit"))]
#[cfg(any(unix, target_os = "hermit", all(target_os = "wasi", target_env = "p2")))]
impl<T> event::Source for IoSource<T>
where
T: AsRawFd,
Expand Down Expand Up @@ -175,7 +175,7 @@ where
}
}

#[cfg(target_os = "wasi")]
#[cfg(all(target_os = "wasi", not(target_env = "p2")))]
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we do this?

Suggested change
#[cfg(all(target_os = "wasi", not(target_env = "p2")))]
#[cfg(all(target_os = "wasi", target_env = "p1"))]

Copy link
Author

Choose a reason for hiding this comment

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

The reason I did it that way is because not(target_env = "p2") is backwards compatible with rustc versions prior to the introduction of the wasm32-wasip2 target (i.e. all stable rustc versions as of this writing). See here for further discussion. It does mean we'll need to make changes when p3 becomes available, though. Happy to do whatever you think is best here.

impl<T> event::Source for IoSource<T>
where
T: AsRawFd,
Expand Down
6 changes: 3 additions & 3 deletions src/net/tcp/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::os::windows::io::{
};

use crate::io_source::IoSource;
#[cfg(not(target_os = "wasi"))]
#[cfg(any(not(target_os = "wasi"), target_env = "p2"))]
use crate::sys::tcp::{connect, new_for_addr};
use crate::{event, Interest, Registry, Token};

Expand Down Expand Up @@ -87,10 +87,10 @@ impl TcpStream {
/// entries in the routing cache.
///
/// [write interest]: Interest::WRITABLE
#[cfg(not(target_os = "wasi"))]
#[cfg(any(not(target_os = "wasi"), target_env = "p2"))]
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you use not(all(...)) here?

Copy link
Author

@dicej dicej Oct 10, 2024

Choose a reason for hiding this comment

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

If you mean not(all(target_os = "wasi", target_env = "p1")) then the same rationale I gave above for not using target_env = "p1" applies. Again, though, happy to change it if we're not concerned about backwards rustc compatibility.

pub fn connect(addr: SocketAddr) -> io::Result<TcpStream> {
let socket = new_for_addr(addr)?;
#[cfg(any(unix, target_os = "hermit"))]
#[cfg(any(unix, target_os = "hermit", all(target_os = "wasi", target_env = "p2")))]
let stream = unsafe { TcpStream::from_raw_fd(socket) };
#[cfg(windows)]
let stream = unsafe { TcpStream::from_raw_socket(socket as _) };
Expand Down
1 change: 1 addition & 0 deletions src/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
//! * `Waker`: see [`crate::Waker`].

cfg_os_poll! {
#[cfg(not(all(target_os = "wasi", target_env = "p2")))]
macro_rules! debug_detail {
(
$type: ident ($event_type: ty), $test: path,
Expand Down
Loading
Loading