我试图在Cygwin上安装Rust,但未能与mingw连接.现在我正试图用Msys2安装它.我已经安装了Msys2和Mingw.我试着跟着this wiki page,但我在第二点迷路了:

使用安装程序下载并安装Rust+Cargo,但一定要禁用链接器和平台库选项.

是指the install page上的"rustup init.exe"吗?我应该双击运行此文件还是从Msys2运行它?我try 从Msys2上运行,得到了以下选项:

1) Proceed with installation (default)  
2) Customize installation  
3) Cancel installation

我不知道下一步该怎么办.

我试着遵循弗朗西斯的回答:

Thang@Thang-Laptop MINGW64 /c/Software/Rust
$ ./rustup-init.exe

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 2015 which provides just the Visual C++ build tools:

  http://landinghub.visualstudio.com/visual-cpp-build-tools

Alternately, you can install Visual Studio 2015 or Visual Studio 2013 and
during install select the "C++ tools":

  https://www.visualstudio.com/downloads/

Install the C++ build tools before proceeding.

If you will be targetting 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) Y


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:

  C:\Users\Thang\.cargo\bin

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
  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 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

Modify PATH variable? (y/n)
y


Current installation options:

   default host triple: x86_64-pc-windows-gnu
     default toolchain: stable
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
1

info: updating existing rustup installation


Rust is installed now. Great!

To get started you need Cargo's bin directory (%USERPROFILE%\.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.


Thang@Thang-Laptop MINGW64 /c/Software/Rust
$ rustc --version
bash: rustc: command not found

我添加了配置文件.不知道我是否错过了什么

Thang@Thang-Laptop MINGW64 /c/Users/Thang/.cargo
$ cat config
[target.x86_64-pc-windows-gnu]
linker = "C:\msys2\mingw64\bin\gcc.exe"
ar = "C:\msys2\mingw64\bin\ar.exe"
Thang@Thang-Laptop MINGW64 /c/Users/Thang/.cargo
$ cargo --version
bash: cargo: command not found

编辑2:

Thang@Thang-Laptop MINGW64 ~
$ echo $PATH
/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/c/Windows/System32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/

但我在环境变量中的用户变量中看到了它.

编辑3:

Thang@Thang-Laptop MINGW64 /c/Users/Thang/.cargo/bin
$ ./rustup default stable-x86_64-pc-windows-gnu
info: syncing channel updates for 'stable-x86_64-pc-windows-gnu'
info: latest update on 2017-10-12, rust version 1.21.0 (3b72af97e 2017-10-09)
info: downloading component 'rustc'
info: downloading component 'rust-std'
info: downloading component 'cargo'
info: downloading component 'rust-docs'
info: downloading component 'rust-mingw'
info: installing component 'rustc'
info: installing component 'rust-std'
info: installing component 'cargo'
info: installing component 'rust-docs'
info: installing component 'rust-mingw'
info: default toolchain set to 'stable-x86_64-pc-windows-gnu'

  stable-x86_64-pc-windows-gnu installed - rustc 1.21.0 (3b72af97e 2017-10-09)


Thang@Thang-Laptop MINGW64 /c/Users/Thang/.cargo/bin
$ ls
cargo.exe  rustc.exe    rust-gdb.exe   rustup.exe
rls.exe    rustdoc.exe  rust-lldb.exe

Thang@Thang-Laptop MINGW64 /c/Users/Thang/.cargo/bin
$ rustc --version
bash: rustc: command not found

推荐答案

你链接到的Using Rust on Windows页是在Rustop取代安装程序作为安装Rust的默认选项之前创建的.Installers仍然可用,但如果可能的话,您应该使用Rustop,因为它可以方便地同时更新和使用多个工具链(例如stable、beta和nightly).如果必须使用安装程序,只需 Select x86_64-pc-windows-gnu安装程序并按照Using Rust on Windows页中的步骤操作即可.如果你使用的是Rustop,请继续阅读.

默认情况下,Windows上的Rustop会安装针对MSVC工具链的编译器和工具,而不是GNU/MinGW-w64工具链.在初始菜单中, Select 2) Customize installation.当要求输入主机三元组时,请输入x86_64-pc-windows-gnu.然后 Select 其他问题,然后继续安装.

Note:如果已经安装了rustup,那么重新运行rustup init实际上不会安装请求的工具链.相反,如果已经有了基于MSVC的工具链,请运行rustup toolchain install stable-x86_64-pc-windows-gnu.然后运行rustup default stable-x86_64-pc-windows-gnu将基于GNU的工具链设置为默认值.

Rustop将自动安装MinGW链接器和平台库(作为rust-mingw组件的一部分),并拒绝让您删除它们.如果您更喜欢使用随MSYS2一起安装的MinGW链接器和库,则需要创建一个.cargo/config文件(在您的配置文件目录(即C:\Users\you\.cargo\config)中,或者在您的项目目录(如果此配置特定于某个项目)中).该文件的内容可能如下所示:

[target.x86_64-pc-windows-gnu]
linker = "C:\\msys2\\mingw64\\bin\\gcc.exe"
ar = "C:\\msys2\\mingw64\\bin\\ar.exe"

Rustop将修改PATH环境变量,除非您告诉它不要这样做.但是,MSYS2在启动时默认重置PATH,因此当您try 从MSYS2shell 调用cargorustc时,它可能找不到它.您需要编辑.profile/.bash_profile脚本以正确设置PATH(您需要预先设置/c/Users/yourname/.cargo/bin:PATH).

Rust相关问答推荐

有条件默认实现

borrow 和内部IntoIterator

"value is never read警告似乎不正确.我应该忽略它吗?

如何删除Mac Tauri上的停靠图标?

无法从流中读取Redis请求

如何在Rust中将选项<;选项<;字符串>;转换为选项<;选项&;str>;?

如何从ruust中的fig.toml中读取?

变量需要parse()中的显式类型

完全匹配包含大小写的整数范围(&Q;)

是否提供Bundle 在可执行文件中的warp中的静态文件?

为什么AsyncRead在Box上的实现有一个Unpin特征绑定?

要求类型参数有特定的大小?

我可以解构self 参数吗?

为什么需要静态生命周期以及在处理 Rust 迭代器时如何缩小它?

特征中定义的类型与一般定义的类型之间的区别

为什么指定生命周期让我返回一个引用?

如何在 C++ 和 Rust 之间共享 pthread 同步原语?

实现不消费的迭代器

需要括号的宏调用中的不必要的括号警告 - 这是编写宏的糟糕方法吗?

如何在 Rust 的内置函数上实现特征?