如何防止 Cargo 自动尝试下载更新版本的编译器?

How can I prevent Cargo from automatically trying to download a newer version of the compiler?

我需要编译旧版本的 Parity,它只能使用 1.28 版的 Rust 编译器进行编译。要安装旧版本,我这样做了:

rustup.sh -y --default-toolchain 1.28.0

这似乎有效:

root@2afa3b8dc256:/build# cargo --version
cargo 1.28.0 (96a2c7d16 2018-07-13)
root@2afa3b8dc256:/build# rustc --version
rustc 1.28.0 (9634041f0 2018-07-30)

当我尝试编译项目时,它会立即尝试下载新版本的编译器:

root@2afa3b8dc256:/parity# cargo build --all
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
320.1 KiB / 320.1 KiB (100 %) 271.0 KiB/s ETA:   0 s                
info: latest update on 2018-11-08, rust version 1.30.1 (1433507eb 2018-11-07)
info: downloading component 'rustc'

如何防止 Cargo 这样做?

您可以使用rustup override为特定目录指定使用的工具链版本。例如:

rustup override set 1.28.0