【问题标题】:How can I specify a different default target for building and testing in the Cargo config?如何在 Cargo 配置中为构建和测试指定不同的默认目标?
【发布时间】:2018-10-14 12:50:16
【问题描述】:

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

我创建了文件.cargo/config

[build]
target = "aarch64-unknown-none"

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

我检查了cargo guide,但没有找到有关测试配置的参考。

【问题讨论】:

  • 我假设你的意思是它必须是默认的(我已经根据这个假设更新了你的标题)。否则,你可以做cargo test --target=...
  • @Shepmaster 谢谢,这行得通 - 我把它放到 Makefile.toml 文件中。虽然我很感兴趣是否可以在 Cargo 配置文件中指定它而不是将其作为输入参数传递。

标签: rust rust-cargo


【解决方案1】:

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

[alias]
test_pc = "test --target=x86_64-unknown-linux-gnu"

那么,你只需调用

cargo test_pc

【讨论】:

    【解决方案2】:

    你不能。

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

    仅供参考:如果您使用nightly,您可能有针对此问题的另一种解决方案,尽管我还没有使它起作用。以下链接是关于custom test framework,问题开启者说“解决方案”。

    【讨论】:

      猜你喜欢
      • 2018-09-02
      • 1970-01-01
      • 2016-02-18
      • 1970-01-01
      • 2021-08-25
      • 1970-01-01
      • 2010-12-10
      • 1970-01-01
      • 2022-01-22
      相关资源
      最近更新 更多