mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
5.1 KiB
5.1 KiB
Bun WASM Build Compilation Progress
Task: Get the WASM build of Bun to compile successfully, starting with make wasm and eventually getting JavaScript bindings to work end-to-end for extracting test blocks from bun:test files.
Environment:
- Working in
/workspacedirectory containing Bun codebase - Linux 6.8.0-1024-aws system with /usr/bin/bash shell
✅ COMPLETED ISSUES AND SOLUTIONS
1. Missing Zig Compiler
- Error: "Missing zig. Please make sure zig is in PATH"
- Solution: Downloaded and installed Zig 0.13.0 to
/opt/zigwith symlink to/usr/local/bin/zig
2. Missing Emscripten
- Error: Required for WASM compilation
- Solution: Downloaded and installed emsdk, activated latest version (4.0.10)
3. Missing mimalloc .a file
- Error:
/workspace/vendor/mimallocdirectory didn't exist - Solution: Created vendor directory, cloned specific mimalloc commit (1beadf9651a7bfdec6b5367c380ecc3fe1c40d1a), built mimalloc for WASM using emscripten
- Required: Installing ninja-build for cmake
4. Multiple Zig API Compatibility Issues in build.zig
- Fixed:
b.graph.incrementalfield removal → changed to static value - Fixed:
.pathfield in union 'Build.LazyPath' → removed .path wrapper - Fixed:
root_modulein ObjectOptions/ExecutableOptions → moved to separate assignment - Fixed:
addIncludePath→addIncludeDir - Fixed:
addFail→addSystemCommand - Fixed:
popOrNull()vspop()for ArrayList - Fixed:
bundle_ubsan_rtfield removal → commented out - Fixed:
determined_by_arch_os→determined_by_cpu_arch - Fixed:
unwind_tablesenum → boolean
5. Missing LLVM Tools
- Solution: Installed llvm-19, llvm-19-dev, llvm-19-tools, lld-19
- Created: symlink
/usr/bin/ld.lld→/usr/bin/ld.lld-19
6. Missing Generated Codegen Files
- Error: "Generated file '/workspace/build/debug/codegen/ZigGeneratedClasses.zig' is missing!"
- Solution: Used cmake to configure build system and ninja to generate required files
- Generated: Successfully created ZigGeneratedClasses.zig and other codegen files in
/workspace/build/codegen/
7. Missing bun-wasm Build Target
- Error: "no step named 'bun-wasm'"
- Solution: Added missing
bun-wasmtarget tobuild.zigthat:- Creates a WebAssembly object file using
src/main_wasm.zig - Links with mimalloc WASM object
- Installs to correct location expected by Makefile
- Creates a WebAssembly object file using
8. Codegen Path Resolution Issue
- Error: Build system looking in
/workspace/build/debug/codegen/vs actual location/workspace/build/codegen/ - Solution: Updated Makefile to pass
-Dcodegen_path=build/codegenparameter to all zig build commands
9. Variable Mutability Issues in main_wasm.zig
- Error: Variables declared as
varbut never mutated - Solution: Changed
vartoconstfor immutable variables insrc/main_wasm.zig
🚧 CURRENT STATUS
The build now successfully:
- ✅ Finds and uses correct codegen files
- ✅ Processes all translate-c steps (2459+ dependencies)
- ✅ Reaches the actual Zig compilation phase
- ❌ FAILING: Compilation due to Zig API compatibility issues
🔄 REMAINING WORK
Critical Issue: Zig API Compatibility
The build fails during compilation due to numerous Zig API changes between the version Bun was written for and Zig 0.13.0:
@minimum→@min@enumToInt→@intFromEnum@boolToInt→@intFromBool@truncateargument order changed@ptrCastsyntax changed@branchHintremoved@exportsyntax changedmem.Alignment→std.mem.Alignment
Two Possible Approaches:
Option A: Downgrade Zig (Recommended)
- Find and install the exact Zig version Bun was built with
- This would avoid the need to fix hundreds of API compatibility issues
- Check Bun's CI/build configuration for the exact version
Option B: Fix All API Compatibility Issues
- Systematically update all Zig API calls throughout the codebase
- This is a very large task affecting many files
- Higher risk of introducing bugs
🎯 NEXT STEPS
- Determine Original Zig Version: Check Bun's documentation, CI configs, or release notes for the Zig version they use
- Install Correct Zig Version: Replace Zig 0.13.0 with the version Bun expects
- Test WASM Build: Run
make wasmwith the correct Zig version - Test JavaScript Bindings: Use
node packages/bun-wasm/test/node.mjs <foo.test.ts>to verify end-to-end functionality
📁 FILES MODIFIED
build.zig: Multiple API compatibility fixes + added bun-wasm targetsrc/main_wasm.zig: Fixed variable mutability issuesMakefile: Added-Dcodegen_path=build/codegento bun-wasm build commandswasm-build-progress.md: This progress tracking document
🎉 ACHIEVEMENTS
We've successfully resolved the major build system configuration issues and created a working build pipeline. The build now processes 2459+ dependencies and reaches the compilation stage. The remaining work is primarily about Zig version compatibility, which is a well-defined and solvable issue.