rust-toolchain.toml 从 msvc 更改为 gnu 不起作用

问题描述 投票:0回答:1

我想为我的一个 Rust 项目设置一个工具链覆盖,以使用 GNU 工具链而不是默认的 MSVC 工具链。但不知怎的,

rust-toolchain.toml
中的配置被忽略了。 (我是最新的,不是因为延期。)

事情是这样的:

λ rustup show
Default host: x86_64-pc-windows-msvc
rustup home:  C:\Users\<username>\scoop\persist\rustup\.rustup

installed toolchains
--------------------

stable-x86_64-pc-windows-gnu
stable-x86_64-pc-windows-msvc (default)

installed targets for active toolchain
--------------------------------------

x86_64-pc-windows-gnu
x86_64-pc-windows-msvc

active toolchain
----------------

stable-x86_64-pc-windows-msvc (default)
rustc 1.57.0 (f1edd0429 2021-11-29)

如你所见,我已经安装了 GNU 工具链。

所以我创建了以下

rust-toolchain.toml
文件:

λ cat rust-toolchain.toml
[toolchain]
channel = "stable"
targets = ["x86_64-pc-windows-gnu"]

现在,当我运行

rustup show
时,我得到的结果显示该工具正在查看该文件,但它似乎没有正确处理它,因为它仍然想使用 msvc。

λ rustup show
Default host: x86_64-pc-windows-msvc
rustup home:  C:\Users\<username>\scoop\persist\rustup\.rustup

installed toolchains
--------------------

stable-x86_64-pc-windows-gnu
stable-x86_64-pc-windows-msvc (default)

installed targets for active toolchain
--------------------------------------

x86_64-pc-windows-gnu
x86_64-pc-windows-msvc

active toolchain
----------------

stable-x86_64-pc-windows-msvc (overridden by 'C:\<project path>\rust-toolchain.toml')
rustc 1.57.0 (f1edd0429 2021-11-29)

我的猜测是,由于某种原因,

x86_64-pc-windows-gnu
被认为是
stable-x86_64-pc-windows-msvc
工具链的有效目标,但我不明白为什么,如何防止它,或者如何在我想要的
rust-toolchain.toml
文件中写入使用
x86_64-pc-windows-gnu
工具链的
stable-x86_64-pc-windows-gnu
目标,而不是
stable-x86_64-pc-windows-msvc
工具链之一。

你认为我可以如何解决这个问题?

注意:使用

rustup default stable-gnu
可以按预期工作,但我希望能够在存储库中提交一些内容,以便其他贡献者(及其工具)知道他们需要使用这个特定的工具链。

编辑:rustup 版本以防万一。

λ rustup -V
rustup 1.24.3 (ce5817a94 2021-05-31)
rust toolchain rustup
1个回答
0
投票

正在构建的target仅更改

sys
板条箱将用于构建二进制文件,并且更有可能在
-msvc
-gnu
工具链之间进行双向交叉编译。

这里需要注意的是,

-gnu
-msvc
通道是单独的轨道。您已经知道这是怎么回事了吧?您需要指定要在
channel
中使用的工具链。

[toolchain]
channel = "stable-x86_64-pc-windows-gnu"
# Allow building for MSVC targets too so you don't get
# accidental MingW DLL dependencies or similar
targets = ["x86_64-pc-windows-gnu", "x86_64-pc-windows-msvc"]
© www.soinside.com 2019 - 2024. All rights reserved.