如何在 Cargo 配置中为构建和测试指定不同的默认目标?

pho*_*ina 5 rust rust-cargo

我正在为 AArch64 目标交叉编译 Rust 裸机应用程序,我需要在 x86_64 目标(我的 PC)上运行单元测试。

我创建了文件.cargo/config

[build]
target = "aarch64-unknown-none"
Run Code Online (Sandbox Code Playgroud)

我想为 AArch64 构建,但要为 x86_64 运行测试。如果我将构建更改为x86_64-unknown-linux-gnu然后测试编译和执行。有没有我可以指定的部分?我现在必须手动交换这些。

我检查了货物指南,但没有找到有关测试配置的参考。

小智 6

您可以通过在 .cargo/config 文件中创建别名来实现类似的功能

[alias]
test_pc = "test --target=x86_64-unknown-linux-gnu"
Run Code Online (Sandbox Code Playgroud)

然后,你只需调用

cargo test_pc
Run Code Online (Sandbox Code Playgroud)


yuk*_*uki 1

你不能。

根据issue#6874,cargo不具备为 指定不同目标的功能cargo test

仅供参考:如果您使用,您可能有另一种解决方案来解决此问题nightly,尽管我还没有使其发挥作用。以下链接是关于custom test framework,问题开头说“解决方案”。