From e29203f60365384c88dcb15c5ba296aabfd781d3 Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Tue, 9 Jun 2026 15:25:16 -0400 Subject: [PATCH 1/4] fix(opencode): bundle fff native library --- bun.lock | 1 + package.json | 1 + packages/opencode/script/build.ts | 2 +- patches/@ff-labs%2Ffff-bun@0.9.3.patch | 34 ++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 patches/@ff-labs%2Ffff-bun@0.9.3.patch diff --git a/bun.lock b/bun.lock index 7d5ea89d9452..7bb937ce5dcf 100644 --- a/bun.lock +++ b/bun.lock @@ -914,6 +914,7 @@ "patchedDependencies": { "solid-js@1.9.10": "patches/solid-js@1.9.10.patch", "virtua@0.49.1": "patches/virtua@0.49.1.patch", + "@ff-labs/fff-bun@0.9.3": "patches/@ff-labs%2Ffff-bun@0.9.3.patch", "gcp-metadata@8.1.2": "patches/gcp-metadata@8.1.2.patch", "@ai-sdk/google@3.0.73": "patches/@ai-sdk%2Fgoogle@3.0.73.patch", "@ai-sdk/xai@3.0.82": "patches/@ai-sdk%2Fxai@3.0.82.patch", diff --git a/package.json b/package.json index 61800b8fa74d..8ea2430ac6c6 100644 --- a/package.json +++ b/package.json @@ -140,6 +140,7 @@ "@types/node": "catalog:" }, "patchedDependencies": { + "@ff-labs/fff-bun@0.9.3": "patches/@ff-labs%2Ffff-bun@0.9.3.patch", "@npmcli/agent@4.0.2": "patches/@npmcli%2Fagent@4.0.2.patch", "@silvia-odwyer/photon-node@0.3.4": "patches/@silvia-odwyer%2Fphoton-node@0.3.4.patch", "@standard-community/standard-openapi@0.2.9": "patches/@standard-community%2Fstandard-openapi@0.2.9.patch", diff --git a/packages/opencode/script/build.ts b/packages/opencode/script/build.ts index 782aa07c7336..09300965fe4d 100755 --- a/packages/opencode/script/build.ts +++ b/packages/opencode/script/build.ts @@ -165,7 +165,7 @@ for (const item of targets) { const workerRelativePath = path.relative(dir, parserWorker).replaceAll("\\", "/") await Bun.build({ - conditions: ["node"], + conditions: ["bun", "node"], tsconfig: "./tsconfig.json", plugins: [plugin], external: ["node-gyp"], diff --git a/patches/@ff-labs%2Ffff-bun@0.9.3.patch b/patches/@ff-labs%2Ffff-bun@0.9.3.patch new file mode 100644 index 000000000000..b60128af9e19 --- /dev/null +++ b/patches/@ff-labs%2Ffff-bun@0.9.3.patch @@ -0,0 +1,34 @@ +diff --git a/src/download.ts b/src/download.ts +index 3454256..6dca25a 100644 +--- a/src/download.ts ++++ b/src/download.ts +@@ -7,7 +7,6 @@ + */ + + import { existsSync } from "node:fs"; +-import { createRequire } from "node:module"; + import { dirname, join } from "node:path"; + import { fileURLToPath } from "node:url"; + import { getLibFilename, getNpmPackageName } from "./platform"; +@@ -54,14 +53,14 @@ export function binaryExists(): boolean { + * in the same directory. + */ + function resolveFromNpmPackage(): string | null { +- const packageName = getNpmPackageName(); +- + try { +- // Use createRequire to resolve the platform package's location +- const require = createRequire(join(getPackageDir(), "package.json")); +- const packageJsonPath = require.resolve(`${packageName}/package.json`); +- const packageDir = dirname(packageJsonPath); +- const binaryPath = join(packageDir, getLibFilename()); ++ const binaryPath = process.platform === "win32" ++ ? require(`../../../../../@ff-labs+fff-bin-win32-${process.arch}@0.9.3/node_modules/@ff-labs/fff-bin-win32-${process.arch}/fff_c.dll`) ++ : process.platform === "darwin" ++ ? require(`../../../../../@ff-labs+fff-bin-darwin-${process.arch}@0.9.3/node_modules/@ff-labs/fff-bin-darwin-${process.arch}/libfff_c.dylib`) ++ : getNpmPackageName().endsWith("musl") ++ ? require(`../../../../../@ff-labs+fff-bin-linux-${process.arch}-musl@0.9.3/node_modules/@ff-labs/fff-bin-linux-${process.arch}-musl/libfff_c.so`) ++ : require(`../../../../../@ff-labs+fff-bin-linux-${process.arch}-gnu@0.9.3/node_modules/@ff-labs/fff-bin-linux-${process.arch}-gnu/libfff_c.so`); + + if (existsSync(binaryPath)) { + return binaryPath; From 0195d3d4b6335a90a8cb89944ed19fcad296e136 Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Tue, 9 Jun 2026 15:25:54 -0400 Subject: [PATCH 2/4] chore(opencode): clean fff dependency patch --- patches/@ff-labs%2Ffff-bun@0.9.3.patch | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/patches/@ff-labs%2Ffff-bun@0.9.3.patch b/patches/@ff-labs%2Ffff-bun@0.9.3.patch index b60128af9e19..e1a9d6d8bf4c 100644 --- a/patches/@ff-labs%2Ffff-bun@0.9.3.patch +++ b/patches/@ff-labs%2Ffff-bun@0.9.3.patch @@ -2,18 +2,10 @@ diff --git a/src/download.ts b/src/download.ts index 3454256..6dca25a 100644 --- a/src/download.ts +++ b/src/download.ts -@@ -7,7 +7,6 @@ - */ - +@@ -9,2 +9 @@ import { existsSync } from "node:fs"; -import { createRequire } from "node:module"; - import { dirname, join } from "node:path"; - import { fileURLToPath } from "node:url"; - import { getLibFilename, getNpmPackageName } from "./platform"; -@@ -54,14 +53,14 @@ export function binaryExists(): boolean { - * in the same directory. - */ - function resolveFromNpmPackage(): string | null { +@@ -56,8 +55,8 @@ function resolveFromNpmPackage(): string | null { - const packageName = getNpmPackageName(); - try { @@ -29,6 +21,3 @@ index 3454256..6dca25a 100644 + : getNpmPackageName().endsWith("musl") + ? require(`../../../../../@ff-labs+fff-bin-linux-${process.arch}-musl@0.9.3/node_modules/@ff-labs/fff-bin-linux-${process.arch}-musl/libfff_c.so`) + : require(`../../../../../@ff-labs+fff-bin-linux-${process.arch}-gnu@0.9.3/node_modules/@ff-labs/fff-bin-linux-${process.arch}-gnu/libfff_c.so`); - - if (existsSync(binaryPath)) { - return binaryPath; From 97f94854a0362836ad86d06132877032b9ffa86a Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Tue, 9 Jun 2026 15:27:58 -0400 Subject: [PATCH 3/4] fix(opencode): restore valid fff patch --- patches/@ff-labs%2Ffff-bun@0.9.3.patch | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/patches/@ff-labs%2Ffff-bun@0.9.3.patch b/patches/@ff-labs%2Ffff-bun@0.9.3.patch index e1a9d6d8bf4c..b60128af9e19 100644 --- a/patches/@ff-labs%2Ffff-bun@0.9.3.patch +++ b/patches/@ff-labs%2Ffff-bun@0.9.3.patch @@ -2,10 +2,18 @@ diff --git a/src/download.ts b/src/download.ts index 3454256..6dca25a 100644 --- a/src/download.ts +++ b/src/download.ts -@@ -9,2 +9 @@ +@@ -7,7 +7,6 @@ + */ + import { existsSync } from "node:fs"; -import { createRequire } from "node:module"; -@@ -56,8 +55,8 @@ function resolveFromNpmPackage(): string | null { + import { dirname, join } from "node:path"; + import { fileURLToPath } from "node:url"; + import { getLibFilename, getNpmPackageName } from "./platform"; +@@ -54,14 +53,14 @@ export function binaryExists(): boolean { + * in the same directory. + */ + function resolveFromNpmPackage(): string | null { - const packageName = getNpmPackageName(); - try { @@ -21,3 +29,6 @@ index 3454256..6dca25a 100644 + : getNpmPackageName().endsWith("musl") + ? require(`../../../../../@ff-labs+fff-bin-linux-${process.arch}-musl@0.9.3/node_modules/@ff-labs/fff-bin-linux-${process.arch}-musl/libfff_c.so`) + : require(`../../../../../@ff-labs+fff-bin-linux-${process.arch}-gnu@0.9.3/node_modules/@ff-labs/fff-bin-linux-${process.arch}-gnu/libfff_c.so`); + + if (existsSync(binaryPath)) { + return binaryPath; From b5539f13c686b58d7033884971eadf821b5d19a1 Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Tue, 9 Jun 2026 15:43:21 -0400 Subject: [PATCH 4/4] fix(opencode): select target fff binary --- bun.lock | 1 + packages/opencode/package.json | 1 + packages/opencode/script/build.ts | 2 ++ patches/@ff-labs%2Ffff-bun@0.9.3.patch | 15 ++++++--------- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/bun.lock b/bun.lock index 7bb937ce5dcf..2dd24d537597 100644 --- a/bun.lock +++ b/bun.lock @@ -525,6 +525,7 @@ "@clack/prompts": "1.0.0-alpha.1", "@effect/opentelemetry": "catalog:", "@effect/platform-node": "catalog:", + "@ff-labs/fff-bun": "0.9.3", "@gitlab/opencode-gitlab-auth": "1.3.3", "@modelcontextprotocol/sdk": "1.29.0", "@octokit/graphql": "9.0.2", diff --git a/packages/opencode/package.json b/packages/opencode/package.json index 8150e1e6f450..5dff872b51fb 100644 --- a/packages/opencode/package.json +++ b/packages/opencode/package.json @@ -78,6 +78,7 @@ "@clack/prompts": "1.0.0-alpha.1", "@effect/opentelemetry": "catalog:", "@effect/platform-node": "catalog:", + "@ff-labs/fff-bun": "0.9.3", "@gitlab/opencode-gitlab-auth": "1.3.3", "@modelcontextprotocol/sdk": "1.29.0", "@octokit/graphql": "9.0.2", diff --git a/packages/opencode/script/build.ts b/packages/opencode/script/build.ts index 09300965fe4d..236838dbdee7 100755 --- a/packages/opencode/script/build.ts +++ b/packages/opencode/script/build.ts @@ -140,6 +140,7 @@ const binaries: Record = {} if (!skipInstall) { await $`bun install --os="*" --cpu="*" @opentui/core@${pkg.dependencies["@opentui/core"]}` await $`bun install --os="*" --cpu="*" @parcel/watcher@${pkg.dependencies["@parcel/watcher"]}` + await $`bun install --os="*" --cpu="*" @ff-labs/fff-bun@${pkg.dependencies["@ff-labs/fff-bun"]}` } for (const item of targets) { const name = [ @@ -186,6 +187,7 @@ for (const item of targets) { files: embeddedFileMap ? { "opencode-web-ui.gen.ts": embeddedFileMap } : {}, entrypoints: ["./src/index.ts", parserWorker, workerPath, ...(embeddedFileMap ? ["opencode-web-ui.gen.ts"] : [])], define: { + FFF_LIBC: JSON.stringify(item.abi === "musl" ? "musl" : "gnu"), OPENCODE_VERSION: `'${Script.version}'`, OPENCODE_MODELS_DEV: generated.modelsData, OTUI_TREE_SITTER_WORKER_PATH: bunfsRoot + workerRelativePath, diff --git a/patches/@ff-labs%2Ffff-bun@0.9.3.patch b/patches/@ff-labs%2Ffff-bun@0.9.3.patch index b60128af9e19..23a7dd54fb15 100644 --- a/patches/@ff-labs%2Ffff-bun@0.9.3.patch +++ b/patches/@ff-labs%2Ffff-bun@0.9.3.patch @@ -2,15 +2,16 @@ diff --git a/src/download.ts b/src/download.ts index 3454256..6dca25a 100644 --- a/src/download.ts +++ b/src/download.ts -@@ -7,7 +7,6 @@ +@@ -7,7 +7,7 @@ */ ++declare const FFF_LIBC: "gnu" | "musl"; import { existsSync } from "node:fs"; -import { createRequire } from "node:module"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; import { getLibFilename, getNpmPackageName } from "./platform"; -@@ -54,14 +53,14 @@ export function binaryExists(): boolean { +@@ -54,14 +54,10 @@ export function binaryExists(): boolean { * in the same directory. */ function resolveFromNpmPackage(): string | null { @@ -22,13 +23,9 @@ index 3454256..6dca25a 100644 - const packageJsonPath = require.resolve(`${packageName}/package.json`); - const packageDir = dirname(packageJsonPath); - const binaryPath = join(packageDir, getLibFilename()); -+ const binaryPath = process.platform === "win32" -+ ? require(`../../../../../@ff-labs+fff-bin-win32-${process.arch}@0.9.3/node_modules/@ff-labs/fff-bin-win32-${process.arch}/fff_c.dll`) -+ : process.platform === "darwin" -+ ? require(`../../../../../@ff-labs+fff-bin-darwin-${process.arch}@0.9.3/node_modules/@ff-labs/fff-bin-darwin-${process.arch}/libfff_c.dylib`) -+ : getNpmPackageName().endsWith("musl") -+ ? require(`../../../../../@ff-labs+fff-bin-linux-${process.arch}-musl@0.9.3/node_modules/@ff-labs/fff-bin-linux-${process.arch}-musl/libfff_c.so`) -+ : require(`../../../../../@ff-labs+fff-bin-linux-${process.arch}-gnu@0.9.3/node_modules/@ff-labs/fff-bin-linux-${process.arch}-gnu/libfff_c.so`); ++ const binaryPath = require( ++ `@ff-labs/fff-bin-${process.platform === "linux" ? `linux-${process.arch}-${typeof FFF_LIBC === "string" ? FFF_LIBC : getNpmPackageName().endsWith("musl") ? "musl" : "gnu"}` : `${process.platform}-${process.arch}`}/${process.platform === "win32" ? "fff_c.dll" : process.platform === "darwin" ? "libfff_c.dylib" : "libfff_c.so"}`, ++ ); if (existsSync(binaryPath)) { return binaryPath;