-
Notifications
You must be signed in to change notification settings - Fork 602
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
Enforce semver rules #435
Comments
Different crates will have different standards for what a breaking change is. |
Could you elaborate that? I'm not really sure what you mean. If my crate's public API changes and becomes incompatible, I can't see how there could be a different "opinion" on that? |
(Edit: Maybe this is overly pessimistic. A tool to find changes is great. Here's some of the challenges of enforcement). Some inspiration from the API evolution RFC https://github.com/rust-lang/rfcs/blob/master/text/1105-api-evolution.md This is just for Rust, but it forms a role model as well. Some breaking changes are just minor changes according to that policy:
Other common issues:
Example from the messy real world:
|
As an example, I accidentally broke glutin by replacing |
@badboy has done work on this: https://github.com/semantic-rs/semantic-rs Edit: oh, hm it's not clear how deep the analysis in that crate is, or is intended to be, but I swear badboy has been exploring that. |
Yes, yes I have. Currently there's no actual code analysis in that crate, it solely relies on commit message conventions. My plan was and still is to have some code analysis to determine certain things. (I have some very very basic code somewhere which can at least detect function signature changes). Putting all rules from RFC1105 into code will be incredibly hard. We won't ever get to a point where we don't miss a thing. And we definitely don't want to stop users from publishing versions, for which the server thinks they are breaking, but they are actually not. |
It seems many prefer at least some level of check on server to nothing. |
Identifying every breaking change is impossible, since it seems easily reducible to the halting problem. But as a lint, this could be useful. For example:
In general, some tool which documents the changes to the public API of your library has many uses. Highlighting breakages/potential breakages is even better. I don't know if there are any breakages that crates.io should block upload on; I think its a potentially good idea but also potentially problematic. |
The main issues I see come up from specifically annotated/documented public APIs which are deprecated, unstable, or some other thing (beta? nightly? testing only?). Unstable APIs in particular shouldn't force a major version bump. I could see the argument for Deprecated methods requiring a major version bump. |
What if the |
Could you expand on that? IMO, if a mechanical process can detect a change that is breaking, then it should block publishing without a major bump. If someone removes a public type from their API, that should, in fact, force at-least-one of (major version bump, revert the change) as far as I can tell. |
There are some examples in the RFC that are technically breaking, but will compile fine in most cases (adding a variant to an enum with a __NonExhaustive variant). It wouldn't make much sense to prevent publishing a packet in that case. The point is, the RFC explicitly defines those cases, so all of them can be detected and dealt with automatically. |
Bugs & false positives? I don't have a concrete example (and if I would we could easily fix that up front). |
What about soundness fixes? odds 0.2.17 was published without a trait bound that was needed for a function to be memory safe. A few minutes later I realized the mistake in the new function and posted the bug fix as 0.2.18, which restricted the function by a trait bound as was intended all along. fix commit This would need an override. |
I think the best course of action is a plugin like clippy that would compare your current code with the previous version, and output warnings for breaking changes. If that works well, maybe Cargo can integrate it and add a confirmation message if you try to publish a version that has breaking changes. |
Unstable crates should use version numbers below The more I think about this, the better I like the idea of not hard-blocking crates from being published for the reasons posted above, integrating such a feature as linter into cargo makes the most sense to me. There will be cases that cannot be caught by a programmatic analysis (removing releases that contain sensitive data? Yanking?). |
I'd suggest keeping it on before 1.0.0 as well: good habits learned during infancy of a project can carry over into good habits in adulthood. Thanks |
FWIW, https://github.com/ibabushkin/rust-semverver is an implementation of a checker for this kind of thing. |
I strongly disagree about keeping the check on. There needs to be a period where a maintainer can signal that a project is in it's infancy and inherently unstable, and isn't forced into a contract before the project is ready to adopt it. I see your point @setharnold and agree about good habit forming. I also view this as unnecessarily constrictive given a <1.0.0 project is still in it's initial development phase considering: https://semver.org/#spec-item-4. A downstream user should be expecting to pin on exact versions before 1.0.0 since there isn't yet a contract, and I'd rather see cargo warning on anything but exact version pinning on crates that are <1.0.0. |
@carols10cents Would you agree that if this were to be considered, it would require a formal RFC? (and hence this issue should be closed) |
Yes, I think hammering out the details of exactly how a tool like rust-semverver would be integrated into crates.io should have an RFC. |
Elm does this. Whenever somebody pushes code to their package management system, it checks the public API for incompatibilities and checks whether those are reflected in the associated version number. This would be great for crates.io! See http://elm-lang.org/.
(Moved from rust-lang/cargo#3074)
The text was updated successfully, but these errors were encountered: