diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 92f6f48d2..526cf1e87 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -83,6 +83,7 @@ jobs: run: > rustup target add wasm32-wasip1 + wasm32-wasip2 x86_64-unknown-fuchsia - if: matrix.rust == '1.63' run: rustup target add x86_64-fuchsia @@ -102,6 +103,8 @@ jobs: - run: cargo check --workspace --release -vv --target=x86_64-unknown-netbsd --features=all-apis --all-targets - if: matrix.rust != '1.63' run: cargo check --workspace --release -vv --target=wasm32-wasip1 --features=all-apis + - if: matrix.rust != '1.63' + run: cargo check --workspace --release -vv --target=wasm32-wasip2 --features=all-apis - if: matrix.rust != '1.63' run: cargo check --workspace --release -vv --target=x86_64-unknown-fuchsia --features=all-apis --all-targets - if: matrix.rust == '1.63' @@ -179,10 +182,8 @@ jobs: - run: > rustup target add x86_64-unknown-redox - wasm32-wasip1 thumbv7neon-unknown-linux-gnueabihf - run: cargo check --workspace --release -vv --target=x86_64-unknown-redox --features=all-apis - - run: cargo check --workspace --release -vv --target=wasm32-wasip1 --features=all-apis - run: cargo check --workspace --release -vv --target=thumbv7neon-unknown-linux-gnueabihf --features=all-apis check_tier3: diff --git a/Cargo.toml b/Cargo.toml index cac66ead1..7c4235855 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -261,5 +261,6 @@ check-cfg = [ 'cfg(thumb_mode)', 'cfg(wasi)', 'cfg(wasi_ext)', + 'cfg(wasip2)', 'cfg(target_arch, values("xtensa"))', ] diff --git a/build.rs b/build.rs index 19b9067a3..037d374e6 100644 --- a/build.rs +++ b/build.rs @@ -82,6 +82,7 @@ fn main() { // WASI support can utilize wasi_ext if present. if os == "wasi" { use_feature_or_nothing("wasi_ext"); + use_feature_or_nothing("wasip2"); } // If the libc backend is requested, or if we're not on a platform for diff --git a/src/lib.rs b/src/lib.rs index f7892fa17..85da4c858 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,8 @@ all( target_os = "wasi", target_env = "p2", - any(feature = "fs", feature = "mount", feature = "net") + any(feature = "fs", feature = "mount", feature = "net"), + wasip2, ), feature(wasip2) )] diff --git a/src/path/arg.rs b/src/path/arg.rs index 275f0058f..a19a54120 100644 --- a/src/path/arg.rs +++ b/src/path/arg.rs @@ -21,7 +21,11 @@ use std::os::hermit::ext::ffi::{OsStrExt, OsStringExt}; use std::os::unix::ffi::{OsStrExt, OsStringExt}; #[cfg(all(feature = "std", target_os = "vxworks"))] use std::os::vxworks::ext::ffi::{OsStrExt, OsStringExt}; -#[cfg(all(feature = "std", target_os = "wasi"))] +#[cfg(all( + feature = "std", + target_os = "wasi", + any(not(target_env = "p2"), wasip2) +))] use std::os::wasi::ffi::{OsStrExt, OsStringExt}; #[cfg(feature = "std")] use std::path::{Component, Components, Iter, Path, PathBuf}; @@ -225,19 +229,18 @@ impl Arg for String { } #[cfg(feature = "std")] +#[cfg(any(not(target_os = "wasi"), not(target_env = "p2"), wasip2))] impl Arg for &OsStr { #[inline] fn as_str(&self) -> io::Result<&str> { self.to_str().ok_or(io::Errno::INVAL) } - #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { OsStr::to_string_lossy(self) } - #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result> { Ok(Cow::Owned( @@ -245,7 +248,6 @@ impl Arg for &OsStr { )) } - #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result> where @@ -267,19 +269,18 @@ impl Arg for &OsStr { } #[cfg(feature = "std")] +#[cfg(any(not(target_os = "wasi"), not(target_env = "p2"), wasip2))] impl Arg for &OsString { #[inline] fn as_str(&self) -> io::Result<&str> { OsString::as_os_str(self).to_str().ok_or(io::Errno::INVAL) } - #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { self.as_os_str().to_string_lossy() } - #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result> { Ok(Cow::Owned( @@ -288,7 +289,6 @@ impl Arg for &OsString { )) } - #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result> where @@ -308,19 +308,18 @@ impl Arg for &OsString { } #[cfg(feature = "std")] +#[cfg(any(not(target_os = "wasi"), not(target_env = "p2"), wasip2))] impl Arg for OsString { #[inline] fn as_str(&self) -> io::Result<&str> { self.as_os_str().to_str().ok_or(io::Errno::INVAL) } - #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { self.as_os_str().to_string_lossy() } - #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result> { Ok(Cow::Owned( @@ -328,7 +327,6 @@ impl Arg for OsString { )) } - #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result> where @@ -350,19 +348,18 @@ impl Arg for OsString { } #[cfg(feature = "std")] +#[cfg(any(not(target_os = "wasi"), not(target_env = "p2"), wasip2))] impl Arg for &Path { #[inline] fn as_str(&self) -> io::Result<&str> { self.as_os_str().to_str().ok_or(io::Errno::INVAL) } - #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { Path::to_string_lossy(self) } - #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result> { Ok(Cow::Owned( @@ -370,7 +367,6 @@ impl Arg for &Path { )) } - #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result> where @@ -392,6 +388,7 @@ impl Arg for &Path { } #[cfg(feature = "std")] +#[cfg(any(not(target_os = "wasi"), not(target_env = "p2"), wasip2))] impl Arg for &PathBuf { #[inline] fn as_str(&self) -> io::Result<&str> { @@ -401,13 +398,11 @@ impl Arg for &PathBuf { .ok_or(io::Errno::INVAL) } - #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { self.as_path().to_string_lossy() } - #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result> { Ok(Cow::Owned( @@ -416,7 +411,6 @@ impl Arg for &PathBuf { )) } - #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result> where @@ -436,19 +430,18 @@ impl Arg for &PathBuf { } #[cfg(feature = "std")] +#[cfg(any(not(target_os = "wasi"), not(target_env = "p2"), wasip2))] impl Arg for PathBuf { #[inline] fn as_str(&self) -> io::Result<&str> { self.as_os_str().to_str().ok_or(io::Errno::INVAL) } - #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { self.as_os_str().to_string_lossy() } - #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result> { Ok(Cow::Owned( @@ -456,7 +449,6 @@ impl Arg for PathBuf { )) } - #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result> where @@ -524,19 +516,16 @@ impl Arg for &CString { unimplemented!() } - #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { unimplemented!() } - #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result> { Ok(Cow::Borrowed(self)) } - #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result> where @@ -562,19 +551,16 @@ impl Arg for CString { self.to_str().map_err(|_utf8_err| io::Errno::INVAL) } - #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { CStr::to_string_lossy(self) } - #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result> { Ok(Cow::Borrowed(self)) } - #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result> where @@ -600,13 +586,11 @@ impl<'a> Arg for Cow<'a, str> { Ok(self) } - #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { Cow::Borrowed(self) } - #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result> { Ok(Cow::Owned( @@ -614,7 +598,6 @@ impl<'a> Arg for Cow<'a, str> { )) } - #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result> where @@ -640,20 +623,18 @@ impl<'a> Arg for Cow<'a, str> { } #[cfg(feature = "std")] -#[cfg(feature = "alloc")] +#[cfg(any(not(target_os = "wasi"), not(target_env = "p2"), wasip2))] impl<'a> Arg for Cow<'a, OsStr> { #[inline] fn as_str(&self) -> io::Result<&str> { (**self).to_str().ok_or(io::Errno::INVAL) } - #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { (**self).to_string_lossy() } - #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result> { Ok(Cow::Owned( @@ -661,7 +642,6 @@ impl<'a> Arg for Cow<'a, OsStr> { )) } - #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result> where @@ -693,20 +673,17 @@ impl<'a> Arg for Cow<'a, CStr> { self.to_str().map_err(|_utf8_err| io::Errno::INVAL) } - #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { let borrow: &CStr = core::borrow::Borrow::borrow(self); borrow.to_string_lossy() } - #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result> { Ok(Cow::Borrowed(self)) } - #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result> where @@ -726,19 +703,18 @@ impl<'a> Arg for Cow<'a, CStr> { } #[cfg(feature = "std")] +#[cfg(any(not(target_os = "wasi"), not(target_env = "p2"), wasip2))] impl<'a> Arg for Component<'a> { #[inline] fn as_str(&self) -> io::Result<&str> { self.as_os_str().to_str().ok_or(io::Errno::INVAL) } - #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { self.as_os_str().to_string_lossy() } - #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result> { Ok(Cow::Owned( @@ -746,7 +722,6 @@ impl<'a> Arg for Component<'a> { )) } - #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result> where @@ -768,19 +743,18 @@ impl<'a> Arg for Component<'a> { } #[cfg(feature = "std")] +#[cfg(any(not(target_os = "wasi"), not(target_env = "p2"), wasip2))] impl<'a> Arg for Components<'a> { #[inline] fn as_str(&self) -> io::Result<&str> { self.as_path().to_str().ok_or(io::Errno::INVAL) } - #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { self.as_path().to_string_lossy() } - #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result> { Ok(Cow::Owned( @@ -789,7 +763,6 @@ impl<'a> Arg for Components<'a> { )) } - #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result> where @@ -812,19 +785,18 @@ impl<'a> Arg for Components<'a> { } #[cfg(feature = "std")] +#[cfg(any(not(target_os = "wasi"), not(target_env = "p2"), wasip2))] impl<'a> Arg for Iter<'a> { #[inline] fn as_str(&self) -> io::Result<&str> { self.as_path().to_str().ok_or(io::Errno::INVAL) } - #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { self.as_path().to_string_lossy() } - #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result> { Ok(Cow::Owned( @@ -833,7 +805,6 @@ impl<'a> Arg for Iter<'a> { )) } - #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result> where @@ -939,6 +910,7 @@ impl Arg for &Vec { } #[cfg(feature = "alloc")] +#[cfg(any(not(target_os = "wasi"), not(target_env = "p2"), wasip2))] impl Arg for Vec { #[inline] fn as_str(&self) -> io::Result<&str> { diff --git a/src/path/dec_int.rs b/src/path/dec_int.rs index afda549f1..a05e30348 100644 --- a/src/path/dec_int.rs +++ b/src/path/dec_int.rs @@ -13,7 +13,11 @@ use core::mem::{self, MaybeUninit}; use core::num::NonZeroU8; #[cfg(all(feature = "std", unix))] use std::os::unix::ffi::OsStrExt; -#[cfg(all(feature = "std", target_os = "wasi"))] +#[cfg(all( + feature = "std", + target_os = "wasi", + any(not(target_env = "p2"), wasip2) +))] use std::os::wasi::ffi::OsStrExt; #[cfg(feature = "std")] use {core::fmt, std::ffi::OsStr, std::path::Path}; @@ -236,6 +240,7 @@ impl DecInt { } #[cfg(feature = "std")] +#[cfg(any(not(target_os = "wasi"), not(target_env = "p2"), wasip2))] impl AsRef for DecInt { #[inline] fn as_ref(&self) -> &Path {