104 lines
2.8 KiB
TypeScript
104 lines
2.8 KiB
TypeScript
#!/usr/bin/env bun
|
|
|
|
import { rm } from "fs/promises"
|
|
import path from "path"
|
|
import { Script } from "@opencode-ai/script"
|
|
import { modelsData } from "./generate"
|
|
|
|
const dir = path.resolve(import.meta.dirname, "..")
|
|
const binary = "lildax"
|
|
process.chdir(dir)
|
|
|
|
await rm("dist", { recursive: true, force: true })
|
|
|
|
const singleFlag = process.argv.includes("--single")
|
|
const baselineFlag = process.argv.includes("--baseline")
|
|
const sourcemapsFlag = process.argv.includes("--sourcemaps")
|
|
|
|
const allTargets: {
|
|
os: string
|
|
arch: "arm64" | "x64"
|
|
abi?: "musl"
|
|
avx2?: false
|
|
}[] = [
|
|
{ os: "linux", arch: "arm64" },
|
|
{ os: "linux", arch: "x64" },
|
|
{ os: "linux", arch: "x64", avx2: false },
|
|
{ os: "linux", arch: "arm64", abi: "musl" },
|
|
{ os: "linux", arch: "x64", abi: "musl" },
|
|
{ os: "linux", arch: "x64", abi: "musl", avx2: false },
|
|
{ os: "darwin", arch: "arm64" },
|
|
{ os: "darwin", arch: "x64" },
|
|
{ os: "darwin", arch: "x64", avx2: false },
|
|
{ os: "win32", arch: "arm64" },
|
|
{ os: "win32", arch: "x64" },
|
|
{ os: "win32", arch: "x64", avx2: false },
|
|
]
|
|
|
|
const targets = singleFlag
|
|
? allTargets.filter((item) => {
|
|
if (item.os !== process.platform || item.arch !== process.arch) return false
|
|
if (item.avx2 === false) return baselineFlag
|
|
return item.abi === undefined
|
|
})
|
|
: allTargets
|
|
|
|
for (const item of targets) {
|
|
const name = [
|
|
binary,
|
|
item.os === "win32" ? "windows" : item.os,
|
|
item.arch,
|
|
item.avx2 === false ? "baseline" : undefined,
|
|
item.abi,
|
|
]
|
|
.filter(Boolean)
|
|
.join("-")
|
|
console.log(`building ${name}`)
|
|
const result = await Bun.build({
|
|
entrypoints: ["./src/index.ts"],
|
|
tsconfig: "./tsconfig.json",
|
|
external: ["node-gyp"],
|
|
format: "esm",
|
|
minify: true,
|
|
sourcemap: sourcemapsFlag ? "linked" : "none",
|
|
splitting: true,
|
|
compile: {
|
|
autoloadBunfig: false,
|
|
autoloadDotenv: false,
|
|
autoloadTsconfig: true,
|
|
autoloadPackageJson: true,
|
|
target: name.replace(binary, "bun") as Bun.Build.CompileTarget,
|
|
outfile: `./dist/${name}/bin/${binary}`,
|
|
execArgv: [`--user-agent=${binary}/${Script.version}`, "--use-system-ca", "--"],
|
|
windows: {},
|
|
},
|
|
define: {
|
|
OPENCODE_VERSION: `'${Script.version}'`,
|
|
OPENCODE_CLI_NAME: `'${binary}'`,
|
|
OPENCODE_MODELS_DEV: modelsData,
|
|
OPENCODE_CHANNEL: `'${Script.channel}'`,
|
|
OPENCODE_LIBC: item.os === "linux" ? `'${item.abi ?? "glibc"}'` : "undefined",
|
|
},
|
|
})
|
|
|
|
if (!result.success) {
|
|
for (const log of result.logs) console.error(log)
|
|
process.exit(1)
|
|
}
|
|
|
|
await Bun.write(
|
|
`./dist/${name}/package.json`,
|
|
JSON.stringify(
|
|
{
|
|
name: `@opencode-ai/${name}`,
|
|
version: Script.version,
|
|
license: "MIT",
|
|
os: [item.os],
|
|
cpu: [item.arch],
|
|
},
|
|
null,
|
|
2,
|
|
),
|
|
)
|
|
}
|