Skip to content

Commit fb606a6

Browse files
committed
review feedback
1 parent b7384b7 commit fb606a6

5 files changed

Lines changed: 15 additions & 21 deletions

File tree

.github/workflows/build.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,7 @@ jobs:
274274
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="custom"
275275
run: cargo build --target riscv32i-unknown-none-elf
276276

277-
278-
runtime-error:
277+
unsupported:
279278
name: Runtime error
280279
runs-on: ubuntu-24.04
281280
steps:
@@ -285,5 +284,5 @@ jobs:
285284
targets: wasm32-unknown-unknown
286285
- uses: Swatinem/rust-cache@v2
287286
- env:
288-
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="runtime_error"
287+
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="unsupported"
289288
run: cargo build --target wasm32-unknown-unknown

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ wasm-bindgen-test = "0.3"
8383
[lints.rust.unexpected_cfgs]
8484
level = "warn"
8585
check-cfg = [
86-
'cfg(getrandom_backend, values("custom", "efi_rng", "rdrand", "rndr", "linux_getrandom", "linux_raw", "wasm_js", "runtime_error"))',
86+
'cfg(getrandom_backend, values("custom", "efi_rng", "rdrand", "rndr", "linux_getrandom", "linux_raw", "wasm_js", "unsupported"))',
8787
'cfg(getrandom_msan)',
8888
'cfg(getrandom_windows_legacy)',
8989
'cfg(getrandom_test_linux_fallback)',

README.md

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ of randomness based on their specific needs:
8787
| `wasm_js` | Web Browser, Node.js | `wasm32‑unknown‑unknown`, `wasm32v1-none` | [`Crypto.getRandomValues`]. Requires feature `wasm_js` ([see below](#webassembly-support)).
8888
| `efi_rng` | UEFI | `*-unknown‑uefi` | [`EFI_RNG_PROTOCOL`] with `EFI_RNG_ALGORITHM_RAW` (requires `std` and Nigthly compiler)
8989
| `custom` | All targets | `*` | User-provided custom implementation (see [custom backend])
90-
| `runtime_error` | All targets | `*` | Errors when providing randomness. Useful when only needing this crate to compile in wasm32, but it's not actually used.
90+
| `unsupported` | All targets | `*` | Always returns `Err(Error::UNSUPPORTED)` (see [unsupported backend])
9191

9292
Opt-in backends can be enabled using the `getrandom_backend` configuration flag.
9393
The flag can be set either by specifying the `rustflags` field in [`.cargo/config.toml`]:
@@ -204,20 +204,14 @@ unsafe extern "Rust" fn __getrandom_v03_custom(
204204
}
205205
```
206206

207-
If you are confident that `getrandom` is not used in your project, but
208-
it gets pulled nevertheless by one of your dependencies, then you can
209-
use the following custom backend, which always returns the "unsupported" error:
210-
```rust
211-
use getrandom::Error;
207+
### Unsupported backend
212208

213-
#[no_mangle]
214-
unsafe extern "Rust" fn __getrandom_v03_custom(
215-
dest: *mut u8,
216-
len: usize,
217-
) -> Result<(), Error> {
218-
Err(Error::UNSUPPORTED)
219-
}
220-
```
209+
In some rare scenarios you might be compiling this crate in a constrained
210+
environment (ex. `wasm32-unknown-unknown`), but this crate's functionality
211+
is not actually used by your code. If you are confident that `getrandom` is
212+
not used in your project, but it gets pulled nevertheless by one of your
213+
dependencies, then you can enable the `unsupported` backend, which always
214+
returns `Err(Error::UNSUPPORTED)`.
221215

222216
### Platform Support
223217

@@ -374,6 +368,7 @@ dual licensed as above, without any additional terms or conditions.
374368
[`get-random-u64`]: https://github.com/WebAssembly/WASI/blob/v0.2.1/wasip2/random/random.wit#L23-L28
375369
[configuration flags]: #configuration-flags
376370
[custom backend]: #custom-backend
371+
[unsupported backend]: #unsupported-backend
377372
[`wasm-bindgen`]: https://github.com/rustwasm/wasm-bindgen
378373
[`module`]: https://rustwasm.github.io/wasm-bindgen/reference/attributes/on-js-imports/module.html
379374
[`sys_read_entropy`]: https://github.com/hermit-os/kernel/blob/315f58ff5efc81d9bf0618af85a59963ff55f8b1/src/syscalls/entropy.rs#L47-L55

src/backends.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ cfg_if! {
3838
));
3939
}
4040
}
41-
} else if #[cfg(getrandom_backend = "runtime_error")] {
42-
mod runtime_error;
43-
pub use runtime_error::*;
41+
} else if #[cfg(getrandom_backend = "unsupported")] {
42+
mod unsupported;
43+
pub use unsupported::*;
4444
} else if #[cfg(all(target_os = "linux", target_env = ""))] {
4545
mod linux_raw;
4646
pub use linux_raw::*;

0 commit comments

Comments
 (0)