utils.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { $ } from "bun"
  2. export const SIDECAR_BINARIES: Array<{ rustTarget: string; ocBinary: string; assetExt: string }> = [
  3. {
  4. rustTarget: "aarch64-apple-darwin",
  5. ocBinary: "@kilocode/cli-darwin-arm64", // kilocode_change
  6. assetExt: "zip",
  7. },
  8. {
  9. rustTarget: "x86_64-apple-darwin",
  10. ocBinary: "@kilocode/cli-darwin-x64", // kilocode_change
  11. assetExt: "zip",
  12. },
  13. {
  14. rustTarget: "aarch64-pc-windows-msvc",
  15. ocBinary: "@kilocode/cli-windows-arm64", // kilocode_change
  16. assetExt: "zip",
  17. },
  18. {
  19. rustTarget: "x86_64-pc-windows-msvc",
  20. ocBinary: "@kilocode/cli-windows-x64", // kilocode_change
  21. assetExt: "zip",
  22. },
  23. {
  24. rustTarget: "x86_64-unknown-linux-gnu",
  25. ocBinary: "@kilocode/cli-linux-x64", // kilocode_change
  26. assetExt: "tar.gz",
  27. },
  28. {
  29. rustTarget: "aarch64-unknown-linux-gnu",
  30. ocBinary: "@kilocode/cli-linux-arm64", // kilocode_change
  31. assetExt: "tar.gz",
  32. },
  33. ]
  34. export const RUST_TARGET = Bun.env.RUST_TARGET
  35. export function getCurrentSidecar(target = RUST_TARGET) {
  36. if (!target && !RUST_TARGET) throw new Error("RUST_TARGET not set")
  37. const binaryConfig = SIDECAR_BINARIES.find((b) => b.rustTarget === target)
  38. if (!binaryConfig) throw new Error(`Sidecar configuration not available for Rust target '${RUST_TARGET}'`)
  39. return binaryConfig
  40. }
  41. export async function copyBinaryToSidecarFolder(source: string, target = RUST_TARGET) {
  42. await $`mkdir -p src-tauri/sidecars`
  43. const dest = windowsify(`src-tauri/sidecars/kilo-cli-${target}`) // kilocode_change
  44. await $`cp ${source} ${dest}`
  45. if (process.platform === "win32" && process.env.GITHUB_ACTIONS === "true") {
  46. await $`pwsh -NoLogo -NoProfile -ExecutionPolicy Bypass -File ../../script/sign-windows.ps1 ${dest}`
  47. }
  48. console.log(`Copied ${source} to ${dest}`)
  49. }
  50. export function windowsify(path: string) {
  51. if (path.endsWith(".exe")) return path
  52. return `${path}${process.platform === "win32" ? ".exe" : ""}`
  53. }