如何为目标设置货物不稳定选项?

Ale*_*oz. 8 config rust rust-cargo

我有.cargo/config.toml以下内容:

\n
[unstable]\nunstable-options = true\nbuild-std = ["core", "alloc"]\n
Run Code Online (Sandbox Code Playgroud)\n

但我build-std只需要一个目标(例如thumbv7em-none-eabihf)。

\n

有没有办法专门为目标声明它?

\n

它可能是这样的:

\n
# wrong example, doesn\'t work apparently\n[target.thumbv7em-none-eabihf.unstable]\nbuild-std = ["core", "alloc"]\n
Run Code Online (Sandbox Code Playgroud)\n

注意,我\xe2\x80\x99m 仅讨论配置,我知道如何使用货物执行参数配置它。\xe2\x80\x99s 需要自动忽略build-std其他提到的目标,例如默认主机目标。

\n

Jad*_*key 3

截至 2023 年 7 月 4 日,仅使用内置货物配置无法实现这一点。有关详细信息,请参阅背景部分。

解决方法

您将需要为该目标使用外部调用货物进行构建,例如“core”和“alloc”

cargo build --target thumbv7em-none-eabihf -Z build-std="core,alloc"
Run Code Online (Sandbox Code Playgroud)

使用安装的相关工具链和此测试程序进行测试:

#![feature(restricted_std)]

fn main() {
    loop {}
}
Run Code Online (Sandbox Code Playgroud)

与货物调用

cargo build --target thumbv7em-none-eabihf -Z build-std="std,panic_abort"
Run Code Online (Sandbox Code Playgroud)

背景

经过一些实验和搜索后,货物在此处添加此功能存在一个悬而未决的问题,但由于已经探索了多种不同的方法,进展似乎很缓慢。由于 build-std 仍然是一个不稳定的接口,仅在 Cargo 的夜间版本中可用,因此仍然与其他功能以及与更改语义相关的一些开放封闭PR 存在冲突。这种功能的跟踪问题就在这里