2727//! | SGX | RDRAND
2828//! | Web browsers | [`Crypto.getRandomValues`][14] (see [Support for WebAssembly and ams.js][14])
2929//! | Node.js | [`crypto.randomBytes`][15] (see [Support for WebAssembly and ams.js][16])
30+ //! | WASI | [`__wasi_random_get`][17]
3031//!
3132//! Getrandom doesn't have a blanket implementation for all Unix-like operating
3233//! systems that reads from `/dev/urandom`. This ensures all supported operating
4445//! features are activated for this crate. Note that if both features are
4546//! enabled `wasm-bindgen` will be used. If neither feature is enabled,
4647//! `getrandom` will always fail.
48+ //!
49+ //! The WASI target `wasm32-unknown-wasi` uses the `__wasi_random_get`
50+ //! function defined by the WASI standard.
51+ //!
4752//!
4853//! ## Early boot
4954//!
108113//! [14]: https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues
109114//! [15]: https://nodejs.org/api/crypto.html#crypto_crypto_randombytes_size_callback
110115//! [16]: #support-for-webassembly-and-amsjs
116+ //! [17]: https://github.com/CraneStation/wasmtime/blob/master/docs/WASI-api.md#__wasi_random_get
111117
112118#![ doc( html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png" ,
113119 html_favicon_url = "https://www.rust-lang.org/favicon.ico" ,
@@ -126,6 +132,21 @@ macro_rules! error { ($($x:tt)*) => () }
126132#[ cfg( target_arch = "wasm32" ) ]
127133extern crate std;
128134
135+ #[ cfg( any(
136+ target_os = "android" ,
137+ target_os = "netbsd" ,
138+ target_os = "solaris" ,
139+ target_os = "illumos" ,
140+ target_os = "redox" ,
141+ target_os = "dragonfly" ,
142+ target_os = "haiku" ,
143+ target_os = "linux" ,
144+ all(
145+ target_arch = "wasm32" ,
146+ not( target_env = "wasi" )
147+ ) ,
148+ ) ) ]
149+ mod utils;
129150mod error;
130151pub use crate :: error:: Error ;
131152
@@ -169,11 +190,13 @@ mod_use!(cfg(target_os = "solaris"), solaris);
169190mod_use ! ( cfg( target_os = "illumos" ) , solaris) ;
170191mod_use ! ( cfg( windows) , windows) ;
171192mod_use ! ( cfg( target_env = "sgx" ) , sgx) ;
193+ mod_use ! ( cfg( target_env = "wasi" ) , wasi) ;
172194
173195mod_use ! (
174196 cfg( all(
175197 target_arch = "wasm32" ,
176198 not( target_os = "emscripten" ) ,
199+ not( target_env = "wasi" ) ,
177200 feature = "wasm-bindgen"
178201 ) ) ,
179202 wasm32_bindgen
@@ -183,6 +206,7 @@ mod_use!(
183206 cfg( all(
184207 target_arch = "wasm32" ,
185208 not( target_os = "emscripten" ) ,
209+ not( target_env = "wasi" ) ,
186210 not( feature = "wasm-bindgen" ) ,
187211 feature = "stdweb" ,
188212 ) ) ,
@@ -213,6 +237,7 @@ mod_use!(
213237 target_arch = "wasm32" ,
214238 any(
215239 target_os = "emscripten" ,
240+ target_env = "wasi" ,
216241 feature = "wasm-bindgen" ,
217242 feature = "stdweb" ,
218243 ) ,
0 commit comments