Skip to main content

ABI Selection

Windows has two prominent ABIs (Application Binary Interfaces):

MSVC ABI

Native Windows ABI
  • Used by Visual Studio
  • Best for Windows-specific development
  • Interoperates with MSVC-built libraries
  • Recommended for most users

GNU ABI

MinGW/GCC Toolchain
  • Uses GNU toolchain (GCC)
  • Better for cross-platform code
  • Interoperates with MinGW-built libraries
  • Good for Unix-style development on Windows
Choose the ABI based on which C/C++ libraries you need to interoperate with. You can build both if needed.

Available Build Triples

  • i686-pc-windows-gnu (32-bit)
  • x86_64-pc-windows-gnu (64-bit)
Specify the build triple using:
python x.py build --build=x86_64-pc-windows-msvc
Or in bootstrap.toml:
[build]
build = "x86_64-pc-windows-msvc"

Building with MSVC

1

Install Dependencies

Install required tools using winget (Windows Package Manager):
winget install -e Python.Python.3
winget install -e Kitware.CMake
winget install -e Git.Git
After installation, add CMake to your system PATH: C:\Program Files\CMake\binSee this guide for instructions on editing PATH.
2

Install Visual Studio

Install Visual Studio 2022 or later with C++ build tools:
  1. Download Visual Studio
  2. Run the installer
  3. Select “Desktop development with C++” workload
  4. Include Windows 10 or 11 SDK
Do NOT select “C++ CMake tools for Windows” under Individual Components - use the standalone CMake installed via winget instead.
Visual Studio 2019 may work but is not actively tested. Visual Studio 2022 or later is recommended.
3

Clone the Repository

git clone https://github.com/rust-lang/rust.git
cd rust
4

Configure the Build

Run the interactive setup:
python x.py setup user
Or create bootstrap.toml manually:
bootstrap.toml
[build]
build = "x86_64-pc-windows-msvc"
extended = true
tools = ["cargo", "clippy", "rustfmt"]

[llvm]
# Highly recommended - skip building LLVM
download-ci-llvm = true
5

Build Rust

Open a Command Prompt or PowerShell and run:
python x.py build
The first build can take 30 minutes to several hours depending on your hardware.

Troubleshooting MSVC Builds

If bootstrap doesn’t detect your Visual Studio version, manually call the vcvars script:
CALL "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
python x.py build
For Visual Studio 2019:
CALL "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
python x.py build
Several tips to improve build speed:
  1. Disable Windows Defender Real-Time Protection (temporarily)
    • Note: It will re-enable automatically after some time
  2. Use native Windows Python instead of MSYS2 Python
    • Can help with LLVM build issues
  3. Use Git for Windows instead of MSYS2 Git
    • Often much faster for git operations
  4. Download pre-built LLVM:
    [llvm]
    download-ci-llvm = true
    
If you encounter linker errors, ensure:
  1. Visual Studio is properly installed with C++ tools
  2. Windows SDK is installed
  3. You’re running from a Visual Studio command prompt, or vcvars is called

Building with MinGW (MSYS2)

1

Install MSYS2

  1. Download the latest MSYS2 installer
  2. Run the installer and follow the instructions
  3. Complete the installation to C:\msys64 (default)
2

Install Git for Windows

Download and install Git for Windows:
  1. Install Git for Windows
  2. Ensure it’s in your Windows PATH
  3. Edit C:\msys64\mingw64.ini (or mingw32.ini for 32-bit)
  4. Uncomment: MSYS2_PATH_TYPE=inherit
You could use MSYS2’s git via pacman, but it’s very slow and not recommended.
3

Install Build Tools

Start a MINGW64 or MINGW32 shell (from start menu or by running C:\msys64\mingw64.exe).Update package mirrors:
pacman -Sy pacman-mirrors
Install build tools:
pacman -S make \
  diffutils \
  tar \
  mingw-w64-x86_64-python \
  mingw-w64-x86_64-cmake \
  mingw-w64-x86_64-gcc \
  mingw-w64-x86_64-ninja
Do NOT use the python2, cmake, and ninja packages from the msys2 subsystem. Use the mingw-w64-* versions instead. Builds are known to fail with msys2 subsystem packages.
4

Clone and Build

In the MINGW64/MINGW32 shell:
# Clone (or navigate to existing clone)
git clone https://github.com/rust-lang/rust.git
cd rust

# Setup and build
python x.py setup dist
python x.py build
python x.py install

MinGW Build Tips

If you experience issues with LLVM builds, try using native Windows Python and CMake:
  1. Install Python and CMake for Windows (via winget)
  2. Remove them from the pacman command above
  3. Ensure Windows Python/CMake are in PATH (following step 2’s MSYS2_PATH_TYPE setting)

Advanced Configuration

Build for both MSVC and GNU targets:
bootstrap.toml
[build]
build = "x86_64-pc-windows-msvc"
target = [
  "x86_64-pc-windows-msvc",
  "x86_64-pc-windows-gnu",
]
Build with:
python x.py build --target x86_64-pc-windows-gnu
bootstrap.toml
[build]
build = "x86_64-pc-windows-msvc"
extended = true
tools = ["cargo", "clippy", "rustfmt", "rust-analyzer"]

# Use all CPU cores
jobs = 0

[llvm]
# Download instead of building
download-ci-llvm = true

# If building LLVM, use Ninja
ninja = true

[rust]
channel = "dev"
debug-assertions = true

# Enable incremental compilation
incremental = true
To use GNU ABI from PowerShell or MSVC ABI from MINGW:
# From any environment
python x.py build --build=x86_64-pc-windows-gnu
# or
python x.py build --build=x86_64-pc-windows-msvc

Building Documentation

Build Rust documentation:
python x.py doc
Documentation will be generated in:
build\x86_64-pc-windows-msvc\doc
Or for GNU builds:
build\x86_64-pc-windows-gnu\doc

Testing Your Build

python x.py check

Common Issues

Ensure Python is in your PATH:
# Check Python
python --version

# If not found, add to PATH or use full path
C:\Python312\python.exe x.py build
Update submodules:
git submodule update --init --recursive
Windows has a 260-character path limit by default. Enable long paths:
  1. Run as Administrator:
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" `
  -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force
  1. Or use Group Policy Editor (gpedit.msc):
    • Computer Configuration → Administrative Templates → System → Filesystem
    • Enable “Enable Win32 long paths”
Reduce parallel jobs:
python x.py build -j 1
Or limit LLVM linker jobs:
[llvm]
link-jobs = 1

Next Steps

Configuration Options

Explore all available build configuration options

Dependencies Reference

Detailed dependency information

Build docs developers (and LLMs) love