Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Research identified these common failure points:
| [build-debootstrap](linux/build-debootstrap/) | Linux | Partial (0.7) | Claude Opus 4.5 |
| [build-livebuild](linux/build-livebuild/) | Linux | Partial (0.6) | Claude Opus 4.5 |
| [benchmark](linux/benchmark/) | Linux | Success (1.0) | Claude Opus 4.5 |
| [build-bunjs](runtimes/build-bunjs/) | Runtimes | Partial (0.6) | Claude Opus 4.5 |

## Contributing Experiments

Expand Down
78 changes: 78 additions & 0 deletions runtimes/build-bunjs/EXPERIMENT.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: "Building Bun from Source"
id: build-bunjs
category: build
status: partial

agent:
model: claude-opus-4-5
sessions: 1
total_duration_hours: 0.75
active_duration_hours: 0.5

task:
description: "Build the Bun JavaScript/TypeScript runtime from source"
initial_prompt: "Build Bun from source, experimenting with the llm-builds-linux benchmark approach"
difficulty: hard
estimated_steps: 100

results:
success: false
partial_score: 0.6
artifacts:
- "Dockerfile"
- "build.sh"
key_metrics:
build_steps_completed: 205
build_steps_total: 632
completion_percentage: 32
dependencies_resolved: 20
js_modules_bundled: 136
docker_image_size_gb: 8
cmake_configure_success: true
cpp_compilation_started: true
zig_compilation_failed: true

# No cost data available for this experiment
cost: null

human_intervention:
count: 0
critical: false
details: []

findings:
successes:
- "Successfully set up Docker build environment with LLVM 19, Rust 1.92, Go 1.22, CMake, Ninja"
- "Resolved Cargo.lock v4 version issue by switching from apt Rust to rustup"
- "CMake configuration completed successfully with 632 build targets"
- "Downloaded and built 20+ external dependencies (lolhtml, brotli, zstd, sqlite, boringssl, c-ares, libarchive)"
- "JavaScript module bundling completed (1780kb, 136 modules for bake runtime)"
- "C/C++ compilation progressed to step 205/632 (~32%)"
- "All Rust dependencies compiled successfully with nightly-2025-12-10 toolchain"
failures:
- "Zig compiler (0.15.2) failed with 'command terminated unexpectedly'"
- "Target aarch64-linux-gnu.2.26 with -mcpu cortex_a35 causes crash"
- "Error occurs during 'zig build-obj' for bun-debug target with AddressSanitizer"
- "Root cause: Zig LLVM backend issues on Apple Silicon Docker (ARM64)"
lessons:
- "Rust version from apt (1.75) is too old for Cargo.lock v4 - must use rustup (1.78+)"
- "Zig build fails on ARM64 Docker - may need native x86_64 or native ARM64 hardware"
- "Building Bun requires Bun itself (bootstrapping problem - cannot build without existing binary)"
- "LLVM version must exactly match WebKit precompiled version (LLVM 19)"
- "Build has 632 steps with complex parallelism - Zig, C++, Rust compile simultaneously"
- "Build time to failure: ~7 minutes (CMake config + dependency download + partial compilation)"
- "AddressSanitizer is enabled by default in debug builds and may contribute to instability"

references:
docs:
- "https://bun.sh/docs/project/contributing"
- "https://github.com/oven-sh/bun"

tags:
- javascript-runtime
- zig
- llvm
- docker
- arm64
- webkit
- bootstrapping
118 changes: 118 additions & 0 deletions runtimes/build-bunjs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# Building Bun from Source

Can an AI agent build Bun (the JavaScript/TypeScript runtime) from source?

## Overview

| Metric | Value |
|--------|-------|
| Agent | Claude Opus 4.5 |
| Duration | ~1 hour |
| Sessions | 1 |
| Outcome | **PARTIAL (0.6)** - Environment setup complete, build progressed 205/632 steps (32%) before Zig compiler issues |
| Difficulty | Hard |

## Task

Build the Bun JavaScript runtime from source. Bun is written in Zig and powered by JavaScriptCore (WebKit's JS engine). This is a complex build task because:

1. **Multiple languages**: Zig, C++, TypeScript, Rust, and Go
2. **Heavy dependencies**: LLVM 19, WebKit/JSC, BoringSSL, lolhtml, numerous system libraries
3. **Bootstrapping problem**: Building Bun requires an existing Bun binary
4. **Large codebase**: ~10GB for repo + build artifacts
5. **Long build times**: Debug builds take ~6 minutes for Zig compilation alone

## Results Summary

### What Succeeded

- Docker environment setup with all dependencies (LLVM 19, Rust, Go, Ruby, CMake, Ninja)
- Repository clone and Bun bootstrapping
- CMake configuration completed successfully
- Downloaded and configured 20+ dependency libraries (lolhtml, brotli, zstd, highway, etc.)
- JavaScript module bundling completed (1780kb, 136 modules)
- C/C++ compilation of ~200+ source files before failure
- All Rust dependencies (lolhtml) compiled successfully
- All C dependencies (zstd, sqlite, boringssl, c-ares, libarchive) compiled
- Build progressed to step 205/632 (~32% complete)

### Where It Failed

1. **Cargo.lock version issue** (resolved): Initial failure due to Rust version too old for Cargo.lock v4 format
2. **Zig compilation failure**: The Zig compiler (`zig build-obj`) terminated unexpectedly when targeting `aarch64-linux-gnu.2.26` with `-mcpu cortex_a35`
3. **Root cause**: CPU architecture detection issues in Docker ARM64 emulation environment

## Build Requirements

### System Dependencies

**Linux (Ubuntu/Debian)**:
```bash
sudo apt install curl wget lsb-release software-properties-common \
cmake git golang libtool ninja-build pkg-config ruby-full xz-utils

# MUST install Rust via rustup (not apt) for Cargo.lock v4 support
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
```

**LLVM 19** (required to match WebKit):
```bash
wget https://apt.llvm.org/llvm.sh -O - | sudo bash -s -- 19 all
```

### Key Requirements

- ~10GB disk space
- Bun already installed (bootstrapping)
- LLVM 19 specifically (must match WebKit version)
- Rust 1.78+ (for Cargo.lock version 4 support)
- Zig (auto-installed by build scripts)

## Challenges Discovered

1. **Rust version sensitivity**: Ubuntu 24.04's default Rust 1.75 is too old. Cargo.lock v4 format requires Rust 1.78+
2. **CPU architecture detection**: Zig's `-mcpu native` fails in Docker emulation environments
3. **Massive dependency tree**: 20+ external libraries must be fetched and built
4. **Build parallelism**: 632 build steps with complex interdependencies
5. **Memory requirements**: Zig compilation is memory-intensive, may OOM in constrained environments

## Files

```
artifacts/
├── Dockerfile # Build environment (Ubuntu 24.04 + LLVM 19 + Rust via rustup)
├── build.sh # Orchestration script with timeout handling
trajectories/
├── SUMMARY.md
└── session-build.jsonl
```

## Quick Start

```bash
# Build the Docker image (~10 min)
docker build -t bun-build -f artifacts/Dockerfile .

# Run the build (will progress ~32% before Zig issues on emulated ARM64)
docker run --rm bun-build
```

## Key Learnings for Agent Evaluation

1. **Dependency version mismatches are common** - Agents need to diagnose and fix version issues (e.g., Cargo.lock v4 requiring newer Rust)
2. **Build environment matters** - Docker emulation may cause architecture-specific failures
3. **Partial progress is valuable** - Reaching 32% of a 632-step build demonstrates significant capability
4. **Bootstrapping is a real blocker** - You literally cannot build Bun without Bun
5. **Multi-language builds are complex** - Zig, C++, Rust, and TypeScript all compile in parallel with interdependencies

## Recommended Improvements for Future Attempts

1. Use native hardware (not Docker emulation) for ARM64 builds
2. Try x86_64 build instead of ARM64
3. Pre-download WebKit/JSC to avoid network delays
4. Consider using Bun's official devcontainer configuration

## References

- [Bun Contributing Guide](https://bun.sh/docs/project/contributing)
- [Bun GitHub Repository](https://github.com/oven-sh/bun)
84 changes: 84 additions & 0 deletions runtimes/build-bunjs/artifacts/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Dockerfile for building Bun from source
# Based on official Bun contributing documentation
# https://bun.sh/docs/project/contributing

FROM ubuntu:24.04

# Prevent interactive prompts
ENV DEBIAN_FRONTEND=noninteractive

# Install base dependencies
RUN apt-get update && apt-get install -y \
build-essential \
curl \
wget \
lsb-release \
software-properties-common \
git \
cmake \
ninja-build \
pkg-config \
libtool \
xz-utils \
unzip \
python3 \
python3-pip \
golang \
ruby-full \
ccache \
gnupg \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*

# Install GCC 11+ for C++20 support (required for 'span' header)
RUN apt-get update && apt-get install -y gcc-11 g++-11 && \
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100 && \
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100 && \
rm -rf /var/lib/apt/lists/*

# Install LLVM 19 (MUST match WebKit version)
RUN wget https://apt.llvm.org/llvm.sh && \
chmod +x llvm.sh && \
./llvm.sh 19 all && \
rm llvm.sh && \
rm -rf /var/lib/apt/lists/*

# Add LLVM 19 to PATH
ENV PATH="/usr/lib/llvm-19/bin:${PATH}"
ENV CC=clang-19
ENV CXX=clang++-19

# Install Rust via rustup (needed for lolhtml and other Rust dependencies)
# The default Ubuntu rustc is too old for some Cargo.lock files
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"

# Install Bun (required for bootstrapping - you can't build Bun without Bun)
RUN curl -fsSL https://bun.com/install | bash
ENV PATH="/root/.bun/bin:${PATH}"

# Create work directory
WORKDIR /build

# Clone Bun repository with full history (needed for submodules and cargo lock files)
# Note: This is a large clone (~1GB+), but shallow clones break submodule dependencies
RUN git clone https://github.com/oven-sh/bun.git bun

WORKDIR /build/bun

# Initialize submodules - needed for dependencies like lolhtml
RUN git submodule update --init --recursive

# Setup environment
ENV BUN_INSTALL="/root/.bun"
ENV PATH="${BUN_INSTALL}/bin:${PATH}"

# Pre-install dependencies to avoid EEXIST errors during parallel build
RUN bun install --frozen-lockfile || bun install

# Build script
COPY build.sh /build/build.sh
RUN chmod +x /build/build.sh

# Default command - run the build
CMD ["/build/build.sh"]
77 changes: 77 additions & 0 deletions runtimes/build-bunjs/artifacts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/bash
# Build Bun from source
# This script is meant to be run inside the Docker container

set -e

echo "=========================================="
echo "Building Bun from Source"
echo "=========================================="

cd /build/bun

# Verify prerequisites
echo ""
echo "Checking prerequisites..."
echo "- Bun version: $(bun --version)"
echo "- Clang version: $(clang-19 --version | head -1)"
echo "- CMake version: $(cmake --version | head -1)"
echo "- Ninja version: $(ninja --version)"
echo "- Go version: $(go version)"
echo "- Rust version: $(rustc --version)"

echo ""
echo "Disk space:"
df -h /build

echo ""
echo "=========================================="
echo "Starting build process..."
echo "=========================================="

# Run the build
# This will:
# 1. Clone submodules
# 2. Download/install Zig (automatically)
# 3. Build dependencies
# 4. Compile Bun

echo ""
echo "Running: bun run build"
echo "This will take a while..."
echo ""

# Set timeout for very long builds (2 hours)
timeout 7200 bun run build || {
exit_code=$?
if [ $exit_code -eq 124 ]; then
echo "ERROR: Build timed out after 2 hours"
exit 1
fi
echo "ERROR: Build failed with exit code $exit_code"
exit $exit_code
}

echo ""
echo "=========================================="
echo "Build completed!"
echo "=========================================="

# Verify the build
if [ -f "./build/debug/bun-debug" ]; then
echo ""
echo "Debug binary created successfully!"
echo "Version: $(./build/debug/bun-debug --version)"
echo "Size: $(ls -lh ./build/debug/bun-debug | awk '{print $5}')"
echo ""
echo "Running quick sanity test..."
./build/debug/bun-debug --print "console.log('Hello from Bun debug build!')"
exit 0
else
echo ""
echo "ERROR: Debug binary not found at ./build/debug/bun-debug"
echo ""
echo "Contents of ./build directory:"
ls -la ./build/ || echo "(directory doesn't exist)"
exit 1
fi
Loading