Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 17 additions & 36 deletions packages/desktop/src-tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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();
Expand All @@ -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);
))
}
}

Expand All @@ -98,21 +97,3 @@ fn find_in_path(binary: &str) -> Option<PathBuf> {
}
})
}

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));
}
}
3 changes: 2 additions & 1 deletion packages/desktop/src/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ export default function App() {
const [themeMode, setThemeMode] = createSignal<ThemeMode>(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");
Expand Down