cargo rebuilds every time when installing a crate with binaries behind feature gates #8703
Labels
A-required-features
Area: required-features setting
C-bug
Category: bug
Command-install
E-medium
Experience: Medium
S-needs-mentor
Status: Issue or feature is accepted, but needs a team member to commit to helping and reviewing.
Problem
Whenever a crate containing multiple binaries, where some of them are behind a feature gate, performing a
cargo install <crate-name>
will cause a rebuild every time, instead of ignoring the rebuild. This is prevalent fornushell
, which has several binaries behind theextra
feature, but I was able to reproduce this in a simple project, as described below.Steps
cargo new --bin cargo_rebuild_bug && cd cargo_rebuild_bug
.src/optional/optional.rs
:Cargo.toml
:cargo install --path .
, I modified thecargo
crate source code to investigate what cargo think is different in comparison to the previously stored tracking information. I applied the following git patch:cargo run -- install nu
in the modifiedcargo
crate. The first time I run it, it will install the nu package as usual, but if I run it a second time after that, it rebuilds again and receives the following output:It seems like when
exe_names
incheck_upgrade
incommon_for_install_and_uninstall.rs
generates the binary names, it includes all binaries, even the ones behind the feature gate.cargo run -- install --path /path/to/cargo_rebuild_bug
also reveals the extraneous package names:Possible Solution(s)
exe_names
should not only check if the target is a bin (for when theCompileFilter
isDefault
), but also if it should be included given the current feature flags passed to the install subcommand. This is at least the only change I think is needed forcargo
to realize that the packages are the same.Or, this is a misconfiguration on
nushell
s part, and there is perhaps a better way to specify binaries behind feature gates?I could give a go implementing the first suggestion and create a PR for it, but I have not worked in this project before, so I thought I'd first create this issue. :)
Notes
Output of
cargo version
:The text was updated successfully, but these errors were encountered: