Skip to content

Different default targets for cargo build and cargo test? #6784

Open
@phil-opp

Description

@phil-opp

Describe the problem you are trying to solve

Cargo currently provides a build.target configuration key that allows to change the default target triple. This changes the default target for all cargo commands, including cargo build, cargo run, cargo test and cargo bench. For embedded/OS crates it often makes sense to set that key so that the project is automatically built for the bare-metal target system instead of the host system.

The problem is that one might still want to run the cargo test and cargo bench commands on the host architecture because they depend on std (and thus don't work on the embedded target). Currently the only way to do this is to specify the full host triple on each cargo test invocation, which is not portable across different host systems.

Describe the solution you'd like

It would be nice if there would be an additional build.build-target configuration key that overrides the target only for cargo build, cargo check, and cargo run, but not for cargo test and cargo bench.

Notes

I'm happy to create a PR for this if something like this is desired.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-configurationArea: cargo config files and env varsC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Command-testS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions