|
36 | 36 | //! systems are using the recommended interface and respect maximum buffer |
37 | 37 | //! sizes. |
38 | 38 | //! |
39 | | -//! ## Support for WebAssembly and ams.js |
| 39 | +//! ## Support for WebAssembly and asm.js |
40 | 40 | //! |
41 | 41 | //! The three Emscripten targets `asmjs-unknown-emscripten`, |
42 | 42 | //! `wasm32-unknown-emscripten` and `wasm32-experimental-emscripten` use |
|
46 | 46 | //! methods directly, using either `stdweb` or `wasm-bindgen` depending on what |
47 | 47 | //! features are activated for this crate. Note that if both features are |
48 | 48 | //! enabled `wasm-bindgen` will be used. If neither feature is enabled, |
49 | | -//! `getrandom` will always fail. |
| 49 | +//! compiling `getrandom` will result in a compilation error. It can be disabled |
| 50 | +//! by enabling `wasm_dummy` feature, with which `getrandom` will use an always |
| 51 | +//! erroring dummy implementation. |
50 | 52 | //! |
51 | 53 | //! The WASI target `wasm32-wasi` uses the `__wasi_random_get` function defined |
52 | 54 | //! by the WASI standard. |
@@ -231,12 +233,24 @@ cfg_if! { |
231 | 233 | #[path = "wasm32_bindgen.rs"] mod imp; |
232 | 234 | } else if #[cfg(feature = "stdweb")] { |
233 | 235 | #[path = "wasm32_stdweb.rs"] mod imp; |
234 | | - } else { |
| 236 | + } else if #[cfg(any(feature = "wasm_dummy", feature = "dummy"))] { |
235 | 237 | #[path = "dummy.rs"] mod imp; |
| 238 | + } else { |
| 239 | + compile_error!("\ |
| 240 | + wasm32-unknown-unknown target requires one of the following |
| 241 | + features to be enabled: `stdweb`, `wasm-bindgen` or |
| 242 | + `dummy`/`wasm_dummy`\ |
| 243 | + "); |
236 | 244 | } |
237 | 245 | } |
238 | | - } else { |
| 246 | + } else if #[cfg(feature = "dummy")] { |
239 | 247 | #[path = "dummy.rs"] mod imp; |
| 248 | + } else { |
| 249 | + compile_error!("\ |
| 250 | + target is not supported, you may enable dummy implementation \ |
| 251 | + using `dummy` feature or replace `getrandom` crate with a custom \ |
| 252 | + crate which supports your target\ |
| 253 | + "); |
240 | 254 | } |
241 | 255 | } |
242 | 256 |
|
|
0 commit comments