This article describes how to install and configure the Rust development environment on Windows.
1 Install the toolchain for the MSVC ABI
In the VS2019 C/C++ toolchain official website to download the generation tool, and select Visual Studio generation tool to download and install
Note:This tool does not install Visual Studio, just the MSVC toolchain.
2 Configure the Rust toolchain installation position
Add the following two environment variables to specify where cargo and Rustup will be installed:
- CARGO_HOME: specify
cargo
Is the installation directory of. - RUSTUP_HOME: specify
rustup
Is the installation directory of.
Note: These are optional. If not specified, the default is to install them in the.cargo and.rustup directories respectively.
3 the configurationrustup
USTC source
Add the following two environment variables to update the toolchain and Rustup itself using the USTC source:
- RUSTUP_DIST_SERVER:
https://mirrors.ustc.edu.cn/rust-static
- RUSTUP_UPDATE_ROOT:
https://mirrors.ustc.edu.cn/rust-static/rustup
4 configurationcargo
USTC source
Create a file called config in the cargo installation directory with the contents specified as:
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'ustc'
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"
5 installationRLS
andstd
The source code
The RLS is Rust Language Server. It is a daemon process used to communicate with the IDE used during development, complete code prompts, jump to definitions, and display variable types.
STD is the standard library of Rust. By default, Rust installs binaries from the standard library, and adding the source code makes it easy to query implementations of some of the standard libraries.
Use the following command to install:
Rustup Component add RLS -- Toolchain stable # RLS Rustup Component add rust-analysis -- Toolchain Stable # Rustup Component add rust-src -- Toolchain stable # STD
6 install the VSCode plug-in
Install the plug-in rust-Analyzer and its dependency Rust-Analyzer Server.
By default, rust-Analyzer Server is automatically pulled from Github by VSCode. If the installation fails due to network reasons, you can manually compile the installation from the source code by doing the following:
- Install on the machine
node.js
Environment for packaging VSCode plug-in generation. - fromHere,download
rust-analyzer server
The source code. -
Decompress and run the following command in the source root directory:
cargo xtask install
The Rust environment has been installed.