Skip to content

feat(fff-bun): allow an explicit native library via FFF_C_LIB - #904

Open
samm-git wants to merge 1 commit into
dmtrKovalenko:mainfrom
samm-git:freebsd-fff-c-lib
Open

samm-git wants to merge 1 commit into
dmtrKovalenko:mainfrom
samm-git:freebsd-fff-c-lib

Conversation

@samm-git

@samm-git samm-git commented Oct 5, 2026 •

Copy link
Copy Markdown

What

Lets @ff-labs/fff-bun use a native library built from source on platforms that
have no @ff-labs/fff-bin-* package, via an FFF_C_LIB environment override.

Why

The fff-c crate builds cleanly on FreeBSD (x86_64 and aarch64) with no Rust
changes — this was built and FFI-validated in #824. But no FreeBSD prebuilt is
published, so an npm/bun install can never resolve one: getTriple() throws for
freebsd, and package.json excludes it, so the package does not install at all.

FFF_C_LIB closes that gap without committing the project to a release leg it
has to keep green (no GitHub-hosted FreeBSD runner), and it is generic — it also
covers any custom or cross-compiled build on a supported platform.

Changes

  • src/download.ts: findBinary() checks FFF_C_LIB first. If it is set but the
    path does not exist, resolution fails with an explicit error instead of silently
    falling through.
  • src/download.ts: resolveFromNpmPackage() returns null (instead of throwing)
    when the platform has no package mapped — matching its existing "expected on
    unsupported platforms" contract.
  • src/platform.ts: getTriple() recognises freebsd → unknown-freebsd.
  • package.json: add freebsd to os so the package installs there.
  • README.md: document the override.

No TRIPLE_TO_NPM_PACKAGE entries are added: there is no
@ff-labs/fff-bin-freebsd-* to point at, so naming one would be a dead entry.
Adding those two lines is all that is needed if FreeBSD prebuilts are ever
published.

Notes

  • This is resolution-only; the FFI layer is unchanged.
  • bun --compile: on FreeBSD resolveEmbeddedLibPath() returns null, so
    findBinary() is consulted at runtime and an external FFF_C_LIB library is
    dlopen'ed normally.
  • packages/fff-node duplicates the same getTriple()/resolution logic; happy to
    mirror this there if wanted.
  • Real-world consumer: OpenCode on FreeBSD (its TUI currently degrades gracefully
    without fff; see feat: add FreeBSD (x86_64, aarch64) build support anomalyco/opencode#53371).

Thanks to @apbodrov for proposing exactly this in #824 and for the FreeBSD builds
that show the native library works there.

Summary by CodeRabbit

  • New Features
    • Added FreeBSD support for the Bun package.
    • You can now provide a custom C library path using FFF_C_LIB. This path is checked before platform packages and local builds; if it does not exist, an explicit error is shown.
    • Platforms without a prebuilt package can build the C library from source and configure FFF_C_LIB.
  • Bug Fixes
    • Platforms without a mapped package can proceed to other available library-resolution options instead of failing during package lookup.

Some platforms have no @ff-labs/fff-bin-* prebuilt. FreeBSD builds the C
library cleanly from source, but nothing publishes it, so an npm install
can never resolve it. Add an FFF_C_LIB override, checked before the npm
package and the local dev build, so such a build is usable from a normal
install (and from a bun --compile binary, where resolution happens at
runtime).

Also recognise freebsd in getTriple(), allow @ff-labs/fff-bun to install
there, and make resolveFromNpmPackage() return null instead of throwing
when the platform has no package mapped.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6142ac72-33a9-4930-93aa-1b4adaf10d8b
📥 Commits

Reviewing files that changed from the base of the PR and between c188e7a and e916640.

📒 Files selected for processing (4)
  • packages/fff-bun/README.md
  • packages/fff-bun/package.json
  • packages/fff-bun/src/download.ts
  • packages/fff-bun/src/platform.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The package now supports FreeBSD and checks FFF_C_LIB before its other binary resolution sources. The npm-package resolver returns null when no platform package mapping exists. The README documents how to build the library and configure the override.

Changes

Platform support and binary resolution

Layer / File(s) Summary
Add FreeBSD platform support
packages/fff-bun/package.json, packages/fff-bun/src/platform.ts
The package metadata adds FreeBSD to its supported operating systems. getTriple maps FreeBSD to unknown-freebsd.
Update binary resolution
packages/fff-bun/src/download.ts, packages/fff-bun/README.md
findBinary checks FFF_C_LIB before other resolution sources and throws an error if the path does not exist. The npm-package resolver returns null when no package mapping exists. The README explains how to build the library and set the override.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Suggested reviewers: dmtrkovalenko

Merge Risk: ⚪ Minimal · up to e9166

FreeBSD is now recognized, and an explicit library path takes priority in the normal binary-resolution flow; embedded executables retain their embedded library. No actionable merge risk remains.

Architecture Summary

Architecture risk: 🟡 Medium · up to e9166

The change affects 1 system.

Changed systems: packages/fff-bun

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — packages/fff-bun (library) was modified; 4 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in packages/fff-bun/README.md: Added instructions for platforms without a prebuilt package: build fff-c, set FFF_C_LIB to the resulting library, and use it with the regular package install. The text specifies that this override takes precedence over platform packages and the local development build, and that a nonexistent path produces an explicit error rather than falling back.
  • observed — Modified behavior in packages/fff-bun/package.json: The package adds android and freebsd to its supported operating systems; android was already listed and remains supported.
  • observed — Modified behavior in packages/fff-bun/src/download.ts: The documented resolution sources now list FFF_C_LIB first, ahead of the platform-specific npm package and local development build.
  • observed — Modified behavior in packages/fff-bun/src/download.ts: resolveFromNpmPackage now catches errors from getNpmPackageName() and returns null when the platform is unsupported or has no package mapping; previously, that error propagated.

Reliability and maintainability

  • inferred — Risk-relevant change factors for packages/fff-bun: blast_radius_1; direct_dependents_1
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly names the main change: support for an explicit native library path through FFF_C_LIB.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. (2 skipped: 2 …
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant