-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cargo should allow features/optional-dependencies to be private or public, private by default #7769
Comments
After reading RFC 1977 it is clear that is a different though related proposal, about leaking child dependencies out of your (rust-language-level) API. By contrast, this issue is about restricting the visibility of your (crate-level) API, which is not otherwise restrictable today. However it does propose a new public_features = ["parallel"]
# ^ public optional dependencies would go here as well, as the --features flag does
[features]
parallel = ["num_cpus", "jobserver"]
[dependencies.jobserver]
version = "0.1.16"
optional = true
allow_public = true Otherwise if you use |
I think the main issue here is with implicit features caused by optional dependencies as it should be more clear that explicit features are part of the API. The latest stable release has cargo weak and namespaced features which is now documented as the default approach. While we have an issue changing the default for weak features (#10556), we've talked some about about changing the default for namespacing but not as sure on that. Seeing as my understanding of the need in this issue is resolved (hiding implicit features), I'm going to close this. If there is something I missed, feel free to say so. If there is something more (like removing implicit features completely), please open a new issue. |
If this is true, then crates.io should be detecting when people upload crates changing its explicit API features in a way that breaks semver. Does it do that at the moment? |
A feature of a crate is part of its public API, but many crate authors don't realise this and constantly re-arrange their features. This in fact breaks semver, because someone depending on e.g.
cc/rayon
(present in version1.0.37
) will have this broken bycc
version1.0.47
which does not have this feature. What one should actually be depending on is theparallel
feature which points torayon
in version1.0.37
, but points instead tonum_cpus, jobserver
in version1.0.47
thereby retaining semver compatibility.However the fact that the "public/private"-ness of features is not even typically discussed, means that many crate authors are unaware of this, and freely add and remove features/optional-dependencies from their crates without thinking about semver compatibility.
Not sure if this is related to #6129 or not - that issue seems more to be about the
--extern
flag torustc
.The text was updated successfully, but these errors were encountered: