This guide covers the essentials of developing the Rust compiler itself, from understanding its architecture to building and testing your changes.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/rust-lang/rust/llms.txt
Use this file to discover all available pages before exploring further.
Compiler Architecture
The Rust compiler is organized into multiple crates, each handling specific compilation phases:rustc_driver
Orchestrates the compilation process and knits together code from other crates
rustc_ast
Abstract Syntax Tree representation and parsing
rustc_hir
High-level Intermediate Representation after AST lowering
rustc_middle
Core type system and middle-stage representations
rustc_codegen_*
Code generation backends (LLVM, Cranelift, GCC)
rustc_borrowck
Borrow checker implementation
Setting Up Your Development Environment
Configure your build
Create a
config.toml file in the root directory:- Development Profile
- Library Profile
- Performance Profile
Bootstrap Build System
The Rust compiler uses a multi-stage bootstrap process:Build Stages Explained
Stage 0 - Bootstrap Compiler
Stage 0 - Bootstrap Compiler
The stage 0 compiler is downloaded from Rust’s CI. This is a pre-built stable or beta compiler used to bootstrap your build.Location:
build/x86_64-unknown-linux-gnu/stage0/Stage 1 - First Build
Stage 1 - First Build
Stage 1 is built using the stage 0 compiler. This includes your changes and is suitable for most development work.Location:
build/x86_64-unknown-linux-gnu/stage1/Use case: Testing library changes, running the compiler with your modificationsStage 2 - Self-hosting
Stage 2 - Self-hosting
Stage 2 is built using the stage 1 compiler. This ensures your compiler can compile itself.Location:
build/x86_64-unknown-linux-gnu/stage2/Use case: Validating compiler changes, running the full test suiteCommon Build Commands
Using x.py
Thex.py script is the main entry point for building and testing:
Directory Structure
Working with Compiler Crates
Adding a New Compiler Crate
Compilation Phases
Understanding the compilation pipeline helps when working on specific components:Configuration Options
Important build.toml Settings
- LLVM Options
- Rust Options
- Build Options
Development Workflow
Typical Development Cycle
- Make your changes to compiler crates
- Quick check with
./x.py check - Build stage 1 with
./x.py build --stage 1 - Run targeted tests with
./x.py test tests/ui/my-feature - Run full test suite before submitting
Speeding Up Development
Use --keep-stage
Use check instead of build
Download pre-built artifacts
Set
download-ci-llvm = true and download-rustc = "if-unchanged"Incremental compilation
Compiler Queries
The Rust compiler uses a query-based architecture for on-demand computation:Key Concepts
- Queries are cached, on-demand computations
- Incremental compilation tracks query dependencies
- Query results are memoized between compilations
- Defined in
rustc_middle/src/query/mod.rs
Resources
Rustc Dev Guide
Comprehensive guide to compiler internals
Zulip Chat
Get help from the compiler team
Forge
Infrastructure and process documentation
GitHub Issues
Track bugs and feature requests
Next Steps
Library Development
Learn about developing the standard library
Debugging
Debug compiler issues and crashes
Profiling
Profile and optimize compiler performance