What does cargo publish --all-features do

I'm sure I'm being a dunce here, but I'm having trouble understanding the difference between cargo publish and cargo publish --all-features. I created a "dummy" package with an intentionally ridiculous name to avoid name squatting something useful. Anyway, I can't find any observable difference on crates.io when I cargo publish with and without --all-features. I can't see any difference when I use cargo add or cargo install either. The following is a snippet of my Cargo.toml:

[[bin]]
name = <redacted_to_avoid_advertising_a_useless_crate>
required-features = ["fizz", "std"]

[features]
default = ["foo"]
std = []
foo = []
bar = []
fizz = []
buzz = []

I've published the package without having a default feature as well, and that doesn't change the behavior. When there is a default feature, cargo add and cargo install only enable that feature and crates.io only displays the features that are enabled by default as checked. Without a default feature, no features are used by cargo add or cargo install, and crates.io doesn't show any feature with a box checked.

I expect that the only thing that option does is change which features are enabled in the verify build. It definitely won’t change what gets published — publication only filters files, not features.

3 Likes

Ah, good to know. I suppose it makes more sense to verify the default set of features (if one is defined) over all features since it's likely more common people use just the default set, so I'll probably start using cargo publish. I've been using cargo publish --all-features, and I didn't bother to really see what the difference is until now.

Personally, I think --all-features would make more sense as a default choice. Assuming you cargo test before you publish, the only added value of the verify build is that it catches files omitted from the package. But if those files are only used when some feature is enabled, and you don't use publish --all-features, you could publish a broken package and not notice. That’s unlikely (it would have to be an optional file not included by the include/exclude rules, so probably a non-.rs file), but possible.

Good point. I'll keep running cargo publish --all-features then. I wonder why that's not the default behavior. Like you said, it's unlikely it matters what one runs; but ideally the default should be the one that makes the most sense.

I suspect that the reason for not enabling --all-features by default, might be caused by the fact that, even this is strongly discouraged, some crates do use mutually exclusive features, that can break compilation.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.