Repository: zng-ui/zng (language: rust)

Issue:
View-prebuilt does not work in old macOS
On a macOS 12 run:

```console
cargo do run animation
```

Panics with:

```
cannot load 'zv.0.11.3.hash.dylib' (load command 0x80000034 is unknown)
```


Discussion / hints:

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 99d0b3f04..59c77ada1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,6 @@
 # Unreleased
 
+* Define oldest supported macOS prebuilt. Only supported >=11, now this is documented.
 * Fix `"view_prebuilt"` linking on macOS.
 * Fix panic on old macOS (<11). Color scheme and accent is only supported >=11.
 * Fix `cargo zng fmt` of widgets with multi value property assigns.
diff --git a/README.md b/README.md
index 1188642b9..ac3b0bf10 100644
--- a/README.md
+++ b/README.md
@@ -103,7 +103,8 @@ The Cargo features of each crate are documented in the README file for that crat
 
 ##### On macOS:
 
-* No special requirements, we assume XCode 14 or newer and may depend on it in future releases.
+* TO build with `"view_prebuilt"` feature:
+    - macOS 11 or newer.
 
 ##### For Android:
 
diff --git a/crates/zng-view-prebuilt/build.rs b/crates/zng-view-prebuilt/build.rs
index de7bb9ba4..2ff4d54a9 100644
--- a/crates/zng-view-prebuilt/build.rs
+++ b/crates/zng-view-prebuilt/build.rs
@@ -46,6 +46,11 @@ fn main() {
         if !lib.exists() {
             let lib_tar = out_dir.join(format!("{file}.tar.gz"));
 
+            #[cfg(target_os = "macos")]
+            if macos_major_version() < 11 {
+                panic!("prebuilt download is only supported on macOS 11 or newer");
+            }
+
             let url = format!("https://github.com/zng-ui/zng/releases/download/v{version}/{file}.tar.gz");
             let r = std::process::Command::new("curl")
                 .arg("--location")
@@ -123,3 +128,29 @@ fn main() {
         panic!("view prebuilt not embedded, missing '{file}'");
     }
 }
+
+#[cfg(target_os = "macos")]
+fn macos_major_version() -> u32 {
+    let output = match std::process::Command::new("sw_vers").arg("-productVersion").output() {
+        Ok(o) => o,
+        Err(e) => {
+            eprintln!("cannot retrieve macos version, {e}");
+            return 0;
+        }
+    };
+
+    if output.status.success() {
+        let ver = String::from_utf8_lossy(&output.stdout);
+        match ver.trim().split('.').next().unwrap_or("").parse() {
+            Ok(v) => v,
+            Err(_) => {
+                eprintln!("cannot parse macos version {ver:?}");
+                0
+            }
+        }
+    } else {
+        let err = String::from_utf8_lossy(&output.stderr);
+        eprintln!("cannot retrieve macos version, {}", err.trim());
+        0
+    }
+}


Test patch: