下载rust
到rust官网下载rustup
: https://www.rust-lang.org/tools/install
rustup
是一个管理 Rust 版本和相关工具的命令行工具。下载时需要联网。
运行以后提示需要安装C++ build tools
, 是否继续:
Rust Visual C++ prerequisites
Rust requires the Microsoft C++ build tools for Visual Studio 2013 or
later, but they don't seem to be installed.
The easiest way to acquire the build tools is by installing Microsoft
Visual C++ Build Tools 2019 which provides just the Visual C++ build
tools:
https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019
Please ensure the Windows 10 SDK and the English language pack components
are included when installing the Visual C++ Build Tools.
Alternately, you can install Visual Studio 2019, Visual Studio 2017,
Visual Studio 2015, or Visual Studio 2013 and during install select
the "C++ tools":
https://visualstudio.microsoft.com/downloads/
Install the C++ build tools before proceeding.
If you will be targeting the GNU ABI or otherwise know what you are
doing then it is fine to continue installation without the build
tools, but otherwise, install the C++ build tools before proceeding.
Continue? (Y/n)
这里选择否退出。
安装Visual c++ 生成工具
, 去提示的地址https://visualstudio.microsoft.com/downloads/
安装Visual Studio 2019 生成工具。
在Visual Studio 2019 工具
下拉菜单里选择Visual Studio 2019 生成工具
并下载, 之后安装。
安装时在工作负载
中勾选c++生成工具
, 在语言包中勾选英语
, 开始安装。
安装完之后重启。
安装rust
重新打开rustup-init.exe
:
Welcome to Rust!
This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.
It will add the cargo, rustc, rustup and other commands to
Cargo's bin directory, located at:
C:\Users\windows\.cargo\bin
This can be modified with the CARGO_HOME environment variable.
Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:
C:\Users\windows\.rustup
This can be modified with the RUSTUP_HOME environment variable.
This path will then be added to your PATH environment variable by
modifying the HKEY_CURRENT_USER/Environment/PATH registry key.
You can uninstall at any time with rustup self uninstall and
these changes will be reverted.
Current installation options:
default host triple: x86_64-pc-windows-msvc
default toolchain: stable
profile: default
modify PATH variable: yes
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
这里选择第一个, 或者直接按回车, 出现安装成功提示:
Rust is installed now. Great!
To get started you need Cargo's bin directory (%USERPROFILE%.cargo\bin) in your
PATH
environment variable. Future applications will automatically have the
correct environment, but you may need to restart your current shell.
测试rust是否成功安装
打开cmd并输入:
rustc --version
你应能看到已发布的最新稳定版的版本号、提交哈希和提交日期, 类似如下格式:
rustc 1.43.0 (4fb7144ed 2020-04-20)
安装程序也自带一份文档的本地拷贝,可以离线阅读。运行 rustup doc 在浏览器中查看本地文档。
cargo加速
在.cargo
文件夹(就是安装rust里面出现的那个目录, 例如这里是C:\Users\windows\.cargo
)中新建config.txt
, 在里面写入以下内容, 保存退出, 之后把后缀名去掉, 得到文件config
。
# Put the content into ${HOME}/.cargo/config
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
# replace with your favourite mirror
replace-with = 'sjtu'
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"
[source.sjtu]
registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"
[source.rustcc]
registry = "https://code.aliyun.com/rustcc/crates.io-index.git"