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: weak-link FoundationModels.framework to prevent launch crash on macOS < 26

Louis Beaumont31f374072ff8
diff --git a/crates/screenpipe-apple-intelligence/build.rs b/crates/screenpipe-apple-intelligence/build.rs
index e33017d21..4922198ba 100644
--- a/crates/screenpipe-apple-intelligence/build.rs
+++ b/crates/screenpipe-apple-intelligence/build.rs
@@ -53,7 +53,9 @@ fn main() {
println!("cargo:rustc-link-lib=static=foundation_models_bridge");
// Link required system frameworks and Swift runtime
- println!("cargo:rustc-link-lib=framework=FoundationModels");
+ // Weak-link so the app can launch on macOS versions without FoundationModels.framework
+ // (only available on macOS 26+). The framework is loaded at runtime if present.
+ println!("cargo:rustc-link-arg=-Wl,-weak_framework,FoundationModels");
println!("cargo:rustc-link-lib=framework=Foundation");
// Swift runtime libraries
diff --git a/crates/screenpipe-apple-intelligence/src/engine.rs b/crates/screenpipe-apple-intelligence/src/engine.rs
index fa45547fb..bb09babff 100644
--- a/crates/screenpipe-apple-intelligence/src/engine.rs
+++ b/crates/screenpipe-apple-intelligence/src/engine.rs
@@ -5,6 +5,30 @@ use anyhow::{bail, Result};
use serde::{Deserialize, Serialize};
use std::ffi::{CStr, CString};
+/// Check if the current macOS version supports FoundationModels (macOS 26+).
+/// Returns false on non-macOS or macOS < 26, preventing any FFI calls
+/// into the weak-linked FoundationModels.framework.
+fn is_macos_26_or_later() -> bool {
+ #[cfg(target_os = "macos")]
+ {
+ use std::process::Command;
+ if let Ok(output) = Command::new("sw_vers").arg("-productVersion").output() {
+ if let Ok(version) = String::from_utf8(output.stdout) {
+ if let Some(major) = version.trim().split('.').next() {
+ if let Ok(major_num) = major.parse::<u32>() {
+ return major_num >= 26;
+ }
+ }
+ }
+ }
+ false
+ }
+ #[cfg(not(target_os = "macos"))]
+ {
+ false
+ }
+}
+
// MARK: - Types
/// Availability status of Foundation Models on this system.
@@ -82,6 +106,9 @@ unsafe fn extract_and_free(ptr: *mut std::os::raw::c_char) -> Option<String> {
/// Check if Apple Foundation Models is available on this system.
pub fn check_availability() -> Availability {
+ if !is_macos_26_or_later() {
+ return Availability::DeviceNotEligible;
+ }
unsafe {
let mut reason_ptr: *mut std::os::raw::c_char = std::ptr::null_mut();
let status = ffi::fm_check_availability(&mut reason_ptr);
@@ -102,6 +129,9 @@ pub fn check_availability() -> Availability {
/// Loads model assets into memory ahead of time to reduce latency
/// on the first request. Blocking call, may take a few hundred ms.
pub fn prewarm() -> Result<()> {
+ if !is_macos_26_or_later() {
+ bail!("Foundation Models requires macOS 26+");
+ }
let status = unsafe { ffi::fm_prewarm() };
if status != 0 {
bail!("Foundation Models prewarm failed (model not available)");
@@ -111,6 +141,9 @@ pub fn prewarm() -> Result<()> {
/// Get the list of languages supported by the on-device model.
pub fn supported_languages() -> Result<Vec<String>> {
+ if !is_macos_26_or_later() {
+ return Ok(vec![]);
+ }
unsafe {
let ptr = ffi::fm_supported_languages();
let json_str = extract_and_free(ptr).unwrap_or_else(|| "[]".to_string());
@@ -128,6 +161,9 @@ pub fn supported_languages() -> Result<Vec<String>> {
/// # Returns
/// A `GenerationResult` containing the response text and performance metrics.
pub fn generate_text(instructions: Option<&str>, prompt: &str) -> Result<GenerationResult> {
+ if !is_macos_26_or_later() {
+ bail!("Foundation Models requires macOS 26+");
+ }
let prompt_c = CString::new(prompt)?;
let instructions_c = instructions.map(|s| CString::new(s)).transpose()?;
@@ -181,6 +217,9 @@ pub fn generate_json(
prompt: &str,
json_schema: &str,
) -> Result<JsonGenerationResult> {
+ if !is_macos_26_or_later() {
+ bail!("Foundation Models requires macOS 26+");
+ }
let prompt_c = CString::new(prompt)?;
let schema_c = CString::new(json_schema)?;
let instructions_c = instructions.map(|s| CString::new(s)).transpose()?;