0%

【Rust】Rust在win10下开发环境的搭建

记录下如何在Windows 10环境下部署VScode的Rust开发环境。

配置步骤

环境变量设置

1
2
3
4
5
6
RUST=d:\Program Files\RUST\.rustup\toolchains\stable-x86_64-pc-windows-msvc  
CARGO HOME = D:\Program Files\RUST\.cargo
RUSTUP_DIST_SERVER = https://mirrors.ustc.edu.cn/rust-static
RUSTUP_HOME = D:\Program Files\RUST\.rustup
RUSTUP_UPDATE_ROOT = https://mirrors.ustc.edu.cn/rust-static/rustup
RUST_SRC_PATH = d:\Program Files\RUST\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src

配置Windows的Rust和Crates.io国内镜像

修改Crates.io国内镜像

修改~/.cargo/config

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[source.crates-io]  
registry = "https://github.com/rust-lang/crates.io-index"

#Replace with any mirror source
replace-with = 'ustc'
#replace-with = 'tuna'
#replace-with = 'sjtu'
#replace-with = 'rustcc'

#University of science and technology of China
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"

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

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

#Rustcc community
[source.rustcc]
registry = "git://crates.rustcc.cn/crates.io-index"
### 修改rustup国内镜像

在系统环境变量中设置

1
2
3
4
CARGO HOME = D:\Program Files\RUST\.cargo  
RUSTUP_DIST_SERVER = https://mirrors.ustc.edu.cn/rust-static
RUSTUP_HOME = D:\Program Files\RUST\.rustup
RUSTUP_UPDATE_ROOT = https://mirrors.ustc.edu.cn/rust-static/rustup

VS Code插件安装

  1. rust-analyzer

    该插件有说明与会与官方的Rust有冲突,二者只能先激活一个。

  2. CodeLLDB

    基于LLDB的原生debugger.详见官网

  3. TabNine

    基于深度学习的智能提示插件, 详见官网

开启VS Code进行测试

安装插件,重启VS Code后。

现在运行官网示例。

1
2
3
4
5
6
7
8
9
10
11
use ferris_says::say; // from the previous step
use std::io::{stdout, BufWriter};

fn main() {
let stdout = stdout();
let message = String::from("Hello fellow Rustaceans!");
let width = message.chars().count();

let mut writer = BufWriter::new(stdout.lock());
say(message.as_bytes(), width, &mut writer).unwrap();
}

测试, RA、CodeLLDB及TabNine工作正常。