Update to wasi 0.11 (#253)
* Update to wasi 0.11 The main breaking change between v0.10 and v0.11 is that Error is removed in favour of Errno. Unfortunately we can't create an Errno from outside the wasi create so we're loosing some debug information for errors. I've opened an issue to add back such a constructor, see <https://github.com/bytecodealliance/wasi/issues/64>. * Use libc::strerror to get the error message on wasi Since wasi v0.11 doesn't (yet) provided a way to create Errno, see <https://github.com/bytecodealliance/wasi/issues/64>. * Remove libc dependency for WASI This does mean that we won't get an error message for the error type.
This commit is contained in:
parent
4882ac8a4c
commit
2d65a40cc5
@ -21,7 +21,7 @@ core = { version = "1.0", optional = true, package = "rustc-std-workspace-core"
|
||||
libc = { version = "0.2.120", default-features = false }
|
||||
|
||||
[target.'cfg(target_os = "wasi")'.dependencies]
|
||||
wasi = "0.10"
|
||||
wasi = "0.11"
|
||||
|
||||
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
|
||||
wasm-bindgen = { version = "0.2.62", default-features = false, optional = true }
|
||||
|
@ -109,10 +109,6 @@ cfg_if! {
|
||||
let idx = buf.iter().position(|&b| b == 0).unwrap_or(n);
|
||||
core::str::from_utf8(&buf[..idx]).ok()
|
||||
}
|
||||
} else if #[cfg(target_os = "wasi")] {
|
||||
fn os_err(errno: i32, _buf: &mut [u8]) -> Option<wasi::Error> {
|
||||
wasi::Error::from_raw_error(errno as _)
|
||||
}
|
||||
} else {
|
||||
fn os_err(_errno: i32, _buf: &mut [u8]) -> Option<&str> {
|
||||
None
|
||||
|
12
src/wasi.rs
12
src/wasi.rs
@ -9,15 +9,11 @@
|
||||
//! Implementation for WASI
|
||||
use crate::Error;
|
||||
use core::num::NonZeroU32;
|
||||
use wasi::random_get;
|
||||
use wasi::wasi_snapshot_preview1::random_get;
|
||||
|
||||
pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
|
||||
unsafe {
|
||||
random_get(dest.as_mut_ptr(), dest.len()).map_err(|e: wasi::Error| {
|
||||
// convert wasi's Error into getrandom's NonZeroU32 error
|
||||
// SAFETY: `wasi::Error` is `NonZeroU16` internally, so `e.raw_error()`
|
||||
// will never return 0
|
||||
NonZeroU32::new_unchecked(e.raw_error() as u32).into()
|
||||
})
|
||||
match unsafe { random_get(dest.as_mut_ptr() as i32, dest.len() as i32) } {
|
||||
0 => Ok(()),
|
||||
err => Err(unsafe { NonZeroU32::new_unchecked(err as u32) }.into()),
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user