走进 Rust:Windows 环境搭建
Rust Windows 镜像 About 5,288 words配置环境变量
CARGO_HOME
:设置Cargo
目录为D:\rust\cargo
;RUSTUP_HOME
:设置Rustup
目录为D:\rust\rustup
;RUSTUP_DIST_SERVER
:设置rustup
的DIST
代理为https://mirrors.ustc.edu.cn/rust-static
;RUSTUP_UPDATE_ROOT
:设置rustup
的UPDATE
代理为https://mirrors.ustc.edu.cn/rust-static/rustup
;
配置 Cargo 镜像
在CARGO_HOME
(前文已设置为D:\rust\cargo
)下新建config
文件(文件名就叫config
,无后缀),添加一下内容。
[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"
[http]
check-config = false
添加http.check-config = false
为了解决设置代理后无法下载的问题。报错信息如下:
Caused by:
[35] SSL connect error (schannel: next InitializeSecurityContext failed: Unknown error (0x80092013)
issue
链接:https://github.com/rust-lang/cargo/issues/7096
安装 Rust
下载 rustup
地址:https://www.rust-lang.org/tools/install
双击运行
Rust
需要微软C++
构建工具,在执行安装前,请安装好这些。
但是如果主要用于GNU ABI
,则可以不用安装。(微软的Visual
太大了,不想安装)。
确认输入Y
。
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)
安装方式
下载Rust
官方编译器和包管理器Cargo
,Rustup
元数据和工具链。
输入2
,进入自定义安装,可以选择不同平台,如下:
- GNU ABI (using GCC)
i686-pc-windows-gnu
:32位GNU
x86_64-pc-windows-gnu
:64
位GNU
- The MSVC ABI
i686-pc-windows-msvc
:32位微软Visual C++
- x86_64-pc-windows-msvc:64位微软
Visual C++
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:
D:\rust\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:
D:\rust\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
>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-gnu`。
Default toolchain? (stable/beta/nightly/none) 输入`stable`。
Profile (which tools and data to install)? (minimal/default/complete) 输入`default`。
Modify PATH variable? (y/n) 输入`y`。
回车确认开始下载安装。
安装完成
按Enter
继续。
info: profile set to 'default'
info: setting default host triple to x86_64-pc-windows-gnu
info: syncing channel updates for 'stable-x86_64-pc-windows-gnu'
463.3 KiB / 463.3 KiB (100 %) 402.6 KiB/s in 1s ETA: 0s
info: latest update on 2020-04-23, rust version 1.43.0 (4fb7144ed 2020-04-20)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
info: downloading component 'rust-mingw'
info: downloading component 'rust-std'
info: downloading component 'rustc'
54.1 MiB / 54.1 MiB (100 %) 44.6 MiB/s in 1s ETA: 0s
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
12.1 MiB / 12.1 MiB (100 %) 1.2 MiB/s in 8s ETA: 0s
info: installing component 'rust-mingw'
info: installing component 'rust-std'
15.8 MiB / 15.8 MiB (100 %) 11.8 MiB/s in 1s ETA: 0s
info: installing component 'rustc'
54.1 MiB / 54.1 MiB (100 %) 8.6 MiB/s in 6s ETA: 0s
7 IO-ops / 7 IO-ops (100 %) 6 IOPS in 2s ETA: 0s
info: installing component 'rustfmt'
info: default toolchain set to 'stable'
stable installed - rustc 1.43.0 (4fb7144ed 2020-04-20)
Rust is installed now. Great!
To get started you need Cargo's bin directory (D:\rust\cargo\bin) in your PATH
environment variable. Future applications will automatically have the
correct environment, but you may need to restart your current shell.
Press the Enter key to continue.
测试命令
命令行运行cargo
和rustup
是否有信息输出,有表示安装成功。
下载源码
不下载也可使用Rust
,但标准库中的函数将无法使用。
rustup component add rust-src
下载完成提示信息。
info: downloading component 'rust-src'
1.6 MiB / 1.6 MiB (100 %) 127.5 KiB/s in 16s ETA: 0s
info: installing component 'rust-src'
相关网址
Views: 7,063 · Posted: 2020-06-27
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...