This page provides technical details for setting up a local development environment, building Bun from source, and participating in the development workflow. Bun is primarily written in Rust (the core runtime, bundler, and package manager), with C++ for JavaScriptCore (JSC) integration, and TypeScript for built-in modules and type definitions CLAUDE.md1-2 CLAUDE.md110-115
Building Bun requires approximately 10GB of free disk space for the repository and build artifacts CONTRIBUTING.md1
rust-toolchain.toml. The build scripts use rustup to manage this CONTRIBUTING.md47-51Sources: CONTRIBUTING.md1-125 CLAUDE.md1-2 rust-toolchain.toml1-10
Bun utilizes a custom TypeScript-based build orchestration system that generates build.ninja files. The scripts in scripts/build/ describe the build, while Ninja performs the actual compilation and linking scripts/build/CLAUDE.md1-4
The build is controlled by a flat Config struct resolved at configure-time scripts/build/config.ts73-176 Compiler and linker flags are managed in scripts/build/flags.ts, which uses a flat table with predicates to determine when a flag is applied scripts/build/flags.ts4-40
The primary entry point for developers is the bd (Build Debug) package script CLAUDE.md7-16
| Command | Action | Output Path |
|---|---|---|
bun bd | Incremental debug build | ./build/debug/bun-debug CLAUDE.md8 |
bun run build | Full debug build (clones submodules) | ./build/debug/bun-debug CONTRIBUTING.md156-159 |
bun run build:release | Optimized release build | ./build/release/bun CLAUDE.md23 |
bun run build:local | Debug build using local WebKit source | ./build/debug/bun-debug CLAUDE.md24 |
The following diagram illustrates the relationship between source entities and the build process.
"Development Workflow and Code Entities"
Sources: CLAUDE.md110-115 CONTRIBUTING.md156-163 scripts/build/bun.ts1-40 scripts/build/rust.ts1-25
The CLAUDE.md file contains instructions for AI assistants. A critical rule is build-then-exec: any bun run build* command accepts trailing arguments passed to the built executable, ensuring you always test the newly built binary CLAUDE.md18-25
VSCode is the recommended IDE. Configuration is provided in .vscode/settings.json and .vscode/launch.json.
rust-analyzer, clangd, and CodeLLDB .vscode/extensions.json4-13Cargo.toml and pinned nightly toolchain CONTRIBUTING.md168-170CodeLLDB with the provided launch configurations .vscode/launch.json14-107./build/debug to your $PATH to use bun-debug globally CONTRIBUTING.md172-176BUN_DEBUG_<scope>=1. Use BUN_DEBUG_QUIET_LOGS=1 to suppress non-explicit logs CONTRIBUTING.md194BUN_JSC_validateExceptionChecks=1 and BUN_JSC_dumpSimulatedThrows=1 CLAUDE.md13-14BUN_GARBAGE_COLLECTOR_LEVEL=2 forces GC to run after every expect() in tests .vscode/launch.json3Sources: CONTRIBUTING.md166-202 CLAUDE.md13-25 .vscode/launch.json1-107
Bun's test suite is extensive and organized by module. Tests are written in TypeScript using bun:test CLAUDE.md69
| Path | Description |
|---|---|
test/js/bun/ | Bun-specific API tests (HTTP, SQL, Shell, FFI) CLAUDE.md53 |
test/js/node/ | Node.js compatibility suite CLAUDE.md54 |
test/js/web/ | Web API standards (Fetch, WebSocket, Streams) CLAUDE.md55 |
test/cli/ | CLI command behavior (Install, Run, Build) CLAUDE.md56 |
test/bundler/ | Transpiler and Linker logic CLAUDE.md57 |
test/regression/ | Reproductions for specific GitHub issues CLAUDE.md62 |
Tests rely on the harness module for reproducible environments and utility functions like bunExe(), bunEnv, and tempDir() test/CLAUDE.md28-33 test/CLAUDE.md186-196
"Testing Entity Mapping"
Sources: CLAUDE.md53-66 test/CLAUDE.md28-143
bun test directly: Use bun bd test <file> to ensure your local changes are included in the binary being tested CLAUDE.md11 test/CLAUDE.md15port: 0 to prevent collisions CLAUDE.md100 test/CLAUDE.md21setTimeout: Tests should await conditions, not time passing CLAUDE.md105 test/CLAUDE.md21test/no-validate-leaksan.txt test/no-validate-leaksan.txt1-150USE_SYSTEM_BUN=1 and pass with the debug build to ensure the test is valid CLAUDE.md106Sources:
Refresh this wiki
This wiki was recently refreshed. Please wait 3 days to refresh again.