Why does cargo build -p have to rebuild anything?

I've been trying to run a binary that builds some crates and creates an SDK. I've been trying to run cargo build -p on the ones that it needs, but I've noticed that it always needs to do some rebuild, even if I cargo build in the root directory.
When running with the fingerprint info, I see that fingerprint dirty for <crate> and that some dependency info has changed
dirty: UnitDependencyInfoChanged { old_name: "quiche", old_fingerprint: 2901189237625079336, new_name: "quiche", new_fingerprint: 16408896289750780237 }
but i have done nothing other than switch from cargo build to cargo build -p <crate>

That can change the set of features enabled for a dependency, since other crates in the workspace aren't being built that were the previous time you ran cargo build.

This may provide more information:

CARGO_LOG=cargo::core::compiler::fingerprint=trace cargo build -p crate

in this case though the crate in question (quiche) has no features specified? is there a way to build it such that it uses the same features as the root level cargo build?

cargo tree -e features -i quiche should show where different features are coming from if that's it.

quiche v0.17.2
├── quiche feature "boringssl-vendored"
│ └── quiche feature "default"
│ └── crate1 v0.1.0
│ └── crate1 feature "default" (command-line)
│ └── crate2 v0.1.0
│ └── crate2 feature "default" (command-line)
└── quiche feature "default" (*)

it looks like my crates only depend on "default"

If you are using a workspace, you can use a workspace hack crate to hold your external dependencies and make sure the same set of features is used for all crates of your workspace.

The crate cargo_hakari can be used for this.

Each crate of your workspace depends on the workspace hack crate, and cargo hakari manages the dependencies of the workspace crate for you (when you call it it makes sure that all dependencies are included with minimal needed features).

i've tried installing and running cargo hakari to set up a workspace hack, but it still causes small extra rebuilds when running cargo build and then cargo build -p crate

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.