|
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 | +//! ## Unsupported targets |
| 40 | +//! By default, compiling `getrandom` for an unsupported target will result in |
| 41 | +//! a compilation error. If you want to build an application which uses `getrandom` |
| 42 | +//! for such target, you can either: |
| 43 | +//! - Use [`[replace]`][replace] or [`[patch]`][patch] section in your `Cargo.toml` |
| 44 | +//! to switch to a custom implementation with a support of your target. |
| 45 | +//! - Enable the `dummy` feature to have getrandom use an implementation that always |
| 46 | +//! fails at run-time on unsupported targets. |
| 47 | +//! |
| 48 | +//! [replace]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-replace-section |
| 49 | +//! [patch]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-patch-section |
| 50 | +//! |
| 51 | +//! ## Support for WebAssembly and asm.js |
40 | 52 | //!
|
41 | 53 | //! The three Emscripten targets `asmjs-unknown-emscripten`,
|
42 | 54 | //! `wasm32-unknown-emscripten` and `wasm32-experimental-emscripten` use
|
|
46 | 58 | //! methods directly, using either `stdweb` or `wasm-bindgen` depending on what
|
47 | 59 | //! features are activated for this crate. Note that if both features are
|
48 | 60 | //! enabled `wasm-bindgen` will be used. If neither feature is enabled,
|
49 |
| -//! `getrandom` will always fail. |
| 61 | +//! compiling `getrandom` will result in a compilation error. It can be avoided |
| 62 | +//! by enabling the `dummy` feature, which will make `getrandom` to use an |
| 63 | +//! always failing implementation. |
50 | 64 | //!
|
51 | 65 | //! The WASI target `wasm32-wasi` uses the `__wasi_random_get` function defined
|
52 | 66 | //! by the WASI standard.
|
@@ -221,18 +235,20 @@ cfg_if! {
|
221 | 235 | target_env = "sgx",
|
222 | 236 | )))] {
|
223 | 237 | #[path = "rdrand.rs"] mod imp;
|
224 |
| - } else if #[cfg(target_arch = "wasm32")] { |
225 |
| - cfg_if! { |
226 |
| - if #[cfg(feature = "wasm-bindgen")] { |
227 |
| - #[path = "wasm32_bindgen.rs"] mod imp; |
228 |
| - } else if #[cfg(feature = "stdweb")] { |
229 |
| - #[path = "wasm32_stdweb.rs"] mod imp; |
230 |
| - } else { |
231 |
| - #[path = "dummy.rs"] mod imp; |
232 |
| - } |
233 |
| - } |
234 |
| - } else { |
| 238 | + // the following two branches are intended only for `wasm32-unknown-unknown` |
| 239 | + // target and may not work or work inefficiently on targets which may be |
| 240 | + // added in future |
| 241 | + } else if #[cfg(all(target_arch = "wasm32", feature = "wasm-bindgen"))] { |
| 242 | + #[path = "wasm32_bindgen.rs"] mod imp; |
| 243 | + } else if #[cfg(all(target_arch = "wasm32", feature = "stdweb"))] { |
| 244 | + #[path = "wasm32_stdweb.rs"] mod imp; |
| 245 | + } else if #[cfg(feature = "dummy")] { |
235 | 246 | #[path = "dummy.rs"] mod imp;
|
| 247 | + } else { |
| 248 | + compile_error!("\ |
| 249 | + target is not supported, for more information see: \ |
| 250 | + https://docs.rs/getrandom/#unsupported-targets\ |
| 251 | + "); |
236 | 252 | }
|
237 | 253 | }
|
238 | 254 |
|
|
0 commit comments