fortrangoingonforty/afs-as / cea2569

Browse files

Match host default build version

Authored by espadonne
SHA
cea2569cfb80705f3eaeceadd8968aa031c22813
Parents
30edca9
Tree
1f0bcba

1 changed file

StatusFile+-
M src/macho.rs 24 1
src/macho.rsmodified
@@ -6,6 +6,8 @@
66
 
77
 use std::collections::BTreeMap;
88
 use std::io::{self, Write};
9
+use std::process::Command;
10
+use std::sync::OnceLock;
911
 
1012
 // ---- Mach-O Constants ----
1113
 
@@ -83,12 +85,33 @@ impl Default for BuildVersion {
8385
     fn default() -> Self {
8486
         Self {
8587
             platform: PLATFORM_MACOS,
86
-            minos: pack_version(15, 0, 0),
88
+            minos: default_host_minos(),
8789
             sdk: 0,
8890
         }
8991
     }
9092
 }
9193
 
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
+
92115
 /// A symbol in the object file.
93116
 #[derive(Debug, Clone)]
94117
 pub struct Symbol {