utils.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. rustTarget: "aarch64-unknown-linux-gnu",
  25. ocBinary: "opencode-linux-arm64",
  26. assetExt: "tar.gz",
  27. },
  28. ]
  29. export const RUST_TARGET = Bun.env.RUST_TARGET
  30. export function getCurrentSidecar(target = RUST_TARGET) {
  31. if (!target && !RUST_TARGET) throw new Error("RUST_TARGET not set")
  32. const binaryConfig = SIDECAR_BINARIES.find((b) => b.rustTarget === target)
  33. if (!binaryConfig) throw new Error(`Sidecar configuration not available for Rust target '${RUST_TARGET}'`)
  34. return binaryConfig
  35. }
  36. export async function copyBinaryToSidecarFolder(source: string, target = RUST_TARGET) {
  37. await $`mkdir -p src-tauri/sidecars`
  38. const dest = `src-tauri/sidecars/opencode-cli-${target}${process.platform === "win32" ? ".exe" : ""}`
  39. await $`cp ${source} ${dest}`
  40. console.log(`Copied ${source} to ${dest}`)
  41. }