utils.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { $ } from "bun"
  2. export const SIDECAR_BINARIES: Array<{ rustTarget: string; ocBinary: string; assetExt: string }> = [
  3. {
  4. rustTarget: "aarch64-apple-darwin",
  5. ocBinary: "opencode-darwin-arm64",
  6. assetExt: "zip",
  7. },
  8. {
  9. rustTarget: "x86_64-apple-darwin",
  10. ocBinary: "opencode-darwin-x64",
  11. assetExt: "zip",
  12. },
  13. {
  14. rustTarget: "x86_64-pc-windows-msvc",
  15. ocBinary: "opencode-windows-x64",
  16. assetExt: "zip",
  17. },
  18. {
  19. rustTarget: "x86_64-unknown-linux-gnu",
  20. ocBinary: "opencode-linux-x64",
  21. assetExt: "tar.gz",
  22. },
  23. ]
  24. export const RUST_TARGET = Bun.env.RUST_TARGET
  25. export function getCurrentSidecar(target = RUST_TARGET) {
  26. if (!target && !RUST_TARGET) throw new Error("RUST_TARGET not set")
  27. const binaryConfig = SIDECAR_BINARIES.find((b) => b.rustTarget === target)
  28. if (!binaryConfig) throw new Error(`Sidecar configuration not available for Rust target '${RUST_TARGET}'`)
  29. return binaryConfig
  30. }
  31. export async function copyBinaryToSidecarFolder(source: string, target = RUST_TARGET) {
  32. await $`mkdir -p src-tauri/sidecars`
  33. const dest = `src-tauri/sidecars/opencode-${target}${process.platform === "win32" ? ".exe" : ""}`
  34. await $`cp ${source} ${dest}`
  35. console.log(`Copied ${source} to ${dest}`)
  36. }