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" ,
@@ -135,7 +141,10 @@ extern crate std;
135141 target_os = "dragonfly" ,
136142 target_os = "haiku" ,
137143 target_os = "linux" ,
138- target_arch = "wasm32" ,
144+ all(
145+ target_arch = "wasm32" ,
146+ not( target_env = "wasi" )
147+ ) ,
139148) ) ]
140149mod utils;
141150mod error;
@@ -181,11 +190,13 @@ mod_use!(cfg(target_os = "redox"), use_file);
181190mod_use ! ( cfg( target_os = "solaris" ) , solaris_illumos) ;
182191mod_use ! ( cfg( windows) , windows) ;
183192mod_use ! ( cfg( target_env = "sgx" ) , sgx) ;
193+ mod_use ! ( cfg( target_env = "wasi" ) , wasi) ;
184194
185195mod_use ! (
186196 cfg( all(
187197 target_arch = "wasm32" ,
188198 not( target_os = "emscripten" ) ,
199+ not( target_env = "wasi" ) ,
189200 feature = "wasm-bindgen"
190201 ) ) ,
191202 wasm32_bindgen
@@ -195,6 +206,7 @@ mod_use!(
195206 cfg( all(
196207 target_arch = "wasm32" ,
197208 not( target_os = "emscripten" ) ,
209+ not( target_env = "wasi" ) ,
198210 not( feature = "wasm-bindgen" ) ,
199211 feature = "stdweb" ,
200212 ) ) ,
@@ -225,6 +237,7 @@ mod_use!(
225237 target_arch = "wasm32" ,
226238 any(
227239 target_os = "emscripten" ,
240+ target_env = "wasi" ,
228241 feature = "wasm-bindgen" ,
229242 feature = "stdweb" ,
230243 ) ,
0 commit comments