Invalid binary already exists error from cargo install in case of binary disabled by feature
Problem
In case of 2 crates contain the same binary in case of some feature enabled there is a conflict detected even in case of disabled feature.
This behaviour depends on the order of cargo install commands, i.e. if you are installing crate with the conflicting binary disabled by feature first you are getting no errors.
Steps
- Install
invalid-bin-conflict-afirst and theninvalid-bin-conflict-b:
cargo install invalid-bin-conflict-a
cargo install invalid-bin-conflict-b
- There is an error:
$ cargo install invalid-bin-conflict-b
Updating crates.io index
error: binary `invalid-bin-conflict-a` already exists in destination as part of `invalid-bin-conflict-a v0.1.0`
Add --force to overwrite
Possible Solution(s)
Exclude binaries disabled by features for binary conflict check.
Notes
If you try to install invalid-bin-conflict-b first and then invalid-bin-conflict-a - there would be no error.
Version
$ cargo version --verbose
cargo 1.80.0 (376290515 2024-07-16)
release: 1.80.0
commit-hash: 37629051518c3df9ac2c1744589362a02ecafa99
commit-date: 2024-07-16
host: x86_64-unknown-linux-gnu
libgit2: 1.7.2 (sys:0.18.3 vendored)
libcurl: 8.6.0-DEV (sys:0.4.72+curl-8.6.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w 11 Sep 2023
os: Gentoo Linux 2.15.0 [64-bit]
Thanks for setting up the reproduction steps!
That seems unfortunate. cargo install already filters bin targets by names. However, it happens way earlier before Cargo starts resolving feature, so the filter process know nothing about required-features.
https://github.com/rust-lang/cargo/blob/5ff9328cb4d79afb7badb7d5d8869c3611677cf7/src/cargo/ops/common_for_install_and_uninstall.rs#L175
It's a bit difficult to fix this, and seems somehow related to https://github.com/rust-lang/cargo/issues/4663, which also want to determine what to run in advance.
In the meanwhile, cargod install invalid-bin-conflict-b --bin invalid-bin-conflict-b should work.