Closed
Description
All examples in documentation should be built by scripts/build.sh
, but that currently does cargo build
only, not cargo test
.
cargo test
needs the test
crate, which isn't available on Cortex-M. Which means we need to compile the tests on the host machine, which is fine, since we don't need to run them. The problem is, the target is set in .cargo/config
, and there's no way (as far as I can tell) to say "ignore that, I want the target to be the host".
This leaves us with several options, none of which are ideal:
- Not set the target in
.cargo/config
. This means we'll have to pass--target=thumbv6m-none-eabi
to everything. This would suck, as I'm doing a lot ofcargo run --example
during development. - Override the target by passing
--target
tocargo test
. We could just passx86_64-unknown-linux-gnu
, which would be good enough for me and for CI, but not for the general case. - Auto-detect target in
build.rs
and pass that via--target
tocargo test
. Maybe we can write the target triple into a file intarget/
, and read that inscripts/build.sh
. - Write a Rust program that prints the current target (using
build.rs
, as in the linked Stack Overflow answer),cargo install
that inscripts/build.sh
. Maybe something like that even exists? - Implement Different default targets for
cargo build
andcargo test
? rust-lang/cargo#6784 and use that new capability once it's released.