Cargo multiple target setup for build and test


I've a problem to setup my environment to be working nicely for embedded rust development.

1 cargo config

Is it possible to setup cargo so that cargo test is running with --target HOST and -Z build-std=core not set.
But running cargo build with a different --target and adding -Z build-std=core?

Up to now I've only found the possibility to add

build-std = ["core"]

to .cargo/config.toml.
But no way to differ here for the target-triple or e.g. 'cfg(test)'.

2 vscode environment

What are you doing to have a fully working and comfortable vscode environment for embedded development?

Especially with the

#[cfg(not(test))] // The main function interfers with 'cargo test' when targeting the host machine.
pub extern "C" fn main() {}

This is fine for running local tests on host target, but vscode deactivates the bin code, because test is always specified in the IDE to check all the code. So as a workaround I comment the cfg-line during development and uncomment for test run. Not so great.

Is there any better option?

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.