Repository navigation
cargo install cargo-edit --no-default-features fails to compile #947
Description
Activity
While this is a bug, its relatively minor in my opinion.
The big issue is that cargo does not report the error about nothing to install until after it has compiled things
$ cargo install pulldown-cmark --no-default-features Updating crates.io index Installing pulldown-cmark v0.13.0 Updating crates.io index Locking 3 packages to latest compatible versions Compiling pulldown-cmark v0.13.0 Compiling bitflags v2.9.3 Compiling unicase v2.8.1 Compiling memchr v2.7.5 Finished `release` profile [optimized] target(s) in 2.12s warning: none of the package's binaries are available for install using the selected features bin "pulldown-cmark" requires the features: `getopts` example "broken-link-callbacks" requires the features: `html` example "event-filter" requires the features: `html` example "events" requires the features: example "footnote-rewrite" requires the features: `html` example "normalize-wikilink" requires the features: `html` example "parser-map-event-print" requires the features: `html` 2 more targets also requires features not enabled. See them in the Cargo.toml file. Consider enabling some of the needed features by passing, e.g., `--features="getopts"`
This is being tracked in rust-lang/cargo#8970
I'm unsure I understand. I cloned the repo and added a simple
#[cfg(feature = "cli")]to the mentionedFromimpl, andcargo build --release --no-default-featurescompiles just fine. Are you saying that it shouldn't compile at all ifcliis not enabled or thatcargo-editis useless without at least that feature enabled? If so, thencompile_errorwould still be appropriate in my opinion.cargo build --release --no-default-featureswill build butcargo install --release --no-default-featureswill error because all of the binaries require some feature to be enabled.cargo-editis a library (which is all that is left without features) is not generally a priority, see https://docs.rs/cargo-edit/latest/cargo_edit/#semver-compatibilityThe right fix is adding the appropriate
#[cfg]s, its just a low priority for me to do anything about it.OK, can you tell me what the minimum set of features are for the binary? Is
clienough?We have a feature per binary, see
Lines 38 to 56 in d722ed8
[[bin]] name = "cargo-add" path = "src/bin/add/main.rs" required-features = ["add"] [[bin]] name = "cargo-rm" path = "src/bin/rm/main.rs" required-features = ["rm"] [[bin]] name = "cargo-upgrade" path = "src/bin/upgrade/main.rs" required-features = ["upgrade"] [[bin]] name = "cargo-set-version" path = "src/bin/set-version/main.rs" required-features = ["set-version"] Reacted by philomathic_lifeYou can set a
compiler_errorin lib.rs to short-circuit erroneous compilation:#[cfg(not(feature = "cli"))] { compile_error!("At least 1 feature is required to install"); }
This would help avoid duplicate issues in the future and provide a more meaningful error message.
Please disregard if this crate is intended to be a lib crate as well as a binary crate.
Machine info:
If one must enable certain features, ideally
compile_errorwould be used informing a user the minimum set of features that must be enabled; otherwise any use ofclapshould be gated behind acfgattribute based on the set of features that enable it.