Skip to content

feat(ffi): enable bun:ffi on FreeBSD - #31528

Open
mfwolffe wants to merge 2 commits into
oven-sh:mainfrom
mfwolffe:freebsd-ffi-v2
Open

feat(ffi): enable bun:ffi on FreeBSD#31528
mfwolffe wants to merge 2 commits into
oven-sh:mainfrom
mfwolffe:freebsd-ffi-v2

Conversation

@mfwolffe

Copy link
Copy Markdown

What does this PR do?

Enable TinyCC and bun:ffi dlopen() on FreeBSD. The vendored TinyCC
fork already has full FreeBSD ELF support (TARGETOS_FreeBSD, note
sections, ld-elf.so.1 interp) but was excluded from the build.

Changes:

  • config.ts / buildOptionsRs.ts: remove FreeBSD from tinycc exclusion
  • tinycc.ts: set TARGETOS_FreeBSD define
  • tcc.rs: remove FreeBSD from cfg-gated extern stubs
  • tools.ts: add FreeBSD LLVM paths and name variants (clang21, lld21),
    wire up ld.lld and strip resolution

How did you verify your code works?

Full build from source on FreeBSD 15.0 x86_64 with LLVM 21.1.8 and
Rust nightly-2026-05-06. bun:ffi dlopen() loads a Zig-compiled .so
and the resulting binary passes the version smoke test.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

Actionable comments posted: 0

@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6d11b815-cd7e-46e2-9594-45b998adc48a

📥 Commits

Reviewing files that changed from the base of the PR and between 281ea42 and 22b7074.

📒 Files selected for processing (1)
  • src/runtime/ffi/mod.rs
💤 Files with no reviewable changes (1)
  • src/runtime/ffi/mod.rs

Walkthrough

FreeBSD is removed from TinyCC-disable gating; TinyCC can be enabled on FreeBSD. Build defines add TARGETOS_FreeBSD. LLVM discovery and tool selection are extended for FreeBSD. tcc FFI now emits real extern declarations on FreeBSD instead of stubs.

Changes

FreeBSD TinyCC and LLVM support

Layer / File(s) Summary
TinyCC feature gating for FreeBSD
scripts/build/buildOptionsRs.ts, scripts/build/config.ts
FreeBSD is removed from conditions that disable TinyCC, altering the generated ENABLE_TINYCC predicate and default cfg.tinycc.
TinyCC DirectBuild target configuration
scripts/build/deps/tinycc.ts
FreeBSD-specific target define TARGETOS_FreeBSD is added to the TinyCC DirectBuild defines map.
LLVM toolchain discovery for FreeBSD
scripts/build/tools.ts
LLVM search paths include FreeBSD standard and ports directories; name variants include ports-style suffix; linker and strip selection adopt Linux-style resolution for FreeBSD.
TinyCC FFI symbol declarations for FreeBSD
src/tcc_sys/tcc.rs, src/runtime/ffi/mod.rs
tcc_externs! cfg logic and TCC::tcc_delete gating now generate real unsafe extern "C" declarations on FreeBSD; Android and Windows/aarch64 remain stubbed.

Possibly related PRs

  • oven-sh/bun#30749: Modifies ENABLE_TINYCC constant generation in scripts/build/buildOptionsRs.ts with related platform-gating changes.
  • oven-sh/bun#30743: Adjusts TinyCC FFI symbol wiring via target-specific extern declarations for consistency with bun_tcc_sys support.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly describes the main objective: enabling bun:ffi on FreeBSD, which aligns with all changes across the codebase.
Description check ✅ Passed The description includes both required sections with comprehensive details: 'What does this PR do?' explains the feature and lists changes; 'How did you verify?' documents the build environment and testing.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

TinyCC's vendored fork already has full FreeBSD ELF support
(TARGETOS_FreeBSD, note sections, ld-elf.so.1 interp) but was
excluded from the build. Remove the exclusion from three places:

- scripts/build/config.ts: build-time tinycc flag
- scripts/build/buildOptionsRs.ts: ENABLE_TINYCC constant
- src/tcc_sys/tcc.rs: cfg-gated extern stubs

Also add FreeBSD LLVM tool resolution (ports use clang21/lld21
naming and /usr/local paths) and wire up ld.lld/strip for the
FreeBSD link step.

Tested: bun build + bun:ffi dlopen() on FreeBSD 15.0 x86_64.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/tcc_sys/tcc.rs`:
- Around line 34-40: The runtime FFI gating is out of sync with tcc_sys: in
mod.rs update the cfg attributes so FreeBSD is treated the same as in
tcc_sys—remove "target_os = \"freebsd\"" from the #[cfg(not(any(...)))] that
wraps the real extern "C" block and from the #[cfg(any(...))] that provides the
tcc_delete unreachable! stub; instead enable the real extern "C" bindings on
FreeBSD and replace the stubbed tcc_delete with the forwarding implementation
that calls into the tcc_sys binding (use the same extern symbol names and the
tcc_delete function identifier) so FreeBSD uses the real TinyCC FFI rather than
panicking.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6af37c84-4a9c-4673-a6ae-8278af584eb9

📥 Commits

Reviewing files that changed from the base of the PR and between c731fe9 and 281ea42.

📒 Files selected for processing (5)
  • scripts/build/buildOptionsRs.ts
  • scripts/build/config.ts
  • scripts/build/deps/tinycc.ts
  • scripts/build/tools.ts
  • src/tcc_sys/tcc.rs
💤 Files with no reviewable changes (1)
  • scripts/build/buildOptionsRs.ts

Comment thread src/tcc_sys/tcc.rs
Missed a second cfg gate — tcc_delete in runtime/ffi/mod.rs had
its own FreeBSD exclusion independent of tcc_sys. Remove it to
match the tcc_sys change.

Found by CodeRabbit review.
@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

Actionable comments posted: 0

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