Description
Problem
If you first install the binaries of a crate using cargo install
, then issue another cargo install
specifying fewer features in a way that should result in fewer binaries, those binaries which corresponds to no longer active features are not removed. I'm not sure if this is the intended behavior or not (I could not find anything clear about it), but it was at least not the behavior I expected.
Steps
-
Install a crate with multiple binaries tied to different features and examine result.
$ cargo install --root cargo-home convert2json Updating crates.io index Installing convert2json v1.1.4 ... Compiling convert2json v1.1.4 Finished `release` profile [optimized] target(s) in 14.51s Installing cargo-home/bin/cq Installing cargo-home/bin/csv2json Installing cargo-home/bin/ini2json Installing cargo-home/bin/iq Installing cargo-home/bin/rq Installing cargo-home/bin/rsv2json Installing cargo-home/bin/toml2json Installing cargo-home/bin/tq Installing cargo-home/bin/xml2json Installing cargo-home/bin/xq Installing cargo-home/bin/yaml2json Installing cargo-home/bin/yq Installed package `convert2json v1.1.4` (executables `cq`, `csv2json`, `ini2json`, `iq`, `rq`, `rsv2json`, `toml2json`, `tq`, `xml2json`, `xq`, `yaml2json`, `yq`) $ ls cargo-home/bin/ cq csv2json ini2json iq rq rsv2json toml2json tq xml2json xq yaml2json yq
-
Reinstall the same crate with features disabled and examine the result to see that the same binaries are still installed.
$ cargo install --root cargo-home --no-default-features --features xml convert2json Updating crates.io index Installing convert2json v1.1.4 ... Compiling convert2json v1.1.4 Finished `release` profile [optimized] target(s) in 8.18s Replacing cargo-home/bin/xml2json Replacing cargo-home/bin/xq Replaced package `convert2json v1.1.4` with `convert2json v1.1.4` (executables `cq`, `csv2json`, `ini2json`, `iq`, `rq`, `rsv2json`, `toml2json`, `tq`, `xml2json`, `xq`, `yaml2json`, `yq`) $ ls cargo-home/bin/ cq csv2json ini2json iq rq rsv2json toml2json tq xml2json xq yaml2json yq
-
Manually remove installed binaries, install again with features disabled, and examine the result to see that only a subset of binaries are installed. This is what I would have expected already at step 2.
$ rm -r cargo-home/ $ cargo install --root cargo-home --no-default-features --features xml convert2json Updating crates.io index Installing convert2json v1.1.4 ... Finished `release` profile [optimized] target(s) in 8.21s Installing cargo-home/bin/xml2json Installing cargo-home/bin/xq Installed package `convert2json v1.1.4` (executables `xml2json`, `xq`) $ ls cargo-home/bin/ xml2json xq
Possible Solution(s)
The straight forward solution, I assume, would be to list installed binaries at the start of the process, then do the compilation and installation, and finally remove any previously installed binaries that where not replaced by the newly compiled crate.
Version
cargo 1.84.0 (66221abde 2024-11-19)
release: 1.84.0
commit-hash: 66221abdeca2002d318fde6efff516aab091df0e
commit-date: 2024-11-19
host: x86_64-unknown-linux-gnu
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.9.0-DEV (sys:0.4.74+curl-8.9.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w 11 Sep 2023
os: Linux Mint 21.2.0 (victoria) [64-bit]