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
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix(mac): let tauri sign mlx metallib sidecar
Louis Beaumontd1ddc6f62825
diff --git a/.github/workflows/release-app.yml b/.github/workflows/release-app.ymlindex 99b45ffce..6953cc288 100644--- a/.github/workflows/release-app.yml+++ b/.github/workflows/release-app.yml@@ -690,7 +690,7 @@ jobs:echo "args=$ARGS" >> $GITHUB_OUTPUTecho "Final tauri args: $ARGS"- - name: Select macOS sidecar bundle entries+ - name: Configure macOS sidecar bundle entriesif: matrix.os_type == 'macos'shell: bashrun: |@@ -703,8 +703,11 @@ jobs:const config = JSON.parse(fs.readFileSync(path, "utf8"));config.bundle ??= {};config.bundle.macOS ??= {};+ config.bundle.externalBin = [...new Set(config.bundle.externalBin ?? [])]+ .filter((entry) => entry !== "mlx.metallib");if (target === "aarch64-apple-darwin") {- config.bundle.macOS.files = { "MacOS/mlx.metallib": "mlx.metallib" };+ config.bundle.macOS.files = {};+ config.bundle.externalBin.push("mlx.metallib");} else if (target === "x86_64-apple-darwin") {config.bundle.macOS.files = {"MacOS/libonnxruntime.dylib": "libonnxruntime.dylib",@@ -713,7 +716,7 @@ jobs:throw new Error(`unknown macOS release target: ${target}`);}fs.writeFileSync(path, `${JSON.stringify(config, null, 2)}\n`);- console.log(`macOS bundle sidecars selected for ${target}`);+ console.log(`macOS bundle sidecars configured for ${target}`);NODEenv:TARGET: ${{ matrix.target }}@@ -1097,8 +1100,8 @@ jobs:# build-keychain dance (the `errSecInternalComponent` class — see# the keychain setup above) only surfaces as a notarization failure# much later in the workflow.- # Covers the single Tauri codesign pass for the architecture-specific- # sidecar staged into Contents/MacOS/ via bundle.macOS.files.+ # Covers the single Tauri codesign pass for architecture-specific+ # sidecars staged into Contents/MacOS/ via externalBin/macOS.files.if: matrix.os_type == 'macos'shell: bashrun: |diff --git a/apps/screenpipe-app-tauri/scripts/pre_build.js b/apps/screenpipe-app-tauri/scripts/pre_build.jsindex 672271b77..0be058e57 100644--- a/apps/screenpipe-app-tauri/scripts/pre_build.js+++ b/apps/screenpipe-app-tauri/scripts/pre_build.js@@ -78,6 +78,7 @@ const config = {ffprobeUrlArm: 'https://www.osxexperts.net/ffprobe71arm.zip',ffmpegUrlx86_64: 'https://www.osxexperts.net/ffmpeg80intel.zip',ffprobeUrlx86_64: 'https://www.osxexperts.net/ffprobe71intel.zip',+ mlxMetallibUrl: 'https://github.com/screenpipe/screenpipe/releases/download/mlx-metallib-v0.2.0/mlx.metallib',},}@@ -285,6 +286,48 @@ async function copyFile(src, dest) {await fs.chmod(dest, 0o755); // ensure the binary is executable}+async function ensureMacosMlxMetallibSidecar() {+ const releaseTarget = process.env.SCREENPIPE_RELEASE_TARGET;+ if (releaseTarget !== 'aarch64-apple-darwin') return;++ const minSize = 1_000_000; // real metallib is ~84MB+ const baseMetallib = path.join(cwd, 'mlx.metallib');+ const sidecarMetallib = path.join(cwd, 'mlx.metallib-aarch64-apple-darwin');++ const fileSize = async (filePath) => {+ try {+ return (await fs.stat(filePath)).size;+ } catch {+ return 0;+ }+ };++ if ((await fileSize(sidecarMetallib)) >= minSize) {+ if ((await fileSize(baseMetallib)) < minSize) {+ await fs.copyFile(sidecarMetallib, baseMetallib);+ }+ console.log('mlx.metallib sidecar already exists for tauri externalBin.');+ return;+ }++ if ((await fileSize(baseMetallib)) >= minSize) {+ await fs.copyFile(baseMetallib, sidecarMetallib);+ await fs.chmod(sidecarMetallib, 0o755);+ console.log('copied mlx.metallib to aarch64 tauri externalBin sidecar.');+ return;+ }++ console.log('downloading mlx.metallib for macOS aarch64 tauri externalBin...');+ await downloadFile(config.macos.mlxMetallibUrl, sidecarMetallib, { retries: 10, timeoutMs: 900000 });+ await fs.chmod(sidecarMetallib, 0o755);+ await fs.copyFile(sidecarMetallib, baseMetallib);+ const size = await fileSize(sidecarMetallib);+ if (size < minSize) {+ throw new Error(`downloaded mlx.metallib sidecar is too small: ${size} bytes`);+ }+ console.log(`mlx.metallib sidecar installed to ${sidecarMetallib}`);+}+async function linkSystemBinary(binaryName, destination) {try {const source = await findOnPath(binaryName);@@ -433,6 +476,14 @@ async function verifyMacosSidecarsSelfContained() {if (sidecars.length === 0) return;console.log('verifying macOS sidecars are self-contained...');for (const bin of sidecars) {+ if (/^mlx\.metallib-(aarch64|x86_64)-apple-darwin$/.test(bin)) {+ const size = (await fs.stat(bin)).size;+ if (size < 1_000_000) {+ throw new Error(`sidecar ${bin} is too small to be the real MLX metallib: ${size} bytes`);+ }+ console.log(` ok: ${bin} (${Math.round(size / 1_000_000)} MB metallib)`);+ continue;+ }const expectedArch = bin.endsWith('-aarch64-apple-darwin') ? 'arm64' : 'x86_64';const fileOut = (await runWithTimeout(['file', bin], { label: `file ${bin}` })).trim();// `file` on a fat binary lists every slice; on a thin binary, just one.@@ -854,6 +905,8 @@ if (platform == 'macos') {await $`rm -rf ffprobe-x86_64`;}+ await ensureMacosMlxMetallibSidecar();+console.log('FFMPEG and FFPROBE checks completed');console.log('Moved and renamed ffmpeg binary for externalBin');diff --git a/apps/screenpipe-app-tauri/src-tauri/build.rs b/apps/screenpipe-app-tauri/src-tauri/build.rsindex ed82c70a2..763403833 100644--- a/apps/screenpipe-app-tauri/src-tauri/build.rs+++ b/apps/screenpipe-app-tauri/src-tauri/build.rs@@ -341,9 +341,9 @@ fn main() {// Build SwiftUI shortcut reminderbuild_shortcut_reminder();- // Copy mlx.metallib and libonnxruntime.dylib to src-tauri/ for bundle.macOS.files- // (Contents/MacOS/). MLX metallib must be next to the binary; onnx dylib- // is loaded via ort load-dynamic on x86_64.+ // Stage macOS runtime sidecars into src-tauri/. Release builds bundle+ // mlx.metallib as a Tauri externalBin on arm64 so Tauri signs it, and+ // copy libonnxruntime.dylib via macOS.files on x86_64 for ort load-dynamic.stage_macos_sidecar_libs();// Stage permission-flow's resource bundle for Tauri to pick up.@@ -554,8 +554,8 @@ int shortcut_is_available(void) { return 0; }println!("cargo:rustc-link-lib=static=shortcut_reminder");}-/// Stage mlx.metallib and libonnxruntime.dylib into `src-tauri/` so Tauri's-/// `bundle.macOS.files` can copy them into `Contents/MacOS/` before codesign.+/// Stage mlx.metallib and libonnxruntime.dylib into `src-tauri/` for macOS+/// release bundling./// MLX needs metallib next to the binary at runtime (parakeet-mlx crashes without it)./// x86_64 Intel builds need libonnxruntime.dylib colocated for ort `load-dynamic`./// Same build-time staging pattern as `copy_permission_flow_bundle` (#3990).@@ -565,10 +565,10 @@ fn stage_macos_sidecar_libs() {stage_libonnxruntime_dylib();}-/// Copy mlx.metallib to a known location so Tauri can bundle it via-/// bundle.macOS.files on aarch64 macOS release builds. MLX compiles Metal-/// shaders into this file during mlx-sys build. Without it, parakeet-mlx-/// crashes with "Failed to load the default metallib".+/// Copy mlx.metallib to a known location so release packaging can bundle it as+/// a Tauri externalBin on aarch64 macOS builds. MLX compiles Metal shaders into+/// this file during mlx-sys build. Without it, parakeet-mlx crashes with+/// "Failed to load the default metallib".#[cfg(target_os = "macos")]fn stage_mlx_metallib() {let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();@@ -588,8 +588,8 @@ fn stage_mlx_metallib() {if needs_download {// Download mlx.metallib (pre-compiled MLX Metal shaders) for parakeet-mlx.- // MLX needs this file next to the binary at runtime. Tauri copies it into- // Contents/MacOS/ via bundle.macOS.files (see tauri.macos.conf.json).+ // MLX needs this file next to the binary at runtime. The release+ // workflow exposes the target-suffixed externalBin copy to Tauri.println!("cargo:warning=mlx-metallib: downloading from GitHub releases...");let url ="https://github.com/screenpipe/screenpipe/releases/download/mlx-metallib-v0.2.0/mlx.metallib";diff --git a/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/apps/screenpipe-app-tauri/src-tauri/src/main.rsindex 166a83337..f274a781c 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/main.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/main.rs@@ -1129,9 +1129,9 @@ async fn main() {}// 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.+ // for macOS release bundling (see build.rs stage_macos_sidecar_libs).+ // arm64 bundles mlx.metallib as a Tauri externalBin so Tauri signs it;+ // x86_64 copies libonnxruntime.dylib via macOS.files.//// Previously this block created a symlink at Contents/MacOS/mlx.metallib// pointing at Contents/Resources/mlx.metallib on first launch. Apple