Match host default build version
- SHA
cea2569cfb80705f3eaeceadd8968aa031c22813- Parents
-
30edca9 - Tree
1f0bcba
cea2569
cea2569cfb80705f3eaeceadd8968aa031c2281330edca9
1f0bcba| Status | File | + | - |
|---|---|---|---|
| M |
src/macho.rs
|
24 | 1 |
src/macho.rsmodified@@ -6,6 +6,8 @@ | ||
| 6 | 6 | |
| 7 | 7 | use std::collections::BTreeMap; |
| 8 | 8 | use std::io::{self, Write}; |
| 9 | +use std::process::Command; | |
| 10 | +use std::sync::OnceLock; | |
| 9 | 11 | |
| 10 | 12 | // ---- Mach-O Constants ---- |
| 11 | 13 | |
@@ -83,12 +85,33 @@ impl Default for BuildVersion { | ||
| 83 | 85 | fn default() -> Self { |
| 84 | 86 | Self { |
| 85 | 87 | platform: PLATFORM_MACOS, |
| 86 | - minos: pack_version(15, 0, 0), | |
| 88 | + minos: default_host_minos(), | |
| 87 | 89 | sdk: 0, |
| 88 | 90 | } |
| 89 | 91 | } |
| 90 | 92 | } |
| 91 | 93 | |
| 94 | +fn default_host_minos() -> u32 { | |
| 95 | + static HOST_MINOS: OnceLock<u32> = OnceLock::new(); | |
| 96 | + *HOST_MINOS.get_or_init(|| { | |
| 97 | + Command::new("sw_vers") | |
| 98 | + .arg("-productVersion") | |
| 99 | + .output() | |
| 100 | + .ok() | |
| 101 | + .and_then(|out| out.status.success().then_some(out.stdout)) | |
| 102 | + .and_then(|stdout| { | |
| 103 | + let version = String::from_utf8(stdout).ok()?; | |
| 104 | + version | |
| 105 | + .trim() | |
| 106 | + .split('.') | |
| 107 | + .next() | |
| 108 | + .and_then(|major| major.parse::<u32>().ok()) | |
| 109 | + }) | |
| 110 | + .map(|major| pack_version(major, 0, 0)) | |
| 111 | + .unwrap_or_else(|| pack_version(15, 0, 0)) | |
| 112 | + }) | |
| 113 | +} | |
| 114 | + | |
| 92 | 115 | /// A symbol in the object file. |
| 93 | 116 | #[derive(Debug, Clone)] |
| 94 | 117 | pub struct Symbol { |