- Install FreeBSD 13.2 in a VM and create dummy account, call it
bun
for example - Install these packages as root using
pkg install
ccache cmake git go libiconv libtool gmake ninja pkgconf python rust unzip ruby automake bash llvm16 llvm17 gcc13-dev npm icu libsysinfo
- Change
bun
's shell to/usr/local/bin/bash
usingchsh
( I recommend installing neovim and running the command asEDITOR=nvim chsh
)
now always login as
bun
user
- Clone these repos - there is space between urls,
git clone
each one separately
https://github.com/Bun-BSD/codegen.git https://github.com/oven-sh/WebKit.git https://github.com/ziglang/zig.git https://github.com/Bun-BSD/bun.git
Now we will compile all deps, make sure you are in home directory each time
- Building WebKit
- In your home directory create
webkit.sh
and write this into it
cmake . -B WebKitBuild/Debug \ -DPORT=JSCOnly \ -DENABLE_STATIC_JSC=ON \ -DENABLE_SINGLE_THREADED_VM_ENTRY_SCOPE=ON \ -DCMAKE_BUILD_TYPE=Debug \ -DENABLE_BUN_SKIP_FAILING_ASSERTIONS=ON \ -DUSE_THIN_ARCHIVES=OFF \ -DENABLE_FTL_JIT=ON \ -DCMAKE_C_COMPILER="$(which clang16)" \ -DCMAKE_CXX_COMPILER="$(which clang++16)" \ -DUSE_BUN_JSC_ADDITIONS=ON \ -DCMAKE_C_FLAGS="-I /usr/local/include/ -L /usr/local/lib/ -lsysinfo" \ -DCMAKE_CXX_FLAGS="-I /usr/local/include/ -L /usr/local/lib/ -lsysinfo" \ -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" \ -DCMAKE_AR="$(which llvm-ar)" \ -DCMAKE_RANLIB="$(which llvm-ranlib)" \ -DALLOW_LINE_AND_COLUMN_NUMBER_IN_BUILTINS=ON \ -G Ninja \ -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 \ -DPTHREAD_JIT_PERMISSIONS_API=1 \ -DUSE_PTHREAD_JIT_PERMISSIONS_API=ON \ -DENABLE_REMOTE_INSPECTOR=ON
- In your home directory create
webkitbuninstall.sh
and write this into it
mkdir -p bun mkdir -p bun/include mkdir -p bun/include/JavaScriptCore cp cmakeconfig.h bun/include/ find JavaScriptCore/Headers/JavaScriptCore/ -name "*.h" -exec cp {} bun/include/JavaScriptCore/ \; find JavaScriptCore/PrivateHeaders/JavaScriptCore/ -name "*.h" -exec cp {} bun/include/JavaScriptCore/ \; cp -r bmalloc/Headers/bmalloc bun/include/ cp -r WTF/Headers/wtf bun/include/wtf/ mkdir -p bun/Source/JavaScriptCore/ cp -r ../../Source/JavaScriptCore/Scripts bun/Source/JavaScriptCore cp ../../Source/JavaScriptCore/create_hash_table bun/Source/JavaScriptCore echo "Copying fat libJavaScriptCore.a" mv lib bun/ for i in libicui18n.a libicutest.a libicuuc.a libicudata.a libicuio.a libicutu.a; do cp "/usr/local/lib/${i}" bun/lib/ done rm -f bun/lib/*.so
Both are shell scripts, make them executable with
chmod +x
- Change directory into
WebKit
and run~/webkit.sh
- Change directory into
WebKitBuild/Debug
and runninja jsc
This way you'll build webkit for bun
- While being in the directory run
~/webkitbuninstall.sh
- Once the script has done executing run
cp -r bun ~/bun-webkit
- Now you have built WebKit used by bun, feel free to remove
WebKit
- In your home directory create
- Building Zig
- Change directory into
zig
and create directorybuild
- Change directory into
build
and run
cmake .. -DZIG_STATIC_LLVM=ON -DCMAKE_PREFIX_PATH="/usr/local/llvm17;/usr/local"
- Compile zig using
make
- Once zig is compiled, run
make install
and zig should be installed insidestage3
directory - Run command
echo $PATH
if it contains something like/home/bun/bin
, you are on good track
If it does not contain the directory, run this command
echo 'export PATH="$PATH:$HOME/bin"' >> "~/.bashrc"
and then run. ~/.bashrc
- Create directory
~/bin
and copybin
andlib
fromstage3
into~/bin/
- Change directory into
~/bin/
and runln -s bin/zig zig
- Now by running
zig version
you should see something like0.12.0-dev.1646+4e212f165
This is not exact version bun needs bun it can compile with it Now if you want to save space, get rid of
zig
source code - Change directory into
- Building Bun
- Change directory into
bun
and rungit checkout Bun-BSD/freebsd-port
- Execute
./scripts/setup.sh
- Execute
gmake node-fallbacks && gmake all-js
- Execute
pushd ~/codegen/ && tar xf codegen.tar && popd
- Configure cmake with this command
cmake -S . -G Ninja -B build -DCMAKE_BUILD_TYPE=Debug -DNO_CODEGEN=1 -DUSE_DEBUG_JSC=1 -DCMAKE_CXX_COMPILER="clang++16" -DCMAKE_C_COMPILER="clang16" -DCMAKE_EXE_LINKER_FLAGS="-L /usr/local/lib/gcc13/ -L /usr/local/lib/ -lsysinfo -Wl,-undefined,error" -DCMAKE_CXX_FLAGS="-I /usr/local/include/"
- Execute
cp -r ~/codegen/build-codegen-freebsd-x64/* build/
- Execute
ninja -C build
and when it starts to compile zig code, interrupt it withctrl + c
- Execute
rm -rf build/bun-webkit/ && cp -r ~/bun-webkit/ build/bun-webkit
Now you should have our custom built webkit
- Now just run
ninja -C build
and everything should compile fine
- Change directory into
Now you should have bun
binary in build/bun-debug
If I missed something or made mistake, tell me