cargo icon indicating copy to clipboard operation
cargo copied to clipboard

The `cargo build --bins` re-builds binaries again after `cargo build --all-targets`

Open achary opened this issue 1 year ago • 2 comments

Problem

There seem to be unnecessary build happening in the following sequence.

cargo build --release --all-targets
cargo build --release --bins

Not sure that his matters, but my setup uses workspace.

Steps

  1. Run cargo build --release --all-targets
  2. Immediately after run cargo build --release --bins

At step 2. I would expect getting just a "Finished" message straight away, with no re-build happening in between steps 1. and 2., as the --all-targets conceptually include building full set of binary executables already.

Possible Solution(s)

No response

Notes

No response

Version

rustc 1.77.1
cargo 1.77.1 (e52e36006 2024-03-26)

achary avatar May 02 '24 09:05 achary

To know more, we'd need a reproduction case.

I'm assuming whats happening is --all-targets is causing your dev-dependencies to be included in the build graph. These dev-dependencies may be activating features on your dependencies that weren't activated otherwise, causing a rebuild. This is roughly the same issue as #11954 and related issues are #4463 and #8157.

epage avatar May 02 '24 12:05 epage

Is there a way to make cargo check --lib --tests behave the same as running cargo check --lib && cargo check --tests?

Context I used to run cargo check --all-targets thinking I would check all my targets with an implicit assumption that this would be equivalent to running cargo check <target> for each target. I realized today that this is not the case because of feature unification (even with resolver 2) and found this issue which seems to be exactly that. I'm wondering if I should simply run cargo check and cargo check --tests independently (the latter is subsumed by cargo test so maybe I should just defer it until I run cargo test) or if there is a way to invoke a single cargo execution to check both targets.

EDIT: This is probably more relevant with cargo clippy --all-targets, because it's not subsumed by cargo test.

ia0 avatar May 18 '24 15:05 ia0

FYI I've posted rust-lang/rfcs#3692

epage avatar Sep 11 '24 22:09 epage