在中国安装Rust的注意事项

From Rust Community Wiki
This page is a translated version of the page Rust installation special notes in China and the translation is 89% complete.

为什么?

Generally speaking, there's some strict auditing of Internet traffic in China, both on the content providers' side and service providers' side. None of Rust's major hosting services(rust-lang.org, crates.io, docs.rs, etc) can be classified as trusted here, since there isn't a representative legal body (like a company) participating the audition. These services are not banned either, since they're mostly technical content instead of arbitrary content (like what Google provides). So the actual use experiences will actually vary according to the ISPs in use. If you're working inside technical oriented offices, these services will generally work ok, but there could be connectivity issues now and then. If you're working from home, there's a chance that these services are almost entirely unusable.

怎么做?

One way is to purchase some oversea proxy, if the proxy server is somehow classified more "trusted", the connectivity will be better. Usually it's not expensive to do so. However strictly speaking, this can be interpreted as illegal behavior.

Fortunately, there're other choices. The most useful ones are mirroring service. They provide mirrors to linux distros, homebrew and macports, and so on, for free. Some of them have also been providing Rust mirroring service since Rust has been becoming more popular. Most of the mirrors are provided and maintained by university campus technical leagues. They usually have great bandwidth, but have higher failure rates than the official service, so you'll want to make use of multiple services of them, and switch to another if one of them become unusable.

一些推荐的选择

环境变量

RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static

.cargo/config

[source.crates-io]
replace-with = 'ustc'

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

环境变量

RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup

.cargo/config

[source.crates-io]
replace-with = 'tuna'

[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"

环境变量

RUSTUP_UPDATE_ROOT=https://mirrors.sjtug.sjtu.edu.cn/rust-static/rustup
RUSTUP_DIST_SERVER=https://mirrors.sjtug.sjtu.edu.cn/rust-static

.cargo/config

[source.crates-io]
replace-with = 'sjtu'

[source.sjtu]
registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"