Skip to content

Commit 3983e0f

Browse files
authored
Add windows_legacy opt-in backend (#724)
Some users may prefer to use the legacy Windows backend (e.g. see #723), so I think it's worth to introduce a documented configuration flag for it and replace the undocumented `getrandom_windows_legacy` flag.
1 parent 3cddf08 commit 3983e0f

File tree

7 files changed

+43
-29
lines changed

7 files changed

+43
-29
lines changed

CHANGELOG.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [0.3.4] - UNRELEASED
88

9-
### Changed
10-
- Relax MSRV for the `linux_raw` opt-in backend on ARM targets [#688]
11-
129
### Added
1310
- `unsupported` opt-in backend [#667]
11+
- `windows_legacy` opt-in backend [#724]
12+
13+
### Changed
14+
- Implement Memory Sanitizer unpoisoning more precisely [#678]
15+
- Relax MSRV for the `linux_raw` opt-in backend on ARM targets [#688]
16+
- Use `getrandom` syscall on all RISC-V Linux targets [#699]
17+
- Replaced `wasi` dependency with `wasip2` [#721]
1418

1519
### Removed
1620
- Unstable `rustc-dep-of-std` crate feature [#694]
1721

1822
[#667]: https://github.com/rust-random/getrandom/pull/667
23+
[#678]: https://github.com/rust-random/getrandom/pull/678
1924
[#688]: https://github.com/rust-random/getrandom/pull/688
2025
[#694]: https://github.com/rust-random/getrandom/pull/694
26+
[#699]: https://github.com/rust-random/getrandom/pull/699
27+
[#721]: https://github.com/rust-random/getrandom/pull/721
28+
[#724]: https://github.com/rust-random/getrandom/pull/724
2129

2230
## [0.3.3] - 2025-05-09
2331

Cargo.lock

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,8 @@ wasm-bindgen-test = "0.3"
7777
[lints.rust.unexpected_cfgs]
7878
level = "warn"
7979
check-cfg = [
80-
'cfg(getrandom_backend, values("custom", "efi_rng", "rdrand", "rndr", "linux_getrandom", "linux_raw", "wasm_js", "unsupported"))',
80+
'cfg(getrandom_backend, values("custom", "efi_rng", "rdrand", "rndr", "linux_getrandom", "linux_raw", "wasm_js", "windows_legacy", "unsupported"))',
8181
'cfg(getrandom_msan)',
82-
'cfg(getrandom_windows_legacy)',
8382
'cfg(getrandom_test_linux_fallback)',
8483
'cfg(getrandom_test_linux_without_fallback)',
8584
'cfg(getrandom_test_netbsd_fallback)',

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ of randomness based on their specific needs:
8686
| `rndr` | AArch64 | `aarch64-*` | [`RNDR`] register
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 Nightly compiler)
89+
| `windows_legacy` | Windows | `*-windows-*` | [`RtlGenRandom`]
8990
| `custom` | All targets | `*` | User-provided custom implementation (see [custom backend])
9091
| `unsupported` | All targets | `*` | Always returns `Err(Error::UNSUPPORTED)` (see [unsupported backend])
9192

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fn main() {
4848

4949
match rustc_minor_version() {
5050
Some(minor_ver) if minor_ver < WIN7_INTRODUCED_MINOR_VER => {
51-
println!("cargo:rustc-cfg=getrandom_windows_legacy");
51+
println!("cargo:rustc-cfg=getrandom_backend=\"windows_legacy\"");
5252
}
5353
None => println!("cargo:warning=Couldn't detect minor version of the Rust compiler"),
5454
_ => {}

src/backends.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ cfg_if! {
2828
} else if #[cfg(getrandom_backend = "efi_rng")] {
2929
mod efi_rng;
3030
pub use efi_rng::*;
31+
} else if #[cfg(getrandom_backend = "windows_legacy")] {
32+
mod windows_legacy;
33+
pub use windows_legacy::*;
3134
} else if #[cfg(all(getrandom_backend = "wasm_js"))] {
3235
cfg_if! {
3336
if #[cfg(feature = "wasm_js")] {
@@ -173,9 +176,9 @@ cfg_if! {
173176
} else if #[cfg(target_os = "solid_asp3")] {
174177
mod solid;
175178
pub use solid::*;
176-
} else if #[cfg(all(windows, any(target_vendor = "win7", getrandom_windows_legacy)))] {
177-
mod windows7;
178-
pub use windows7::*;
179+
} else if #[cfg(all(windows, target_vendor = "win7"))] {
180+
mod windows_legacy;
181+
pub use windows_legacy::*;
179182
} else if #[cfg(windows)] {
180183
mod windows;
181184
pub use windows::*;

src/backends/windows7.rs renamed to src/backends/windows_legacy.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ use core::{ffi::c_void, mem::MaybeUninit};
1414

1515
pub use crate::util::{inner_u32, inner_u64};
1616

17+
#[cfg(not(windows))]
18+
compile_error!("`windows_legacy` backend can be enabled only for Windows targets!");
19+
1720
// Binding to the Windows.Win32.Security.Authentication.Identity.RtlGenRandom
1821
// API. Don't use windows-targets as it doesn't support Windows 7 targets.
1922
#[link(name = "advapi32")]

0 commit comments

Comments
 (0)