27
27
//! | SGX | RDRAND
28
28
//! | Web browsers | [`Crypto.getRandomValues`][14] (see [Support for WebAssembly and ams.js][14])
29
29
//! | Node.js | [`crypto.randomBytes`][15] (see [Support for WebAssembly and ams.js][16])
30
+ //! | WASI | [`__wasi_random_get`][17]
30
31
//!
31
32
//! Getrandom doesn't have a blanket implementation for all Unix-like operating
32
33
//! systems that reads from `/dev/urandom`. This ensures all supported operating
44
45
//! features are activated for this crate. Note that if both features are
45
46
//! enabled `wasm-bindgen` will be used. If neither feature is enabled,
46
47
//! `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
+ //!
47
52
//!
48
53
//! ## Early boot
49
54
//!
108
113
//! [14]: https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues
109
114
//! [15]: https://nodejs.org/api/crypto.html#crypto_crypto_randombytes_size_callback
110
115
//! [16]: #support-for-webassembly-and-amsjs
116
+ //! [17]: https://github.com/CraneStation/wasmtime/blob/master/docs/WASI-api.md#__wasi_random_get
111
117
112
118
#![ doc( html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png" ,
113
119
html_favicon_url = "https://www.rust-lang.org/favicon.ico" ,
@@ -135,7 +141,10 @@ extern crate std;
135
141
target_os = "dragonfly" ,
136
142
target_os = "haiku" ,
137
143
target_os = "linux" ,
138
- target_arch = "wasm32" ,
144
+ all(
145
+ target_arch = "wasm32" ,
146
+ not( target_env = "wasi" )
147
+ ) ,
139
148
) ) ]
140
149
mod utils;
141
150
mod error;
@@ -181,11 +190,13 @@ mod_use!(cfg(target_os = "redox"), use_file);
181
190
mod_use ! ( cfg( target_os = "solaris" ) , solaris_illumos) ;
182
191
mod_use ! ( cfg( windows) , windows) ;
183
192
mod_use ! ( cfg( target_env = "sgx" ) , sgx) ;
193
+ mod_use ! ( cfg( target_env = "wasi" ) , wasi) ;
184
194
185
195
mod_use ! (
186
196
cfg( all(
187
197
target_arch = "wasm32" ,
188
198
not( target_os = "emscripten" ) ,
199
+ not( target_env = "wasi" ) ,
189
200
feature = "wasm-bindgen"
190
201
) ) ,
191
202
wasm32_bindgen
@@ -195,6 +206,7 @@ mod_use!(
195
206
cfg( all(
196
207
target_arch = "wasm32" ,
197
208
not( target_os = "emscripten" ) ,
209
+ not( target_env = "wasi" ) ,
198
210
not( feature = "wasm-bindgen" ) ,
199
211
feature = "stdweb" ,
200
212
) ) ,
@@ -225,6 +237,7 @@ mod_use!(
225
237
target_arch = "wasm32" ,
226
238
any(
227
239
target_os = "emscripten" ,
240
+ target_env = "wasi" ,
228
241
feature = "wasm-bindgen" ,
229
242
feature = "stdweb" ,
230
243
) ,
0 commit comments