[英]How can I specify a different default target for building and testing in the Cargo config?
I'm cross-compiling a Rust bare metal application for AArch64 target and I need to run unit tests on x86_64 target (my PC).我正在为 AArch64 目标交叉编译 Rust 裸机应用程序,我需要在 x86_64 目标(我的 PC)上运行单元测试。
I created the file .cargo/config
:我创建了文件
.cargo/config
:
[build]
target = "aarch64-unknown-none"
I'd like to build for AArch64 but to run the tests for x86_64.我想为 AArch64 构建,但要为 x86_64 运行测试。 If I change the build to
x86_64-unknown-linux-gnu
then the tests compile and execute.如果我将构建更改为
x86_64-unknown-linux-gnu
则测试将编译并执行。 Is there a section where I could specify this?有没有我可以指定的部分? I have to swap these manually now.
我现在必须手动交换这些。
I checked cargo guide but found no reference about test configuration.我检查了货物指南,但没有找到有关测试配置的参考。
You can achieve similar functionality by creating an alias in your .cargo/config file您可以通过在 .cargo/config 文件中创建别名来实现类似的功能
[alias]
test_pc = "test --target=x86_64-unknown-linux-gnu"
then, you just just call然后,你只要打电话
cargo test_pc
You cannot.你不能。
According to issue#6874 , cargo doesn't have the feature to specify different target for cargo test
.根据问题#6874 ,cargo 没有为
cargo test
指定不同目标的功能。
FYI: you might have another solution for this issue if you use nightly
, though I haven't made it work.仅供参考:如果您使用
nightly
,您可能有针对此问题的另一种解决方案,尽管我还没有使它起作用。 The following links are about custom test framework
, the issue opener says 'the solution'.以下链接是关于
custom test framework
,问题开场白说“解决方案”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.