https://github.com/8ff/bun-freebsd
https://github.com/8ff/bun-freebsd
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/8ff/bun-freebsd
- Owner: 8ff
- License: mit
- Created: 2026-04-12T16:24:57.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2026-04-20T13:18:47.000Z (about 2 months ago)
- Last Synced: 2026-04-20T15:31:22.814Z (about 2 months ago)
- Language: Shell
- Size: 13.7 KB
- Stars: 7
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bun-freebsd
Build [Bun](https://github.com/oven-sh/bun) natively on FreeBSD. Based on [Li-Wen Hsu's `claude/freebsd-support` branch](https://github.com/lwhsu/bun/tree/claude/freebsd-support) with additional patches for WebKit, bootstrap toolchain, and cmake wiring.
## Build
```sh
git clone https://github.com/8ff/bun-freebsd.git
cd bun-freebsd
sh build.sh
```
Requires FreeBSD 13.2+ amd64, ~16 GB RAM, ~20 GB disk. The script installs all dependencies via `pkg`, clones the source trees, builds Bun's Zig fork, applies patches, and compiles Bun + WebKit/JSC.
Output: `~/src/bun/build/bun` — a native FreeBSD ELF.
## Running Claude Code
After building, grab `cli.js` from the npm package (while it's still available — Anthropic has said this is being deprecated):
```sh
mkdir -p ~/.npm-global
npm config set prefix ~/.npm-global
npm install -g @anthropic-ai/claude-code
```
Then run it under your native bun:
```sh
~/src/bun/build/bun ~/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js --version
```
For convenience, create a wrapper:
```sh
mkdir -p ~/.local/bin
cat > ~/.local/bin/claude <<'EOF'
#!/bin/sh
exec ~/src/bun/build/bun ~/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js "$@"
EOF
chmod +x ~/.local/bin/claude
```
**Note:** `cli.js` is Anthropic's proprietary code (not included in this repo). Anthropic has stated they plan to deprecate the npm package. This repo only contains the Bun build script and patches — sourcing `cli.js` is on you.
## What the patches fix
~150 lines on top of lwhsu's branch:
- **WebKit `AvailableMemory.cpp`** — FreeBSD branch was using Linux-only `struct sysinfo`; replaced with `sysctlbyname("hw.physmem")`
- **WebKit `RAMSize.cpp`** — removed FreeBSD from `#include ` guard (Linux-only header)
- **`SetupWebKit.cmake`** — pass `USE_SYSTEM_MALLOC=ON` to JSC on FreeBSD (lwhsu had a comment for this but never wired it)
- **`codegen-ts-node-runner.mjs`** — fix esbuild output format for Node bootstrap: strip `__commonJS` wrapper, remove `init_define_*` no-ops, disable `keepNames` to avoid `__name()` helper
- **`bundle-functions.ts`** — remove `if (import.meta.main)` guard that esbuild's `--define` constant-folds to `if (true)` in bundled output
- **`glob-sources-node.mjs`** (new) — Node port of Bun-requiring `glob-sources.mjs` for bootstrap on hosts without an existing Bun binary
## Credit
- [Li-Wen Hsu (@lwhsu)](https://github.com/lwhsu) — ~90% of the FreeBSD port
- Upstream: [oven-sh/bun](https://github.com/oven-sh/bun), [oven-sh/WebKit](https://github.com/oven-sh/WebKit), [oven-sh/zig](https://github.com/oven-sh/zig)