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(mac): sign staged release sidecars

Louis Beaumont547d5924923a
diff --git a/apps/screenpipe-app-tauri/src-tauri/build.rs b/apps/screenpipe-app-tauri/src-tauri/build.rs
index 0cb1b3e31..e2d09618b 100644
--- a/apps/screenpipe-app-tauri/src-tauri/build.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/build.rs
@@ -603,6 +603,8 @@ fn stage_mlx_metallib() {
size / 1_000_000
);
}
+
+ sign_macos_sidecar_if_needed(&metallib);
}
/// Ensure mlx.metallib exists so Tauri doesn't fail on the bundle.macOS.files entry.
@@ -611,9 +613,10 @@ fn stage_mlx_metallib() {
fn stage_mlx_metallib() {
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
let metallib = std::path::Path::new(&manifest_dir).join("mlx.metallib");
- if !metallib.exists() {
- let _ = std::fs::write(&metallib, b"");
- }
+ // Truncate any cached real metallib from a previous arm64 build. The
+ // non-arm64 bundle entry is only a placeholder so Tauri's macOS.files entry
+ // resolves; stale nested code in Contents/MacOS breaks app signing.
+ let _ = std::fs::write(&metallib, b"");
}
/// Stage libonnxruntime.dylib for x86_64 Intel builds. ort `load-dynamic` resolves
@@ -668,11 +671,69 @@ fn stage_libonnxruntime_dylib() {
}
}
}
- } else if !dylib.exists() {
+ sign_macos_sidecar_if_needed(&dylib);
+ } else {
+ // Truncate any cached real dylib from a previous x86_64 build. The
+ // non-x86_64 bundle entry is only a placeholder so Tauri's macOS.files
+ // entry resolves; stale nested code in Contents/MacOS breaks app signing.
let _ = std::fs::write(&dylib, b"");
}
}
+#[cfg(target_os = "macos")]
+fn sign_macos_sidecar_if_needed(path: &std::path::Path) {
+ let is_release = std::env::var("PROFILE").as_deref() == Ok("release");
+ if !is_release {
+ return;
+ }
+
+ let size = std::fs::metadata(path).map(|m| m.len()).unwrap_or(0);
+ if size == 0 {
+ return;
+ }
+
+ let Ok(identity) = std::env::var("APPLE_SIGNING_IDENTITY") else {
+ println!(
+ "cargo:warning=macos-sidecar-sign: APPLE_SIGNING_IDENTITY missing; Tauri app signing may reject {}",
+ path.display()
+ );
+ return;
+ };
+
+ let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
+ let entitlements = std::path::Path::new(&manifest_dir).join("entitlements.plist");
+ let status = std::process::Command::new("codesign")
+ .arg("--force")
+ .arg("--sign")
+ .arg(identity)
+ .arg("--options")
+ .arg("runtime")
+ .arg("--timestamp")
+ .arg("--entitlements")
+ .arg(&entitlements)
+ .arg(path)
+ .status();
+
+ match status {
+ Ok(status) if status.success() => {
+ println!(
+ "cargo:warning=macos-sidecar-sign: signed {}",
+ path.file_name().and_then(|n| n.to_str()).unwrap_or("sidecar")
+ );
+ }
+ Ok(status) => panic!(
+ "codesign failed for staged macOS sidecar {} with status {}",
+ path.display(),
+ status
+ ),
+ Err(err) => panic!(
+ "failed to run codesign for staged macOS sidecar {}: {}",
+ path.display(),
+ err
+ ),
+ }
+}
+
#[cfg(target_os = "macos")]
fn download_homebrew_onnxruntime_dylib(dst: &std::path::Path) -> Result<u64, String> {
use std::path::PathBuf;
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/apps/screenpipe-app-tauri/src-tauri/src/main.rs
index 1363bd7af..166a83337 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/main.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/main.rs
@@ -1128,9 +1128,10 @@ async fn main() {
env::set_var("TESSDATA_PREFIX", tessdata_path);
}
- // mlx.metallib and libonnxruntime.dylib are placed at Contents/MacOS/ at
- // build time via bundle.macOS.files (see build.rs stage_macos_sidecar_libs),
- // then signed as part of the normal codesign pass.
+ // mlx.metallib and libonnxruntime.dylib are staged at build time
+ // for bundle.macOS.files (see build.rs stage_macos_sidecar_libs).
+ // Real nested sidecars are pre-signed before Tauri copies them into
+ // Contents/MacOS; unused per-arch placeholders are truncated empty.
//
// Previously this block created a symlink at Contents/MacOS/mlx.metallib
// pointing at Contents/Resources/mlx.metallib on first launch. Apple