Overview
The bootstrap build system is the foundation of Rust compiler development. It orchestrates the multi-stage compilation process, manages dependencies, and coordinates the build of the compiler, standard library, and tooling.Architecture
The bootstrap system is primarily implemented in Rust and lives insrc/bootstrap/. It uses Cargo for individual component builds but handles the orchestration of multiple stages, artifact copying, and cross-compilation.
Key Components
Entry Points
x(Unix)x.ps1(Windows)x.py(cross-platform)
Build System
- Bootstrap binary (Rust)
- Stage management
- Artifact orchestration
Build Phases
Bootstrap progresses through several distinct phases when building the compiler:Phase 1: Entry Point Execution
The entry point script performs initial setup:Download Stage0
Downloads the stage0 compiler and Cargo binaries from CI artifacts or distribution servers.
Phase 2: Configuration & Sanity Checks
Bootstrap performs validation before building:Phase 3: Multi-Stage Compilation
The compiler is built through multiple stages:Stage 0: Downloaded Compiler
Stage 0: Downloaded Compiler
The stage0 compiler is downloaded from CI. This is a stable, pre-built compiler used to bootstrap the build process.Location:
build/x86_64-unknown-linux-gnu/stage0/Purpose: Build the stage1 compiler and librariesStage 1: Initial Build
Stage 1: Initial Build
The stage1 compiler is built using stage0:
- Stage0 compiler builds stage1 compiler
- Stage1 compiler links against stage0 standard library
- Stage1 compiler then builds stage1 standard library
build/x86_64-unknown-linux-gnu/stage1/Purpose: Build the stage2 compiler (the “real” compiler)Stage 2: Production Build
Stage 2: Production Build
The stage2 compiler is the primary output:
- Stage1 compiler builds stage2 compiler
- Stage2 compiler links against stage1 standard library
- This is typically what gets distributed
build/x86_64-unknown-linux-gnu/stage2/Purpose: Final compiler artifacts for distribution or testingStage 3+: Verification (Optional)
Stage 3+: Verification (Optional)
Additional stages can be built for verification:
- Verifies reproducibility
- Compares stage2 and stage3 outputs
- Used in release process
build.full-bootstrap = trueDirectory Structure
Bootstrap organizes all build artifacts under thebuild/ directory:
Stage Artifacts
Each stage produces specific artifacts:Contains the rustc binary and supporting files:
bin/rustc- The compiler executablelib/rustlib/- Target-specific librarieslib/librustc_driver.so- Compiler driver library
Standard library and core components:
lib/libstd.rlib- Standard librarylib/libcore.rlib- Core librarylib/liballoc.rlib- Allocation librarylib/libproc_macro.rlib- Procedural macro support
Development tools:
bin/cargo- Package managerbin/rustdoc- Documentation generatorbin/clippy-driver- Linterbin/rustfmt- Code formatter
Configuration System
Bootstrap is configured viabootstrap.toml (or config.toml for backward compatibility):
Optimization Strategies
Download CI LLVM
The most significant time-saver for development:This downloads pre-built LLVM from CI instead of building it locally, saving 30-60 minutes on first build.
Keep Stage Artifacts
Prevent recompilation of unchanged stages:Incremental Builds
Enable incremental compilation:Environment Variables
Bootstrap respects several environment variables:Path to configuration file (overrides default search)
Override the dist server for downloading stage0
Enable tracing output for bootstrap execution
Enable unstable features in bootstrap compilation
Set the target triple (note: can break bootstrap build)
Python Requirements
Bootstrap requires Python 3.6 or later:- Entry point scripts are written in Python
- Python handles initial setup and stage0 download
- Bootstrap binary itself is pure Rust
Cross-Compilation
Bootstrap supports cross-compilation with proper configuration:Parallel Execution
Control build parallelism:Troubleshooting
Clean Builds
Verbose Output
Debug Bootstrap Itself
Related Documentation
x.py Reference
Learn about x.py commands and options
Configuration Options
Explore all bootstrap.toml options