feat(desktop): compose V2 sidecar
This commit is contained in:
parent
f147ff64f1
commit
850721c3e9
28 changed files with 577 additions and 161 deletions
|
|
@ -7,4 +7,4 @@ const channel = resolveChannel()
|
|||
await $`bun ./scripts/copy-icons.ts ${channel}`
|
||||
await $`bun ./scripts/copy-metainfo.ts ${channel}`
|
||||
|
||||
await $`cd ../opencode && bun script/build-node.ts`
|
||||
await import("./stage-server-assets")
|
||||
|
|
|
|||
|
|
@ -2,4 +2,4 @@ import { $ } from "bun"
|
|||
|
||||
await $`bun ./scripts/copy-icons.ts ${process.env.OPENCODE_CHANNEL ?? "dev"}`
|
||||
|
||||
await $`cd ../opencode && bun script/build-node.ts`
|
||||
await import("./stage-server-assets")
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
#!/usr/bin/env bun
|
||||
import { Script } from "@opencode-ai/script"
|
||||
|
||||
await import("./prebuild")
|
||||
|
||||
const pkg = await Bun.file("./package.json").json()
|
||||
pkg.version = Script.version
|
||||
await Bun.write("./package.json", JSON.stringify(pkg, null, 2) + "\n")
|
||||
|
|
|
|||
36
packages/desktop/scripts/stage-server-assets.ts
Normal file
36
packages/desktop/scripts/stage-server-assets.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import { chmod, cp, mkdir, rm, writeFile } from "node:fs/promises"
|
||||
import path from "node:path"
|
||||
import { fileURLToPath } from "node:url"
|
||||
|
||||
import { getServerTarget } from "./target"
|
||||
|
||||
const target = getServerTarget()
|
||||
const root = path.resolve(import.meta.dirname, "../resources/server-assets")
|
||||
const nodePtyPackage = `@lydell/node-pty-${target.platform}-${target.arch}`
|
||||
const parcelWatcherPackage = `@parcel/watcher-${target.platform}-${target.arch}${target.platform === "linux" ? "-glibc" : ""}`
|
||||
const photonWasm = "@silvia-odwyer/photon-node/photon_rs_bg.wasm"
|
||||
const nodePtyEntry = fileURLToPath(import.meta.resolve(nodePtyPackage))
|
||||
const nodePtyRoot = path.resolve(path.dirname(nodePtyEntry), "..")
|
||||
|
||||
await rm(root, { recursive: true, force: true })
|
||||
await mkdir(root, { recursive: true })
|
||||
await cp(nodePtyRoot, path.join(root, nodePtyPackage), {
|
||||
recursive: true,
|
||||
filter: (source) => !source.endsWith(".map") && !source.endsWith(".pdb"),
|
||||
})
|
||||
await mkdir(path.join(root, parcelWatcherPackage), { recursive: true })
|
||||
await cp(
|
||||
fileURLToPath(import.meta.resolve(parcelWatcherPackage)),
|
||||
path.join(root, parcelWatcherPackage, "watcher.node"),
|
||||
)
|
||||
await mkdir(path.join(root, path.dirname(photonWasm)), { recursive: true })
|
||||
await cp(fileURLToPath(import.meta.resolve(photonWasm)), path.join(root, photonWasm))
|
||||
|
||||
if (target.platform === "darwin") {
|
||||
await chmod(path.join(root, nodePtyPackage, "prebuilds", `darwin-${target.arch}`, "spawn-helper"), 0o755)
|
||||
}
|
||||
|
||||
await writeFile(
|
||||
path.join(root, "target.json"),
|
||||
`${JSON.stringify({ ...target, nodePtyPackage, parcelWatcherPackage }, null, 2)}\n`,
|
||||
)
|
||||
72
packages/desktop/scripts/target.ts
Normal file
72
packages/desktop/scripts/target.ts
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
export const SIDECAR_BINARIES: Array<{
|
||||
rustTarget: string
|
||||
ocBinary: string
|
||||
assetExt: string
|
||||
platform: "darwin" | "linux" | "win32"
|
||||
arch: "arm64" | "x64"
|
||||
}> = [
|
||||
{
|
||||
rustTarget: "aarch64-apple-darwin",
|
||||
ocBinary: "opencode-darwin-arm64",
|
||||
assetExt: "zip",
|
||||
platform: "darwin",
|
||||
arch: "arm64",
|
||||
},
|
||||
{
|
||||
rustTarget: "x86_64-apple-darwin",
|
||||
ocBinary: "opencode-darwin-x64-baseline",
|
||||
assetExt: "zip",
|
||||
platform: "darwin",
|
||||
arch: "x64",
|
||||
},
|
||||
{
|
||||
rustTarget: "aarch64-pc-windows-msvc",
|
||||
ocBinary: "opencode-windows-arm64",
|
||||
assetExt: "zip",
|
||||
platform: "win32",
|
||||
arch: "arm64",
|
||||
},
|
||||
{
|
||||
rustTarget: "x86_64-pc-windows-msvc",
|
||||
ocBinary: "opencode-windows-x64-baseline",
|
||||
assetExt: "zip",
|
||||
platform: "win32",
|
||||
arch: "x64",
|
||||
},
|
||||
{
|
||||
rustTarget: "x86_64-unknown-linux-gnu",
|
||||
ocBinary: "opencode-linux-x64-baseline",
|
||||
assetExt: "tar.gz",
|
||||
platform: "linux",
|
||||
arch: "x64",
|
||||
},
|
||||
{
|
||||
rustTarget: "aarch64-unknown-linux-gnu",
|
||||
ocBinary: "opencode-linux-arm64",
|
||||
assetExt: "tar.gz",
|
||||
platform: "linux",
|
||||
arch: "arm64",
|
||||
},
|
||||
]
|
||||
|
||||
export const RUST_TARGET = process.env.RUST_TARGET
|
||||
|
||||
function nativeTarget() {
|
||||
if (process.platform === "darwin") return process.arch === "arm64" ? "aarch64-apple-darwin" : "x86_64-apple-darwin"
|
||||
if (process.platform === "win32")
|
||||
return process.arch === "arm64" ? "aarch64-pc-windows-msvc" : "x86_64-pc-windows-msvc"
|
||||
if (process.platform === "linux")
|
||||
return process.arch === "arm64" ? "aarch64-unknown-linux-gnu" : "x86_64-unknown-linux-gnu"
|
||||
throw new Error(`Unsupported platform: ${process.platform}/${process.arch}`)
|
||||
}
|
||||
|
||||
export function getCurrentSidecar(target = RUST_TARGET ?? nativeTarget()) {
|
||||
const binaryConfig = SIDECAR_BINARIES.find((item) => item.rustTarget === target)
|
||||
if (!binaryConfig) throw new Error(`Sidecar configuration not available for Rust target '${target}'`)
|
||||
return binaryConfig
|
||||
}
|
||||
|
||||
export function getServerTarget(target = RUST_TARGET ?? nativeTarget()) {
|
||||
const current = getCurrentSidecar(target)
|
||||
return { rustTarget: current.rustTarget, platform: current.platform, arch: current.arch }
|
||||
}
|
||||
28
packages/desktop/scripts/utils.test.ts
Normal file
28
packages/desktop/scripts/utils.test.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { expect, test } from "bun:test"
|
||||
|
||||
import { SIDECAR_BINARIES, getServerTarget } from "./target"
|
||||
import packageManifest from "../package.json"
|
||||
|
||||
test("derives the Windows ARM64 server assets from the release target", () => {
|
||||
expect(getServerTarget("aarch64-pc-windows-msvc")).toEqual({
|
||||
rustTarget: "aarch64-pc-windows-msvc",
|
||||
platform: "win32",
|
||||
arch: "arm64",
|
||||
})
|
||||
})
|
||||
|
||||
test("derives each packaged server architecture independently of the runner", () => {
|
||||
expect(getServerTarget("x86_64-apple-darwin")).toMatchObject({ platform: "darwin", arch: "x64" })
|
||||
expect(getServerTarget("aarch64-unknown-linux-gnu")).toMatchObject({ platform: "linux", arch: "arm64" })
|
||||
})
|
||||
|
||||
test("declares every target-native server dependency directly", () => {
|
||||
const dependencies = packageManifest.devDependencies
|
||||
for (const target of SIDECAR_BINARIES) {
|
||||
expect(dependencies[`@lydell/node-pty-${target.platform}-${target.arch}`]).toBeDefined()
|
||||
const watcher = `@parcel/watcher-${target.platform}-${target.arch}${target.platform === "linux" ? "-glibc" : ""}`
|
||||
expect(dependencies[watcher]).toBeDefined()
|
||||
}
|
||||
expect(dependencies["@parcel/watcher-darwin-x64"]).toBe("2.5.1")
|
||||
expect(dependencies["@silvia-odwyer/photon-node"]).toBe("0.3.4")
|
||||
})
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
import { $ } from "bun"
|
||||
|
||||
export { getCurrentSidecar, getServerTarget, RUST_TARGET, SIDECAR_BINARIES } from "./target"
|
||||
|
||||
export type Channel = "dev" | "beta" | "prod"
|
||||
|
||||
export function resolveChannel(): Channel {
|
||||
|
|
@ -8,56 +10,6 @@ export function resolveChannel(): Channel {
|
|||
return "dev"
|
||||
}
|
||||
|
||||
export const SIDECAR_BINARIES: Array<{ rustTarget: string; ocBinary: string; assetExt: string }> = [
|
||||
{
|
||||
rustTarget: "aarch64-apple-darwin",
|
||||
ocBinary: "opencode-darwin-arm64",
|
||||
assetExt: "zip",
|
||||
},
|
||||
{
|
||||
rustTarget: "x86_64-apple-darwin",
|
||||
ocBinary: "opencode-darwin-x64-baseline",
|
||||
assetExt: "zip",
|
||||
},
|
||||
{
|
||||
rustTarget: "aarch64-pc-windows-msvc",
|
||||
ocBinary: "opencode-windows-arm64",
|
||||
assetExt: "zip",
|
||||
},
|
||||
{
|
||||
rustTarget: "x86_64-pc-windows-msvc",
|
||||
ocBinary: "opencode-windows-x64-baseline",
|
||||
assetExt: "zip",
|
||||
},
|
||||
{
|
||||
rustTarget: "x86_64-unknown-linux-gnu",
|
||||
ocBinary: "opencode-linux-x64-baseline",
|
||||
assetExt: "tar.gz",
|
||||
},
|
||||
{
|
||||
rustTarget: "aarch64-unknown-linux-gnu",
|
||||
ocBinary: "opencode-linux-arm64",
|
||||
assetExt: "tar.gz",
|
||||
},
|
||||
]
|
||||
|
||||
export const RUST_TARGET = Bun.env.RUST_TARGET
|
||||
|
||||
function nativeTarget() {
|
||||
const { platform, arch } = process
|
||||
if (platform === "darwin") return arch === "arm64" ? "aarch64-apple-darwin" : "x86_64-apple-darwin"
|
||||
if (platform === "win32") return arch === "arm64" ? "aarch64-pc-windows-msvc" : "x86_64-pc-windows-msvc"
|
||||
if (platform === "linux") return arch === "arm64" ? "aarch64-unknown-linux-gnu" : "x86_64-unknown-linux-gnu"
|
||||
throw new Error(`Unsupported platform: ${platform}/${arch}`)
|
||||
}
|
||||
|
||||
export function getCurrentSidecar(target = RUST_TARGET ?? nativeTarget()) {
|
||||
const binaryConfig = SIDECAR_BINARIES.find((b) => b.rustTarget === target)
|
||||
if (!binaryConfig) throw new Error(`Sidecar configuration not available for Rust target '${target}'`)
|
||||
|
||||
return binaryConfig
|
||||
}
|
||||
|
||||
export async function copyBinaryToSidecarFolder(source: string) {
|
||||
const dir = `resources`
|
||||
await $`mkdir -p ${dir}`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue