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

Use build.rs for dylibs (#784)

Neptuneb0f3d181437a
diff --git a/screenpipe-app-tauri/scripts/pre_build.js b/screenpipe-app-tauri/scripts/pre_build.js
index c52418d7c..530f6fd33 100644
--- a/screenpipe-app-tauri/scripts/pre_build.js
+++ b/screenpipe-app-tauri/scripts/pre_build.js
@@ -344,79 +344,6 @@ async function getMostRecentBinaryPath(targetArch, paths) {
}
/* ########## macOS ########## */
if (platform == 'macos') {
-
- const architectures = ['arm64', 'x86_64'];
-
- for (const arch of architectures) {
- if (process.env['SKIP_SCREENPIPE_SETUP']) {
- break;
- }
- console.log(`Setting up screenpipe bin for ${arch}...`);
-
- if (arch === 'arm64') {
- const paths = [
- "../../target/aarch64-apple-darwin/release/screenpipe",
- "../../target/release/screenpipe"
- ];
-
- const mostRecentPath = await getMostRecentBinaryPath('arm64', paths);
- if (mostRecentPath) {
- await $`cp ${mostRecentPath} screenpipe-aarch64-apple-darwin`;
- console.log(`Copied most recent arm64 screenpipe binary from ${mostRecentPath}`);
- } else {
- console.error("No suitable arm64 screenpipe binary found");
- }
-
- try {
- // if the binary exists, hard code the fucking dylib
- if (await fs.exists('screenpipe-aarch64-apple-darwin') && !isDevMode) {
- await $`install_name_tool -change screenpipe-vision/lib/libscreenpipe_arm64.dylib @rpath/../Frameworks/libscreenpipe_arm64.dylib ./screenpipe-aarch64-apple-darwin`
- await $`install_name_tool -change screenpipe-vision/lib/libscreenpipe.dylib @rpath/../Frameworks/libscreenpipe.dylib ./screenpipe-aarch64-apple-darwin`
- console.log(`hard coded the dylib`);
- } else if (await fs.exists('screenpipe-aarch64-apple-darwin') && isDevMode) {
- await $`install_name_tool -change screenpipe-vision/lib/libscreenpipe_arm64.dylib @executable_path/../Frameworks/libscreenpipe_arm64.dylib ./screenpipe-aarch64-apple-darwin`
- await $`install_name_tool -change screenpipe-vision/lib/libscreenpipe.dylib @executable_path/../Frameworks/libscreenpipe.dylib ./screenpipe-aarch64-apple-darwin`
- await $`install_name_tool -add_rpath @executable_path/../Frameworks ./screenpipe-aarch64-apple-darwin`
- console.log(`Updated dylib paths for arm64 in dev mode`);
- }
- } catch (error) {
- console.error('Error updating dylib paths:', error);
- }
-
-
- } else if (arch === 'x86_64') {
- // copy screenpipe binary (more recent one)
- const paths = [
- "../../target/x86_64-apple-darwin/release/screenpipe",
- "../../target/release/screenpipe"
- ];
-
- const mostRecentPath = await getMostRecentBinaryPath('x86_64', paths);
-
- if (mostRecentPath) {
- await $`cp ${mostRecentPath} screenpipe-x86_64-apple-darwin`;
- console.log(`Copied most recent x86_64 screenpipe binary from ${mostRecentPath}`);
- } else {
- console.error("No suitable x86_64 screenpipe binary found");
- }
-
- try {
- // hard code the dylib
- if (await fs.exists('screenpipe-x86_64-apple-darwin') && !isDevMode) {
- await $`install_name_tool -change screenpipe-vision/lib/libscreenpipe_x86_64.dylib @rpath/../Frameworks/libscreenpipe_x86_64.dylib ./screenpipe-x86_64-apple-darwin`
- await $`install_name_tool -change screenpipe-vision/lib/libscreenpipe.dylib @rpath/../Frameworks/libscreenpipe.dylib ./screenpipe-x86_64-apple-darwin`
- console.log(`hard coded the dylib`);
- }
- } catch (error) {
- console.error('Error updating dylib paths:', error);
- }
-
- }
-
- console.log(`screenpipe for ${arch} set up successfully.`);
- }
-
-
// Setup FFMPEG
if (!(await fs.exists(config.ffmpegRealname))) {
await $`wget --no-config -nc ${config.macos.ffmpegUrl} -O ${config.macos.ffmpegName}.tar.xz`
diff --git a/screenpipe-app-tauri/src-tauri/build.rs b/screenpipe-app-tauri/src-tauri/build.rs
index d860e1e6a..2815a23df 100644
--- a/screenpipe-app-tauri/src-tauri/build.rs
+++ b/screenpipe-app-tauri/src-tauri/build.rs
@@ -1,3 +1,38 @@
+#[cfg(target_os = "macos")]
+use std::{fs, process::Command};
+
fn main() {
+ // Copies executables and hardcodes the dylibs
+ #[cfg(target_os = "macos")]
+ {
+ #[cfg(target_arch = "x86_64")]
+ {
+ fs::copy("../../target/x86_64-apple-darwin/release/screenpipe", "screenpipe-x86_64-apple-darwin")?;
+ Command::new("install_name_tool")
+ .args(["-change", "../../screenpipe-vision/lib/libscreenpipe_x86_64.dylib",
+ "@executable_path/../Frameworks/libscreenpipe_x86_64.dylib", "./screenpipe-x86_64-apple-darwin"])
+ .status()
+ .expect("failed to execute process");
+ Command::new("install_name_tool")
+ .args(["-change", "../../screenpipe-vision/lib/libscreenpipe.dylib",
+ "@executable_path/../Frameworks/libscreenpipe.dylib", "./screenpipe-x86_64-apple-darwin"])
+ .status()
+ .expect("failed to execute process");
+ }
+ #[cfg(target_arch = "aarch64")]
+ {
+ fs::copy("../../target/aarch64-apple-darwin/release/screenpipe", "screenpipe-aarch64-apple-darwin")?;
+ Command::new("install_name_tool")
+ .args(["-change", "../../screenpipe-vision/lib/libscreenpipe_arm64.dylib",
+ "@executable_path/../Frameworks/libscreenpipe_arm64.dylib", "./screenpipe-aarch64-apple-darwin"])
+ .status()
+ .expect("failed to execute process");
+ Command::new("install_name_tool")
+ .args(["-change", "../../screenpipe-vision/lib/libscreenpipe.dylib",
+ "@executable_path/../Frameworks/libscreenpipe.dylib", "./screenpipe-aarch64-apple-darwin"])
+ .status()
+ .expect("failed to execute process");
+ }
+ }
tauri_build::build()
}