Skip to content

Commit

Permalink
Run version check only for windows targets
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov committed Feb 26, 2025
1 parent d478e53 commit fc48660
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use std::{env, ffi::OsString, process::Command};

/// Minor version of the Rust compiler in which win7 targets were inroduced
const WIN7_INTRODUCED_MINOR_VER: u64 = 78;

/// Tries to get the minor version of use Rust compiler.
///
/// If it fails for any reason, returns `None`.
Expand Down Expand Up @@ -45,10 +42,16 @@ fn main() {

// Use `RtlGenRandom` on older compiler versions since win7 targets
// were introduced only in Rust 1.78
let win_legacy = rustc_minor_version()
.map(|ver| ver < WIN7_INTRODUCED_MINOR_VER)
.unwrap_or(false);
if win_legacy {
println!("cargo:rustc-cfg=getrandom_windows_legacy");
let target_family = env::var_os("CARGO_CFG_TARGET_FAMILY").and_then(|f| f.into_string().ok());
if target_family.as_deref() == Some("windows") {
/// Minor version of the Rust compiler in which win7 targets were inroduced
const WIN7_INTRODUCED_MINOR_VER: u64 = 78;

let win_legacy = rustc_minor_version()
.map(|ver| ver < WIN7_INTRODUCED_MINOR_VER)
.unwrap_or(false);
if win_legacy {
println!("cargo:rustc-cfg=getrandom_windows_legacy");
}
}
}

0 comments on commit fc48660

Please sign in to comment.