使用 Msys2 为 mingw 安装 Rust 和 Cargo 的分步说明?
Step by step instruction to install Rust and Cargo for mingw with Msys2?
我尝试在 Cygwin 上安装 Rust,但无法 link 使用 mingw。现在我想用 Msys2 安装它。我已经安装了 Msys2 和 Mingw。我试图跟随 this wiki page 但我在第 2 位迷路了:
Download and install Rust+Cargo using the installer but be sure to disable the Linker and platform libraries option.
是指the install page上的"rustup-init.exe"吗?我应该双击 运行 这个文件还是从 Msys2 运行 它?我尝试从 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:
我刚刚重新启动了笔记本电脑。还是不行,我查看了msys2中的Path,没有cargo文件夹
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
您链接到 Windows 页面上的 Using Rust 的日期是在 rustup 将安装程序替换为安装 Rust 的默认选项之前的日期。 Installers 仍然可用,但如果可能,您应该使用 rustup,因为它可以轻松更新和同时使用多个工具链(例如稳定版、测试版和夜间版)。如果您必须使用安装程序,只需 select x86_64-pc-windows-gnu
安装程序并按照 Windows 页面上的 Using Rust 中的步骤操作。如果您正在使用 rustup,请继续阅读。
默认情况下,Windows 上的 rustup 安装针对 MSVC 工具链的编译器和工具,而不是 GNU/MinGW-w64 工具链。在初始菜单中,select 2) 自定义安装。当询问主机三元组时,输入 x86_64-pc-windows-gnu
。然后对其他问题进行选择,然后进行安装。
注意:如果 rustup 已经安装,那么重新运行ning rustup-init 将不会实际安装请求的工具链。相反,如果您已经拥有基于 MSVC 的工具链,则 运行 rustup toolchain install stable-x86_64-pc-windows-gnu
。然后 运行 rustup default stable-x86_64-pc-windows-gnu
将基于 GNU 的工具链设置为默认。
Rustup 将自动安装 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"
Rustup 将修改 PATH
环境变量,除非你告诉它不要这样做。但是,MSYS2 在启动时默认重置 PATH
,因此当您尝试从 MSYS2 shell 调用 cargo
或 rustc
时,它可能找不到它。您需要编辑 .profile
/.bash_profile
脚本以正确设置 PATH
(您需要将 /c/Users/yourname/.cargo/bin:
添加到 PATH
)。
我写了一份完整的指南
使用 Visual Studio 代码和 MSYS2 MinGW 在 windows 上安装 Rust
在此处找到的页面上:
我的问题通过以下方式解决了
- 运行
rustup toolchain install stable-x86_64-pc-windows-gnu
- 第二次打开
.rustup
文件夹
- 打开
settings.toml
文件
- 将第一行更改为:
default_toolchain = "stable-x86_64-pc-windows-gnu"
完成!
我尝试在 Cygwin 上安装 Rust,但无法 link 使用 mingw。现在我想用 Msys2 安装它。我已经安装了 Msys2 和 Mingw。我试图跟随 this wiki page 但我在第 2 位迷路了:
Download and install Rust+Cargo using the installer but be sure to disable the Linker and platform libraries option.
是指the install page上的"rustup-init.exe"吗?我应该双击 运行 这个文件还是从 Msys2 运行 它?我尝试从 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:
我刚刚重新启动了笔记本电脑。还是不行,我查看了msys2中的Path,没有cargo文件夹
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
您链接到 Windows 页面上的 Using Rust 的日期是在 rustup 将安装程序替换为安装 Rust 的默认选项之前的日期。 Installers 仍然可用,但如果可能,您应该使用 rustup,因为它可以轻松更新和同时使用多个工具链(例如稳定版、测试版和夜间版)。如果您必须使用安装程序,只需 select x86_64-pc-windows-gnu
安装程序并按照 Windows 页面上的 Using Rust 中的步骤操作。如果您正在使用 rustup,请继续阅读。
默认情况下,Windows 上的 rustup 安装针对 MSVC 工具链的编译器和工具,而不是 GNU/MinGW-w64 工具链。在初始菜单中,select 2) 自定义安装。当询问主机三元组时,输入 x86_64-pc-windows-gnu
。然后对其他问题进行选择,然后进行安装。
注意:如果 rustup 已经安装,那么重新运行ning rustup-init 将不会实际安装请求的工具链。相反,如果您已经拥有基于 MSVC 的工具链,则 运行 rustup toolchain install stable-x86_64-pc-windows-gnu
。然后 运行 rustup default stable-x86_64-pc-windows-gnu
将基于 GNU 的工具链设置为默认。
Rustup 将自动安装 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"
Rustup 将修改 PATH
环境变量,除非你告诉它不要这样做。但是,MSYS2 在启动时默认重置 PATH
,因此当您尝试从 MSYS2 shell 调用 cargo
或 rustc
时,它可能找不到它。您需要编辑 .profile
/.bash_profile
脚本以正确设置 PATH
(您需要将 /c/Users/yourname/.cargo/bin:
添加到 PATH
)。
我写了一份完整的指南
使用 Visual Studio 代码和 MSYS2 MinGW 在 windows 上安装 Rust 在此处找到的页面上:
我的问题通过以下方式解决了
- 运行
rustup toolchain install stable-x86_64-pc-windows-gnu
- 第二次打开
.rustup
文件夹 - 打开
settings.toml
文件 - 将第一行更改为:
default_toolchain = "stable-x86_64-pc-windows-gnu"
完成!