This document describes building Rust from source. This is not recommended if you don’t know what you’re doing. If you just want to install Rust, check out the official installation guide.
Prerequisites
Before you begin, ensure you have the necessary tools installed on your system.Core Dependencies
All platforms require these basic tools:C Compiler
When building for the host,
cc is sufficient. Cross-compiling may need additional compilersCargo Dependencies
To build Cargo, you’ll also need OpenSSL:- Debian/Ubuntu:
libssl-dev - Fedora/RHEL:
openssl-devel - macOS: Included by default
LLVM Build Tools (Optional)
Required tools if building LLVM from source:- C++ Compiler:
g++,clang++, or MSVC (see LLVM requirements) - Build System:
ninja(recommended, especially on Windows) or GNUmake3.81+ - CMake: Version per LLVM documentation
- Linux Only:
libstdc++-static(Fedora, Ubuntu)
Platform-Specific Setup
- Unix-like (Linux/macOS)
- Windows (MSVC)
- Windows (MinGW)
Clone the Repository
Configure the Build
The interactive setup is recommended for new contributors:- Selecting a config profile (user, compiler, library, etc.)
- Setting up LSP for your editor
- Configuring Git hooks
- Other development preferences
Advanced: Using the configure script
Advanced: Using the configure script
For complex configurations, use the This generates a
configure script:bootstrap.toml file with your settings.Build and Install
./x.py install will place several programs into $PREFIX/bin:rustc: The Rust compilerrustdoc: The API documentation toolcargo: The package manager (unless disabled with--set build.extended=false)
The Build System: x.py
The Rust build system uses a Python script calledx.py to build the compiler and manage the bootstrapping process.
Basic Usage
Configuration Files
The build system looks forbootstrap.toml in the project root. You can also specify a custom config:
Common Build Profiles
The./x.py setup command offers several profiles:
| Profile | Description | Use Case |
|---|---|---|
| user | Basic profile for trying out changes | Casual contributors |
| compiler | Optimized for compiler development | Working on rustc |
| library | Optimized for std library work | Standard library development |
| dist | Full build with all tools | Creating distributions |
Building Documentation
To build the documentation:doc in the build directory for your target ABI. For example, if the ABI is x86_64-pc-windows-msvc, the directory will be build/x86_64-pc-windows-msvc/doc.
Specifying Build Targets
You can specify the target triple using:bootstrap.toml:
Available Windows Build Triples
GNU ABI (using GCC):i686-pc-windows-gnux86_64-pc-windows-gnu
i686-pc-windows-msvcx86_64-pc-windows-msvc
Bootstrap Process
Since the Rust compiler is written in Rust, it must be built by a precompiled “snapshot” version of itself (made in an earlier stage of development). As such, source builds require an Internet connection to fetch snapshots.
Optimizing Build Times
Use CI LLVM
Set
llvm.download-ci-llvm = true to download pre-built LLVM instead of building itReduce Debuginfo
Set
rust.debuginfo-level = 1 for faster builds with basic debugging capabilityUse Incremental
Set
rust.incremental = true to enable incremental compilationLimit Codegen Units
Set
rust.codegen-units = 0 to use the default (faster builds, slower runtime)Next Steps
Learn the Workflow
Now that your environment is set up, learn how to make contributions and submit changes