Improving `cargo install` UX for packages with `[lib]`/`[[bin]]` crates with `required-features`

Right now if you attempt to install a package with a [bin] crate with required-features (which are very useful for packages that also contain [lib] crates) you get the following error:

$ cargo install cargo-lock
   Compiling cargo-lock v8.0.3
    Finished release [optimized] target(s) in 34.00s
warning: none of the package's binaries are available for install using the selected features

Just in general that's not a super helpful error. It'd be really nice if it could at least list the required-features which would make the [[bin]] crates available.

But even better: what if there were a separate set of default features when a package was cargo installed?

I'm not going to attempt to describe a syntax in Cargo.toml for this to avoid a bikeshedding debate, but imagine if instead of cargo install exiting with a somewhat inscrutable error, it Just Worked instead, because the required features (cli in this case) were automatically enabled when using cargo install.

I think this would help the usability of packages containing both [lib] and [[bin]] crates significantly.

1 Like

There's an open RFC about automatically activating features for cargo install (and other similar cases):



Nightly should also report required features thanks to That is on the train to stable.