rust-lang / rust-lang/cargo

Reinstalling binaries from a crate while specifying fewer features does not remove already installed binaries corresponding to no longer active features

Open
#15,079 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug Command-install S-needs-design
Dominant language
Rust
Stars
15.5k
Forks
3k
Avg merge
23h 30m
Merged PRs (30d)
51

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
  1. 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
    
  2. 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
    
  3. 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]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the two cargo install commands and the convert2json example, comparing the bin directory before and after reinstalling with fewer features. Trace the cargo install flow responsible for replacing executables; done means binaries from the previous installation that are not built under the new feature set are removed, while the newly enabled binaries remain.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.