Skip to content

Rust ​

构建工具 ​

Windows 推荐 MSVC 工具链。先安装 Visual Studio Build Tools,工作负载勾选「使用 C++ 的桌面开发」。

已安装 Visual Studio 且包含该工作负载时可跳过。

rustup ​

通过 WinGet 安装:

powershell
winget install --id Rustlang.Rustup --source winget

或从 rustup.rs 下载 rustup-init.exe,按默认选项安装 MSVC 工具链。

安装完成后重新打开终端。工具链位于 %USERPROFILE%\.cargo\bin,安装程序会写入用户 Path。

验证:

powershell
rustc --version
cargo --version
rustup --version
rustup 常用命令
powershell
# 查看当前工具链
rustup show

# 更新工具链
rustup update

# 安装指定工具链
rustup toolchain install nightly

# 设置默认工具链
rustup default stable

# 添加编译目标
rustup target add x86_64-pc-windows-msvc

# 安装组件
rustup component add rust-analyzer rustfmt clippy

Git Bash ​

用户 Path 已包含 .cargo\bin 时,Git Bash 可直接使用。否则:

bash
source "$HOME/.cargo/env"

镜像 ​

国内拉取工具链或 crates 不稳定时,使用 rsproxy。

写入 PowerShell 配置文件:

powershell
$env:RUSTUP_DIST_SERVER = "https://rsproxy.cn"
$env:RUSTUP_UPDATE_ROOT = "https://rsproxy.cn/rustup"

已安装 rustup 时执行 rustup update 即可改走镜像。

%USERPROFILE%\.cargo\config.toml:

toml
[source.crates-io]
replace-with = "rsproxy-sparse"

[source.rsproxy]
registry = "https://rsproxy.cn/crates.io-index"

[source.rsproxy-sparse]
registry = "sparse+https://rsproxy.cn/index/"

[registries.rsproxy]
index = "https://rsproxy.cn/crates.io-index"

[net]
git-fetch-with-cli = true

基于 MIT 许可发布