-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
36 lines (30 loc) · 970 Bytes
/
build.rs
File metadata and controls
36 lines (30 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
fn main() {
println!("cargo::rerun-if-env-changed=MACOSX_DEPLOYMENT_TARGET");
println!("cargo::rustc-check-cfg=cfg(HAS_LIQUID_GLASS_WINDOW)");
let macos_version = get_macos_version();
if macos_version >= 26 {
println!("cargo::rustc-cfg=HAS_LIQUID_GLASS_WINDOW");
}
}
fn get_macos_version() -> u32 {
if let Some(v) = parse_version(&std::env::var("MACOSX_DEPLOYMENT_TARGET").ok()) {
return v;
}
#[cfg(target_os = "macos")]
if let Some(v) = infer_macos_version() {
return v;
}
0
}
fn parse_version(version: &Option<String>) -> Option<u32> {
version.as_ref()?.split('.').next()?.parse().ok()
}
#[cfg(target_os = "macos")]
fn infer_macos_version() -> Option<u32> {
let output = std::process::Command::new("sw_vers")
.arg("-productVersion")
.output()
.ok()?;
let version = String::from_utf8(output.stdout).ok()?;
version.trim().split('.').next()?.parse().ok()
}