Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify a different target when running unit tests #8761

Closed

Conversation

seanybaggins
Copy link

When working with bare metal embedded systems, it would be nice to be able to run unit tests on your host machine using cargo test and then deploy to the target device using cargo run. Currently, to build different targets between tests and regular builds, your only option is to explicitly use the --target flag when invoking cargo.

The purpose of this pull request is have different targets between cargo build and cargo test without the need for the --target flag.

This was achieved by changing the .cargo/config.toml options.

Closes #6784

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 8, 2020
@seanybaggins
Copy link
Author

Some things I am still not pleased with...

cargo build --tests
still uses the build.target profile instead of the build.test-target profile.

Open to ideas for the best way to get the context for the --tests flag within the CompileKind::from_requested_targets function.

@seanybaggins
Copy link
Author

Perhaps a better way to implement this is just to use the cargo make tool...

@alexcrichton
Copy link
Member

Thanks for the PR! We discussed this a bit at the last Cargo meeting, and we agree that this may not be the best way to implement it. Especially the gotchas you mention (cargo build --tests not using the same target) feels sort of weird. Would using a solution like cargo make work for you?

@seanybaggins
Copy link
Author

Sorry for such a late reply.

Yes. I think the cargo-make tool solves the problem this pull request was trying to address.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Different default targets for cargo build and cargo test?
3 participants