Rust安装
# 前言
在使用 golang
写粘贴板的时候,发现 golang
的底层库实在是太过于良莠不齐,另外 golang
学的也不是很精通,想做桌面端的时候 wails v3
也是进展缓慢,只好在这个空闲时间来看看 Rust
。废话不多说,预先用之,必先装之。
哦,对了,学习的资料用的是:Rust语言圣经(Rust Course) (opens new window)
因为 wails v3
库不好用,去学习 Rust
总有种为了一碗醋而包了一顿饺子的感觉 😂
# 安装
# Linux
、macOS
直接运行
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
# 输入完上面代码后显示的内容详情见 Windows 安装 Rust
2
这个命令将下载一个脚本并开始安装
rustup
工具,此工具将安装Rust
的最新稳定版本。可能会提示你输入管理员密码。 如果安装成功,会提示Rust is installed now. Great!
我安装完成后就直接重新开了一个终端窗口,运行了 cargo -V
和 rustc -V
都正常了,提示后面的一个环境变量没有执行
# 安装 C
语言编译器:(非必需)
macOS
xcode-select --install
Linux
- 按照相应发行版的文档来安装
GCC
或Clang
- 按照相应发行版的文档来安装
# Windows
因我的环境是
macOS
所以以下安装方式没有验证,自行验证
Windows
环境下必须要C++
环境
下面为两种安装方式
# x86_64-pc-windows-msvc
(官方推荐)
先安装 Microsoft C++ Build Tools (opens new window),勾选安装 C++
环境即可。安装时可自行修改缓存路径与安装路径,避免占用过多 C
盘空间。安装完成后,Rust
所需的 msvc
命令行程序需要手动添加到环境变量中,否则安装 Rust
时 rustup-init
会提示未安装 Microsoft C++ Build Tools
,其位于:%Visual Studio
安装位置%\VC\Tools\MSVC\%version%\bin\Hostx64\x64
(请自行替换其中的 %Visual Studio
安装位置%
、%version%
字段)下。
如果你不想这么做,可以选择安装 Microsoft C++ Build Tools
新增的“定制”终端 Developer Command Prompt for %Visual Studio version%
或 Developer PowerShell for %Visual Studio version%
,在其中运行 rustup-init.exe
。
准备好 C++
环境后开始安装 Rust
:
在 RUSTUP-INIT (opens new window) 下载系统相对应的 Rust
安装程序,一路默认即可。
PS C:\Users\Hehongyuan> rustup-init.exe
......
Current installation options:
default host triple: x86_64-pc-windows-msvc
default toolchain: stable (default)
profile: default
modify PATH variable: yes
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
2
3
4
5
6
7
8
9
10
11
12
# x86_64-pc-windows-gnu
相比于 MSVC
版本来说,GNU
版本具有更轻量,更靠近 Linux
的优势。
首先,根据 MSYS2 (opens new window) 官网 配置 MSYS
。
在安装 mingw-toolchain
后,请将 %MSYS 安装路径%\mingw64\bin
添加到系统变量 PATH
中。
配置好后,在 MSYS
中输入下面的命令来安装 rustup
。
$ curl https://sh.rustup.rs -sSf | sh
之后,根据以下输出进行配置。
Current installation options:
default host triple: x86_64-pc-windows-msvc
default toolchain: stable (default)
profile: default
modify PATH variable: yes
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>2
I'm going to ask you the value of each of these installation options.
You may simply press the Enter key to leave unchanged.
Default host triple? [x86_64-pc-windows-msvc]
x86_64-pc-windows-gnu
Default toolchain? (stable/beta/nightly/none) [stable]
stable
Profile (which tools and data to install)? (minimal/default/complete) [default]
complete
Modify PATH variable? (Y/n)
Y
Current installation options:
default host triple: x86_64-pc-windows-gnu
default toolchain: stable
profile: complete
modify PATH variable: yes
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
再之后,按下 1
,等待。完成后,您就已经安装了 Rust
和 rustup
。
# 为 cargo
和 rustup
设置源
本文替换为[字节跳动]源,参考地址Rust crates.io 索引 (opens new window)
笔记
原本想使用清华源的,但是打开 RustRover
编辑器后地步一直在提示 download
中,并且 main
函数也无法运行,比较耽误时间,所以替换为字节跳动的源了
vi ~/.cargo/config
# 进入编辑器后粘贴下面的信息
[source.crates-io]
replace-with = 'rsproxy'
[source.rsproxy]
registry = "https://rsproxy.cn/crates.io-index"
# 稀疏索引,要求 cargo >= 1.68
[source.rsproxy-sparse]
registry = "sparse+https://rsproxy.cn/index/"
[registries.rsproxy]
index = "https://rsproxy.cn/crates.io-index"
[net]
git-fetch-with-cli = true
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18