-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
wasm: support for wasm32-wasip2 target #12653
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
base: main
Are you sure you want to change the base?
Changes from all commits
485b672
9472e85
4aa6ff1
dca4733
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -133,6 +133,7 @@ EBADF | |
| EBUSY | ||
| EEXIST | ||
| EINVAL | ||
| EISDIR | ||
| ENODATA | ||
| ENOENT | ||
| ENOSPC | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -147,7 +147,7 @@ use std::io::{BufRead, BufReader}; | |
| use std::iter; | ||
| #[cfg(unix)] | ||
| use std::os::unix::ffi::{OsStrExt, OsStringExt}; | ||
| #[cfg(target_os = "wasi")] | ||
| #[cfg(all(target_os = "wasi", target_env = "p1"))] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, what happens when using p2 ?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It fails to compile with:
I am avoiding it so not to deal with needing Rust nightly. Additionally, WASI should only expect valid UTF-8 paths (as stated here and in other parts of the WASI specification). |
||
| use std::os::wasi::ffi::{OsStrExt, OsStringExt}; | ||
| use std::str; | ||
| use std::str::Utf8Chunk; | ||
|
|
@@ -455,7 +455,7 @@ impl error::UError for NonUtf8OsStrError {} | |
| #[cfg_attr(any(unix, target_os = "wasi"), expect(clippy::unnecessary_wraps))] | ||
| pub fn os_str_as_bytes(os_string: &OsStr) -> Result<&[u8], NonUtf8OsStrError> { | ||
| #[cfg(any(unix, target_os = "wasi"))] | ||
| return Ok(os_string.as_bytes()); | ||
| return Ok(os_string.as_encoded_bytes()); | ||
|
|
||
|
eduardomourar marked this conversation as resolved.
|
||
| #[cfg(not(any(unix, target_os = "wasi")))] | ||
| os_string | ||
|
|
@@ -472,7 +472,7 @@ pub fn os_str_as_bytes(os_string: &OsStr) -> Result<&[u8], NonUtf8OsStrError> { | |
| /// and wraps [`OsStr::to_string_lossy`] on non-unix platforms. | ||
| pub fn os_str_as_bytes_lossy(os_string: &OsStr) -> Cow<'_, [u8]> { | ||
| #[cfg(any(unix, target_os = "wasi"))] | ||
| return Cow::from(os_string.as_bytes()); | ||
| return Cow::from(os_string.as_encoded_bytes()); | ||
|
eduardomourar marked this conversation as resolved.
|
||
|
|
||
| #[cfg(not(any(unix, target_os = "wasi")))] | ||
| match os_string.to_string_lossy() { | ||
|
|
@@ -486,12 +486,15 @@ pub fn os_str_as_bytes_lossy(os_string: &OsStr) -> Cow<'_, [u8]> { | |
| /// | ||
| /// This always succeeds on unix platforms, | ||
| /// and fails on other platforms if the bytes can't be parsed as UTF-8. | ||
| #[cfg_attr(any(unix, target_os = "wasi"), expect(clippy::unnecessary_wraps))] | ||
| #[cfg_attr( | ||
| any(unix, all(target_os = "wasi", target_env = "p1")), | ||
| expect(clippy::unnecessary_wraps) | ||
| )] | ||
| pub fn os_str_from_bytes(bytes: &[u8]) -> error::UResult<Cow<'_, OsStr>> { | ||
| #[cfg(any(unix, target_os = "wasi"))] | ||
| #[cfg(any(unix, all(target_os = "wasi", target_env = "p1")))] | ||
| return Ok(Cow::Borrowed(OsStr::from_bytes(bytes))); | ||
|
|
||
| #[cfg(not(any(unix, target_os = "wasi")))] | ||
| #[cfg(not(any(unix, all(target_os = "wasi", target_env = "p1"))))] | ||
| Ok(Cow::Owned(OsString::from(str::from_utf8(bytes).map_err( | ||
| |_| error::UUsageError::new(1, "Unable to transform bytes into OsStr"), | ||
| )?))) | ||
|
|
@@ -501,12 +504,15 @@ pub fn os_str_from_bytes(bytes: &[u8]) -> error::UResult<Cow<'_, OsStr>> { | |
| /// | ||
| /// This always succeeds on unix platforms, | ||
| /// and fails on other platforms if the bytes can't be parsed as UTF-8. | ||
| #[cfg_attr(any(unix, target_os = "wasi"), expect(clippy::unnecessary_wraps))] | ||
| #[cfg_attr( | ||
| any(unix, all(target_os = "wasi", target_env = "p1")), | ||
| expect(clippy::unnecessary_wraps) | ||
| )] | ||
| pub fn os_string_from_vec(vec: Vec<u8>) -> error::UResult<OsString> { | ||
| #[cfg(any(unix, target_os = "wasi"))] | ||
| #[cfg(any(unix, all(target_os = "wasi", target_env = "p1")))] | ||
| return Ok(OsString::from_vec(vec)); | ||
|
|
||
| #[cfg(not(any(unix, target_os = "wasi")))] | ||
| #[cfg(not(any(unix, all(target_os = "wasi", target_env = "p1"))))] | ||
| Ok(OsString::from(String::from_utf8(vec).map_err(|_| { | ||
| error::UUsageError::new(1, "invalid UTF-8 was detected in one or more arguments") | ||
| })?)) | ||
|
|
@@ -516,11 +522,14 @@ pub fn os_string_from_vec(vec: Vec<u8>) -> error::UResult<OsString> { | |
| /// | ||
| /// This always succeeds on unix platforms, | ||
| /// and fails on other platforms if the bytes can't be parsed as UTF-8. | ||
| #[cfg_attr(any(unix, target_os = "wasi"), expect(clippy::unnecessary_wraps))] | ||
| #[cfg_attr( | ||
| any(unix, all(target_os = "wasi", target_env = "p1")), | ||
| expect(clippy::unnecessary_wraps) | ||
| )] | ||
| pub fn os_string_to_vec(s: OsString) -> error::UResult<Vec<u8>> { | ||
| #[cfg(any(unix, target_os = "wasi"))] | ||
| #[cfg(any(unix, all(target_os = "wasi", target_env = "p1")))] | ||
| let v = s.into_vec(); | ||
| #[cfg(not(any(unix, target_os = "wasi")))] | ||
| #[cfg(not(any(unix, all(target_os = "wasi", target_env = "p1"))))] | ||
| let v = s | ||
| .into_string() | ||
| .map_err(|_| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no case for wasm32-wasip2 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skipping integration tests for now until I fix all the error handling issues. It will be in the next PR.