cargo-cache icon indicating copy to clipboard operation
cargo-cache copied to clipboard

`cargo install --no-default-features` fails to build

Open taralx opened this issue 4 years ago • 8 comments

As in title. Lots of complaints about missing crates.

taralx avatar Oct 01 '21 20:10 taralx

Mhh, looks like --no-default-features turns off most of the default dependencies (they are still needed though) which causes the build to fail.

What do you expect when building cargo-cache with --no-default-features?

matthiaskrgr avatar Oct 01 '21 21:10 matthiaskrgr

I expect a minimal version of the program. If these features are actually required for the binary, then there should be a required-features declaration: https://doc.rust-lang.org/cargo/reference/cargo-targets.html#the-required-features-field

taralx avatar Oct 02 '21 03:10 taralx

(It is also common to have a feature "cli" or similar that enables only the minimal required features for the binary, which is often a subset of the default features.)

taralx avatar Oct 02 '21 03:10 taralx

There is a ci-autoclean feature which only leaves in a very stripped-down version of cargo cache that only runs cargo-cache --autoclean upon launch and does nothing else.

There's also an offline_tests features that disables tests that require network connectivity for sandboxed builds.

Besides that, I don't think it is worth it to try to split up the program into multiple features, I mean if someone has a good reason and PR ready, I might consider it, but in the last 4 years, I don't think I came across a moment where I thought "oh it would be great if feature XY that is currently default would be optional".

I'm wondering if setting something like required-features = [default] would solve the build failure though.

matthiaskrgr avatar Oct 05 '21 18:10 matthiaskrgr

Hm, that would probably break the ci-autoclean build then :smile: since that one tries to explicitly NOT use default features/deps, hmm....

matthiaskrgr avatar Oct 05 '21 18:10 matthiaskrgr

I'm confused. If you didn't want to "split up the program into multiple features" then why are there optional dependencies?

taralx avatar Oct 11 '21 14:10 taralx

The dependencies are optional to reduce the build time of the ci-autoclean cargo-cache to around 5 seconds instead of 1-2 mintutes.

matthiaskrgr avatar Nov 13 '21 09:11 matthiaskrgr

Perhaps that could properly be handled by a flag somewhere in that build? --no-deps perhaps?

taralx avatar Nov 13 '21 16:11 taralx