From fc4866050292139dbfb94f457a63d29c2e8c54f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20=5BArtyom=20Pavlov=5D?= Date: Wed, 26 Feb 2025 17:03:09 +0300 Subject: [PATCH] Run version check only for windows targets --- build.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/build.rs b/build.rs index b93deed4..755c35c3 100644 --- a/build.rs +++ b/build.rs @@ -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`. @@ -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"); + } } }