diff --git a/Cargo.toml b/Cargo.toml index e8494cd9..1ccfa0a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,9 @@ core = { version = "1.0", optional = true, package = "rustc-std-workspace-core" [target.'cfg(any(unix, target_os = "redox", target_os = "wasi"))'.dependencies] libc = { version = "0.2.60", default-features = false } +[target.'cfg(target_os = "wasi")'.dependencies] +wasi = "0.5" + [target.wasm32-unknown-unknown.dependencies] wasm-bindgen = { version = "0.2.29", optional = true } stdweb = { version = "0.4.18", optional = true } diff --git a/src/wasi.rs b/src/wasi.rs index 0920752f..a050afc8 100644 --- a/src/wasi.rs +++ b/src/wasi.rs @@ -9,12 +9,12 @@ //! Implementation for WASI use crate::Error; use core::num::NonZeroU32; +use wasi::wasi_unstable::random_get; pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> { - let ret = - unsafe { libc::__wasi_random_get(dest.as_mut_ptr() as *mut libc::c_void, dest.len()) }; + let ret = random_get(dest); if let Some(code) = NonZeroU32::new(ret as u32) { - error!("WASI: __wasi_random_get: failed with {}", ret); + error!("WASI: random_get failed with return value {}", code); Err(Error::from(code)) } else { Ok(()) // Zero means success for WASI