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

refactor(#772): install bun in build.rs instead of pre_build (#779)

ologbonowiwi8a8cdf96f047
diff --git a/install.ps1 b/install.ps1
index 452d87872..46d26ab0b 100644
--- a/install.ps1
+++ b/install.ps1
@@ -47,6 +47,10 @@ try {
# Cleanup
Remove-Item $tempZip -Force
+ # Install bun
+ Write-Host "installing bun..."
+ powershell -c "irm bun.sh/install.ps1|iex"
+
Write-Host "screenpipe installed successfully! restart your terminal and run 'screenpipe'" -ForegroundColor Green
} catch {
Write-Host "installation failed: $($_.Exception.Message)" -ForegroundColor Red
diff --git a/screenpipe-app-tauri/scripts/pre_build.js b/screenpipe-app-tauri/scripts/pre_build.js
index 530f6fd33..d1b220d5a 100644
--- a/screenpipe-app-tauri/scripts/pre_build.js
+++ b/screenpipe-app-tauri/scripts/pre_build.js
@@ -80,42 +80,6 @@ const exports = {
cmake: 'C:\\Program Files\\CMake\\bin',
}
-// Add this function to check if Bun is installed
-async function isBunInstalled() {
- try {
- await $`bun --version`.quiet();
- return true;
- } catch (error) {
- return false;
- }
-}
-
-// Add this function to install Bun
-async function installBun() {
- if (await isBunInstalled()) {
- console.log('bun is already installed.');
- return;
- }
-
- console.log('installing bun...');
-
- if (platform === 'windows') {
- console.log('attempting to install bun using npm...');
- try {
- await $`npm install -g bun`;
- console.log('bun installed successfully using npm.');
- } catch (error) {
- console.error('failed to install bun:', error);
- console.error('please install bun manually.');
- }
- } else {
- // for macos and linux
- await $`curl -fsSL https://bun.sh/install | bash`;
- }
-
- console.log('bun installation attempt completed.');
-}
-
// Add this function to copy the Bun binary
async function copyBunBinary() {
console.log('checking bun binary for tauri...');
@@ -569,7 +533,6 @@ async function installOllamaSidecar() {
}
// Near the end of the script, call these functions
-await installBun();
await copyBunBinary();
await installOllamaSidecar().catch(console.error);
diff --git a/screenpipe-audio/build.rs b/screenpipe-audio/build.rs
index fe7821d50..7e314676b 100644
--- a/screenpipe-audio/build.rs
+++ b/screenpipe-audio/build.rs
@@ -1,29 +1,91 @@
#[cfg(target_os = "windows")]
use std::{env, fs, process::Command};
+use std::{
+ io::Result,
+ process::{Command, Output},
+};
fn main() {
#[cfg(target_os = "windows")]
{
- // Set static CRT for Windows MSVC target
- if env::var("CARGO_CFG_TARGET_ENV").unwrap_or_default() == "msvc" {
- println!("cargo:rustc-env=KNF_STATIC_CRT=1");
- println!("cargo:rustc-flag=-C target-feature=+crt-static");
- }
+ install_onnxruntime();
+ }
- let url = "https://github.com/microsoft/onnxruntime/releases/download/v1.19.2/onnxruntime-win-x64-gpu-1.19.2.zip";
- let resp = reqwest::blocking::get(url).expect("request failed");
- let body = resp.bytes().expect("body invalid");
- fs::write("./onnxruntime-win-x64-gpu-1.19.2.zip", &body);
- let status = Command::new("unzip")
- .args(["onnxruntime-win-x64-gpu-1.19.2.zip"])
- .status()
- .expect("failed to execute process");
- if !status.success() {
- panic!("failed to install onnx binary");
+ if !is_bun_installed() {
+ install_bun();
+ }
+}
+
+fn is_bun_installed() -> bool {
+ let output = Command::new("bun").arg("--version").output();
+
+ match output {
+ Err(_) => false,
+ Ok(output) => output.status.success(),
+ }
+}
+
+fn run_bun_install_command(command: Result<Output>) {
+ match command {
+ Err(error) => {
+ println!("failed to install bun: {}", error);
+ println!("please install bun manually.");
+ }
+ Ok(output) => {
+ if output.status.success() {
+ println!("bun installed successfully.");
+ } else {
+ println!(
+ "failed to install bun: {}",
+ String::from_utf8_lossy(&output.stderr)
+ );
+ println!("please install bun manually.");
+ }
}
- fs::rename(
- "onnxruntime-win-x64-gpu-1.19.2",
- "../screenpipe-app-tauri/src-tauri/onnxruntime-win-x64-gpu-1.19.2",
+ }
+}
+
+fn install_bun() {
+ println!("installing bun...");
+
+ #[cfg(target_os = "windows")]
+ {
+ println!("attempting to install bun using npm...");
+
+ run_bun_install_command(Command::new("npm").args(["install", "-g", "bun"]).output());
+ }
+
+ #[cfg(not(target_os = "windows"))]
+ {
+ run_bun_install_command(
+ Command::new("sh")
+ .args(["-c", "curl -fsSL https://bun.sh/install | bash"])
+ .output(),
);
}
}
+
+#[cfg(target_os = "windows")]
+fn install_onnxruntime() {
+ // Set static CRT for Windows MSVC target
+ if env::var("CARGO_CFG_TARGET_ENV").unwrap_or_default() == "msvc" {
+ println!("cargo:rustc-env=KNF_STATIC_CRT=1");
+ println!("cargo:rustc-flag=-C target-feature=+crt-static");
+ }
+
+ let url = "https://github.com/microsoft/onnxruntime/releases/download/v1.19.2/onnxruntime-win-x64-gpu-1.19.2.zip";
+ let resp = reqwest::blocking::get(url).expect("request failed");
+ let body = resp.bytes().expect("body invalid");
+ fs::write("./onnxruntime-win-x64-gpu-1.19.2.zip", &body);
+ let status = Command::new("unzip")
+ .args(["onnxruntime-win-x64-gpu-1.19.2.zip"])
+ .status()
+ .expect("failed to execute process");
+ if !status.success() {
+ panic!("failed to install onnx binary");
+ }
+ fs::rename(
+ "onnxruntime-win-x64-gpu-1.19.2",
+ "../screenpipe-app-tauri/src-tauri/onnxruntime-win-x64-gpu-1.19.2",
+ );
+}