走进Rust:Windows环境搭建

Rust大约 5283 字

配置环境变量

  • CARGO_HOME:设置Cargo目录为D:\rust\cargo
  • RUSTUP_HOME:设置Rustup目录为D:\rust\rustup
  • RUSTUP_DIST_SERVER:设置rustupDIST代理为https://mirrors.ustc.edu.cn/rust-static
  • RUSTUP_UPDATE_ROOT:设置rustupUPDATE代理为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官方编译器和包管理器CargoRustup元数据和工具链。

输入2,进入自定义安装,可以选择不同平台,如下:

  • GNU ABI (using GCC)
    • i686-pc-windows-gnu:32位GNU
    • x86_64-pc-windows-gnu64GNU
  • 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.

测试命令

命令行运行cargorustup是否有信息输出,有表示安装成功。

下载源码

不下载也可使用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'

相关网址

https://github.com/rust-lang/rust

https://github.com/rust-lang/cargo

阅读 170 · 发布于 2020-06-27

————        END        ————

扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看换一批