diff --git a/packages/desktop/src-tauri/build.rs b/packages/desktop/src-tauri/build.rs index f6a8b9be..cb770638 100644 --- a/packages/desktop/src-tauri/build.rs +++ b/packages/desktop/src-tauri/build.rs @@ -6,17 +6,22 @@ use std::path::PathBuf; use std::os::unix::fs::PermissionsExt; fn main() { - ensure_opencode_sidecar(); + // Ensure sidecar exists in all builds (debug and release) + if let Err(e) = ensure_opencode_sidecar() { + eprintln!("Error: {}", e); + eprintln!("Install OpenCode or set OPENCODE_BIN_PATH."); + std::process::exit(1); + } tauri_build::build(); } -fn ensure_opencode_sidecar() { +fn ensure_opencode_sidecar() -> Result<(), String> { let target = env::var("CARGO_CFG_TARGET_TRIPLE") .or_else(|_| env::var("TARGET")) .or_else(|_| env::var("TAURI_ENV_TARGET_TRIPLE")) .unwrap_or_default(); if target.is_empty() { - return; + return Ok(()); } let manifest_dir = env::var("CARGO_MANIFEST_DIR") @@ -31,7 +36,7 @@ fn ensure_opencode_sidecar() { let dest_path = sidecar_dir.join(file_name); if dest_path.exists() { - return; + return Ok(()); } let source_path = env::var("OPENCODE_BIN_PATH") @@ -40,20 +45,14 @@ fn ensure_opencode_sidecar() { .filter(|path| path.is_file()) .or_else(|| find_in_path(if target.contains("windows") { "opencode.exe" } else { "opencode" })); - let profile = env::var("PROFILE").unwrap_or_default(); - let Some(source_path) = source_path else { - println!( - "cargo:warning=OpenCode sidecar missing at {} (set OPENCODE_BIN_PATH or install OpenCode)", - dest_path.display() - ); - - create_debug_stub(&dest_path, &sidecar_dir, &profile, &target); - return; + return Err(format!( + "OpenCode not found. Install OpenCode or set OPENCODE_BIN_PATH." + )); }; if fs::create_dir_all(&sidecar_dir).is_err() { - return; + return Err(format!("Failed to create directory: {}", sidecar_dir.display())); } let mut copied = fs::copy(&source_path, &dest_path).is_ok(); @@ -77,13 +76,13 @@ fn ensure_opencode_sidecar() { { let _ = fs::set_permissions(&dest_path, fs::Permissions::from_mode(0o755)); } + Ok(()) } else { - println!( - "cargo:warning=Failed to copy OpenCode sidecar from {} to {}", + Err(format!( + "Failed to copy OpenCode from {} to {}", source_path.display(), dest_path.display() - ); - create_debug_stub(&dest_path, &sidecar_dir, &profile, &target); + )) } } @@ -98,21 +97,3 @@ fn find_in_path(binary: &str) -> Option { } }) } - -fn create_debug_stub(dest_path: &PathBuf, sidecar_dir: &PathBuf, profile: &str, target: &str) { - if profile != "debug" || target.contains("windows") { - return; - } - - if fs::create_dir_all(sidecar_dir).is_err() { - return; - } - - let stub = "#!/usr/bin/env bash\n\ -echo 'OpenCode sidecar missing. Install OpenCode or set OPENCODE_BIN_PATH.'\n\ -exit 1\n"; - if fs::write(dest_path, stub).is_ok() { - #[cfg(unix)] - let _ = fs::set_permissions(dest_path, fs::Permissions::from_mode(0o755)); - } -} diff --git a/packages/desktop/src/app/app.tsx b/packages/desktop/src/app/app.tsx index e13f4212..45337f80 100644 --- a/packages/desktop/src/app/app.tsx +++ b/packages/desktop/src/app/app.tsx @@ -129,7 +129,8 @@ export default function App() { const [themeMode, setThemeMode] = createSignal(getInitialThemeMode()); const [engineSource, setEngineSource] = createSignal<"path" | "sidecar">( - isTauriRuntime() ? "sidecar" : "path" + // Use PATH in development, sidecar in production (when bundled) + isTauriRuntime() && import.meta.env.PROD ? "sidecar" : "path" ); const [baseUrl, setBaseUrl] = createSignal("http://127.0.0.1:4096");