-
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
cargo build --all-targets
generates two copies of crate test binary
#4929
Comments
I suspect it is compiling the library once with the |
I see. Although that might be useful in theory, in practice it's a problem because you can't tell which binary is which. |
Aha it does indeed look like @mbrubeck is right! If you build with
(note the I agree this is surprising though! I don't think we should build benchmarks unless |
I would have assumed that if I wanted to run benches on optimized code I would do |
Building a non-debuginfo optimized build into |
I'm looking at modifying Do we really want not to build tests and benchmarks in debug-mode? People may want debug-builds of their benchmarks from |
@rust-lang/cargo may wish to weigh in? To me |
The fact that the bench target is written to the "debug" directory is initially surprising to me (this also happens with --benches and --bench). The --release flag seems to control which directory things will be sent to independent of the target's Profile. Would it make sense to change that? Particularly in light of rust-lang/rfcs#2282 which would put custom profiles in their own directory, it might be simpler if the Profile drives the output directory instead of having various special cases. My intent when I changed it was that --all-targets really means "all targets" so that one can verify that everything compiles the same as-if you did everything individually. I think it would be confusing if --all-targets meant "some targets". |
I implemented filtering out tests in |
I think it would make sense for My problem with the current situation is that currently I think a bigger problem is that apparently despite having used Rust for two years my mental model for cargo is wrong. I had assumed debug/release map to profiles, which are a specific set of compiler options, and build-targets are orthogonal to profiles. But apparently that's not true... |
It makes perfect sense for I think |
Then again, take that with a grain of salt since perhaps I have no idea what a build target actually is. I found https://doc.rust-lang.org/cargo/reference/manifest.html#the-profile-sections which explains some of my misunderstanding. Sorry about not finding that earlier. However, that page nowhere mentions "build target", so it's still unclear exactly what a build target is or how they interact with profiles. I'm particularly confused about how Another thing that confuses me: I had thought of "tests" and "examples" as both being a kind of build target, but building tests is controlled by a flag in the profile, while apparently building examples are not. So whether examples are built is orthogonal to the profile, but whether tests are built is not? |
Yea, I think it would be nice if there was an introduction that explained and defined these different terms (when I first started learning Rust I was confused by what "crate" meant, and it still doesn't seem to be defined anywhere). Configuring a target sort of explains targets.
Perhaps this table will clarify which profile is used based on whether or not
Another point of possible confusion is that lib.rs is a "lib" target, a "test" target (for unit-tests), and a "bench" target.
Perhaps it is clearer to think of each thing that gets built as a pair Let me know if you have any questions. I'm not sure if what I wrote helps. You're not the only one confused by this. @matklad in particular is a proponent of simplifying the profile selection. |
FWIW historically the implementation of targets/profiles in Cargo has been pretty muddied and has had lots of subtle bugs, so I'ms orry if that's cause any confusion! Cargo itself is not doing a great job of making the distinctions here which is the root many issues. I think building benchmarks in debug mode makes sense with |
As there hasn't been any activity here in over 6 months I've marked this as stale and if no further activity happens for 7 days I will close it. I'm a bot so this may be in error! If this issue should remain open, could someone (the author, a team member, or any interested party) please comment to that effect? The team would be especially grateful if such a comment included details such as:
Thank you for contributing! (The cargo team is currently evaluating the use of Stale bot, and using #6035 as the tracking issue to gather feedback.) If you're reading this comment from the distant future, fear not if this was closed automatically. If you believe it's still an issue please leave a comment and a team member can reopen this issue. Opening a new issue is also acceptable! |
No. What needs to change isn't exactly clear.
|
Use "test" profile for `cargo build` benchmarks. When using `cargo build` (without `--release`), build benchmarks using the "test" profile. This was causing some confusion where the benchmark is placed in the `target/debug` directory, and also causing some duplicates that may not be expected. It also makes it easier to debug benchmarks (previously you had to edit the `[profile.bench]` profile). Closes #5575, closes #6301, closes #4240, closes #4929.
Example:
I don't know why it generates two copies of the crate test binary. That seems unnecessary.
The text was updated successfully, but these errors were encountered: