[rust] build a rust environment using MSVC tool chain and vscode


This paper introduces the installation and configuration of rust development environment under windows.

1 install the tool chain for MSVC abi

stayVs2019 C / C + + tool chainDownload the generation tool from the official website and check itVisual studio build toolDownload and install

be careful:This tool does not install visual studio, but only the tool chain of MSVC.

2. Configure the installation position of rust tool chain

Add the following two environment variables to specifycargoandrustupInstallation position:

  • CARGO_HOME: specifycargoInstall directory for.
  • RUSTUP_HOME: specifyrustupInstall directory for.

be carefulThey are optional. If not specified, they are installed in the home directory by default.cargoand.rustupDirectory

3 configurationrustupChina University of science and technology

Add the following two environment variables to update the tool chain and tool chain with the source of China University of science and technology respectivelyrustuponeself:

  • RUSTUP_DIST_SERVERhttps://mirrors.ustc.edu.cn/rust-static
  • RUSTUP_UPDATE_ROOThttps://mirrors.ustc.edu.cn/rust-static/rustup

4 configurationcargoChina University of science and technology

staycargoCreate a file namedconfig, where the contents are specified as:

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

5 installationRLSandstdSource code

RLSThe full name of is:Rust Language Server, a daemon, is used for IPC communication with the IDE used during development to complete code prompt, jump to definition, display variable type and other functions.

stdIt’s rust’s standard library. By default, rust installs the binary code of the standard library, and after adding the source code, it is easy for us to query the implementation of some standard libraries.

Install using the following command:

rustup component add rls           --toolchain stable    # RLS
Trust component add trust analysis -- toolchain stable # analysis tool
Trust component add trust SRC -- toolchain stable # STD source code

6. Install vscode plug-in

Install plug-insrust-analyzerAnd its dependenciesrust-analyzer server

By default,rust-analyzer serverIt is automatically pulled from GitHub by vscode. If the installation fails due to network reasons, you can manually compile and install from the source code by performing the following operations:

  1. Install locallynode.jsEnvironment for packaging and generating vscode plug-ins.
  2. fromheredownloadrust-analyzer serverSource code.
  3. Unzip and execute the following command in the root directory of the source code:

    cargo xtask install

The rust environment is now installed.