-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Different default targets for cargo build
and cargo test
?
#6784
Comments
.cargo/config
key similar to build.target
that only changes target for build
and run
cargo build
and cargo test
?
In case it helps, I personally solved this issue for embedded development with shell scripts or make files for each scenario, so one for running tests on the host, one for flashing the microcontroller, and so on. |
Thanks for the suggestion! I want to avoid Makefiles and external scripts when possible, since they are not really portable across OSs. However, I found a different solution to my problem in the custom test framework feature, which allows me to run my tests on the target system. If nobody else is interested in this issue I will close it in a week. |
Not sure if it helps you to find the motivation to submit the actual PR, but I totally agree that this feature is nice to have. |
@SomeoneToIgnore As noted above, I found a better solution to my problem and I don't have the time for implementing a solution to this problem at the moment. However, I already opened a draft PR at #6825, which might be useful if someone wants to implement it (but please consider the review comments in the PR thread). I'm happy to reopen this issue, though! |
I would very much like this feature! My target is severely memory constrained so running tests on it is not such a nice proposition. |
We would also find this useful for https://github.com/cloud-hypervisor/rust-hypervisor-firmware. We want our firmware to be built with one target, and then for our integration tests to be built for the host target. |
I am working on this issue. Expect a pull request in the near future. |
@seanybaggins one issue that came up in #6825, is that having a I'm actually not sure which approach is best here, but for both my and @phil-opp's use case, we want to build binaries on the custom target, and then run tests on the host. EDIT: Here's a better version of the above idea. Have |
@josephlr This is way better than what I was going to implement. I was going to have a |
Just want to double check... we want the [build]
jobs = 1 # number of parallel jobs, defaults to # of CPUs
rustc = "rustc" # the rust compiler tool
rustc-wrapper = "…" # run this wrapper instead of `rustc`
rustdoc = "rustdoc" # the doc generator tool
# Still wondering if this should be just `target` or `build-target`
target = "triple" # build for the target triple (ignored by `cargo install`)
# Build configs to be added
lib-target = "triple"
bin-target = "triple"
test-target = "triple"
target-dir = "target" # path of where to place all generated artifacts
rustflags = ["…", "…"] # custom flags to pass to all compiler invocations
rustdocflags = ["…", "…"] # custom flags to pass to rustdoc
incremental = true # whether or not to enable incremental compilation
dep-info-basedir = "…" # path for the base directory for targets in depfiles
pipelining = true # rustc pipelining |
Actually, now that I am looking back through this, is having all of these configuration options necessary? My big motivation is to use the When the user invokes What if the user invokes |
So I ended up implementing this and ended up really disliking my implementation. See comments in pull request #8761. I think that cargo-make tool may be the best to achieve the desired behavior. |
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, includingcargo build
,cargo run
,cargo test
andcargo 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
andcargo bench
commands on the host architecture because they depend onstd
(and thus don't work on the embedded target). Currently the only way to do this is to specify the full host triple on eachcargo 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 forcargo build
,cargo check
, andcargo run
, but not forcargo test
andcargo bench
.Notes
I'm happy to create a PR for this if something like this is desired.
The text was updated successfully, but these errors were encountered: