HeadlinesBriefing favicon HeadlinesBriefing.com

Bootstrapping Bun Without Binary Dependencies

Hacker News: Front Page •
×

A developer detailed building the Bun JavaScript toolkit from source without its usual binary dependencies. The effort began when Bun wasn't packaged for their Linux distro, and the official build process required a pre-existing Bun CLI binary. The author created a wrapper script to log dependency calls, revealing Bun's build scripts rely on it as a package manager, TypeScript interpreter, and bundler.

The solution involved substituting Bun's roles with other tools. For package management, the author modified `package.json` to use standard npm syntax and added a CMake option to specify an npm executable. For TypeScript interpretation, they leveraged Node.js v22.18's type stripping feature. The bundling step used esbuild, a tool whose approach Bun itself descends from, replacing `Bun.build` calls.

Challenges emerged during binary assembly. Using the upstream Zig compiler instead of Bun's fork required patching out private struct fields, a feature Bun's Zig fork added. A linker error was fixed by building a Zig static archive. The resulting binary initially failed with a cryptic 'Unexpected end of script' error during testing. This work highlights the hidden dependencies in complex toolchains and provides a path for self-hosted builds.