Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix: conditionally weak-link FoundationModels only when SDK has it

Louis Beaumonta256f95d82d9
diff --git a/apps/screenpipe-app-tauri/src-tauri/build.rs b/apps/screenpipe-app-tauri/src-tauri/build.rs
index fe097977f..511e539a5 100644
--- a/apps/screenpipe-app-tauri/src-tauri/build.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/build.rs
@@ -1,16 +1,39 @@
+#[cfg(target_os = "macos")]
+fn has_foundation_models_sdk() -> bool {
+ let sdk_path = std::process::Command::new("xcrun")
+ .args(["--sdk", "macosx", "--show-sdk-path"])
+ .output()
+ .ok()
+ .and_then(|o| String::from_utf8(o.stdout).ok())
+ .unwrap_or_default();
+ let sdk_path = sdk_path.trim();
+
+ let settings = format!("{}/SDKSettings.json", sdk_path);
+ if let Ok(contents) = std::fs::read_to_string(&settings) {
+ if contents.contains("\"26.") || contents.contains("\"27.") || contents.contains("\"28.") {
+ return true;
+ }
+ }
+ std::path::Path::new(&format!(
+ "{}/System/Library/Frameworks/FoundationModels.framework",
+ sdk_path
+ ))
+ .exists()
+}
+
fn main() {
#[cfg(target_os = "macos")]
{
println!("cargo:rustc-link-lib=framework=AVFoundation");
- // Weak-link FoundationModels so the app launches on macOS < 26.
- // The Swift static library (from screenpipe-apple-intelligence) creates a strong
- // LC_LOAD_DYLIB reference to FoundationModels.framework. Passing -weak_framework
- // here in the *binary* crate's build.rs overrides it to LC_LOAD_WEAK_DYLIB,
- // so DYLD skips the framework instead of crashing when it doesn't exist.
- // Note: cargo:rustc-link-arg in a *library* crate's build.rs does NOT propagate
- // to the final binary — it must be set here.
- println!("cargo:rustc-link-arg=-Wl,-weak_framework,FoundationModels");
+ // Only weak-link FoundationModels if the SDK actually has it.
+ // On macOS < 26 SDKs the framework doesn't exist and the linker fails
+ // even with -weak_framework (can't weak-link what doesn't exist).
+ // When the SDK does have it, weak-linking converts LC_LOAD_DYLIB to
+ // LC_LOAD_WEAK_DYLIB so the app launches on older macOS without crashing.
+ if has_foundation_models_sdk() {
+ println!("cargo:rustc-link-arg=-Wl,-weak_framework,FoundationModels");
+ }
// Swift runtime rpaths — needed for apple-intelligence feature
// (libswift_Concurrency.dylib etc. live in these directories)
diff --git a/crates/screenpipe-server/build.rs b/crates/screenpipe-server/build.rs
index ddff6929a..ca937b49d 100644
--- a/crates/screenpipe-server/build.rs
+++ b/crates/screenpipe-server/build.rs
@@ -3,6 +3,31 @@ fn link_onnx() {
println!("cargo:rustc-link-search=native=../../apps/screenpipe-app-tauri/src-tauri/onnxruntime-win-x64-gpu-1.19.2/lib");
}
+#[cfg(target_os = "macos")]
+fn has_foundation_models_sdk() -> bool {
+ let sdk_path = std::process::Command::new("xcrun")
+ .args(["--sdk", "macosx", "--show-sdk-path"])
+ .output()
+ .ok()
+ .and_then(|o| String::from_utf8(o.stdout).ok())
+ .unwrap_or_default();
+ let sdk_path = sdk_path.trim();
+
+ // Check SDKSettings.json for version 26+
+ let settings = format!("{}/SDKSettings.json", sdk_path);
+ if let Ok(contents) = std::fs::read_to_string(&settings) {
+ if contents.contains("\"26.") || contents.contains("\"27.") || contents.contains("\"28.") {
+ return true;
+ }
+ }
+ // Fallback: check if framework exists in SDK
+ std::path::Path::new(&format!(
+ "{}/System/Library/Frameworks/FoundationModels.framework",
+ sdk_path
+ ))
+ .exists()
+}
+
fn main() {
#[cfg(target_os = "windows")]
{
@@ -11,9 +36,12 @@ fn main() {
#[cfg(target_os = "macos")]
{
- // Weak-link FoundationModels so the CLI launches on macOS < 26.
- // See apps/screenpipe-app-tauri/src-tauri/build.rs for detailed explanation.
- println!("cargo:rustc-link-arg=-Wl,-weak_framework,FoundationModels");
+ // Only weak-link FoundationModels if the SDK actually has it.
+ // On macOS < 26 SDKs the framework doesn't exist and the linker fails
+ // even with -weak_framework (can't weak-link what doesn't exist).
+ if has_foundation_models_sdk() {
+ println!("cargo:rustc-link-arg=-Wl,-weak_framework,FoundationModels");
+ }
println!("cargo:rustc-link-arg=-Wl,-rpath,/usr/lib/swift");
}
}