每天 Shaarli

一天内的所有链接,汇聚在一个页面上。

September 24, 2024

Note: Rust开发环境在Windows下自动安装MSVC工具链并使用

静默安装msvc环境:

vs_BuildTools.exe --quiet --wait --norestart --nocache --installPath C:\BuildTools --add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Component.Windows10SDK.19041 --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --includeRecommended

能看到进度条的安装msvc环境:

vs_BuildTools.exe --passive --wait --norestart --nocache --installPath C:\BuildTools --add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Component.Windows10SDK.19041 --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --includeRecommended

查看当前使用的 Rust 工具链

rustup show active-toolchain

查看所有安装的工具链

rustup toolchain list

要使用 MSVC 工具链,你需要先安装相应的工具链。

rustup toolchain install stable-x86_64-pc-windows-msvc

切换到 MSVC 工具链

rustup default stable-x86_64-pc-windows-msvc
rustup show active-toolchain

切换到 gnu 工具链

rustup default stable-x86_64-pc-windows-gnu

为工程添加工具链

rustup target add stable-x86_64-pc-windows-gnu

使用某个工具链build

cargo build --target=stable-x86_64-pc-windows-gnu --release

在工程中查看工具链

rustup show
Note: 设置 rust 以及 rustup 使用国内源的方法

Windows

rustup set profile minimal

中国科技大学:

setx RUSTUP_DIST_SERVER "https://mirrors.ustc.edu.cn/rust-static" /M
setx RUSTUP_UPDATE_ROOT "https://mirrors.ustc.edu.cn/rust-static/rustup" /M

RsProxy.cn

setx RUSTUP_DIST_SERVER "https://rsproxy.cn" /M
setx RUSTUP_UPDATE_ROOT "https://rsproxy.cn/rustup" /M

C:\Users\Administrator.cargo\config

中国科技大学:

[source.crates-io]
registry ="https://github.com/rust-lang/crates.io-index"
replace-with = 'ustc'
​
[source.ustc]
registry = "https://mirrors.ustc.edu.cn/crates.io-index"

RsProxy.cn

[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

CentOS7

在 CentOS 7 中配置 Rust 及 Rustup 使用国内镜像,可以按照以下步骤进行:


1. 安装 Rustup 并设置 Minimal Profile

首先修用下面的命令,将安装脚本导出

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rust.sh
打开 rust.sh 脚本,将 RUSTUP_UPDATE_ROOT 修改为
RUSTUP_UPDATE_ROOT="https://mirrors.aliyun.com/rustup/rustup/"

这是用来下载 rustup-init 的, 修改后通过国内镜像下载

chmod +x ./rust.sh

最后执行修改后的rust.sh

rustup set profile minimal

2. 配置 Rustup 使用国内源

(1)中国科技大学镜像

echo 'export RUSTUP_DIST_SERVER="https://mirrors.ustc.edu.cn/rust-static"' >> ~/.bashrc
echo 'export RUSTUP_UPDATE_ROOT="https://mirrors.ustc.edu.cn/rust-static/rustup"' >> ~/.bashrc
source ~/.bashrc

(2)RsProxy.cn 镜像

echo 'export RUSTUP_DIST_SERVER="https://rsproxy.cn"' >> ~/.bashrc
echo 'export RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup"' >> ~/.bashrc
source ~/.bashrc

3. 配置 Cargo 使用国内源

编辑 ~/.cargo/config 文件:

(1)中国科技大学镜像

mkdir -p ~/.cargo
cat > ~/.cargo/config <<EOF
[source.crates-io]
registry ="https://github.com/rust-lang/crates.io-index"
replace-with = 'ustc'

[source.ustc]
registry = "https://mirrors.ustc.edu.cn/crates.io-index"
EOF

(2)RsProxy.cn 镜像

mkdir -p ~/.cargo
cat > ~/.cargo/config <<EOF
[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
EOF

4. 更新 Rust 并验证

rustup update
rustc --version
cargo --version

这套配置可以帮助你在 CentOS 7 上顺利使用国内源加速 Rust 及 Cargo 相关的操作。你可以选择 USTC 或 RsProxy 作为镜像源,二者选其一即可。