-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Tighter coupling of Cargo workspaces #2315
Conversation
FWIW, I think the default should be not to have this functionality turned on (though it would be nice to have it available). Part of the reason of splitting out crates in a large project like |
This reminds me of .Net's I feel like, after reading the RFC, I'm not certain exactly what's responsible for checking and ensuring the reasonableness of the combinations here. If crate A is the root, and crates B and C are in the workspace, what exactly happens if B and C both try to impl the same thing or add an inherent method with the same name to the same type? What forces the crates used by rustc to be ones that make sense together? |
@scottmcm that's the same issue we have today when two crates don't interact well. What if crate1 provides:
and crate2 provides:
Currently, this is fine. But if crate1 adds the breaking change:
Then these two types now conflict, and Rust fails to compile. If two crates provide the same name for a method or the same impl, it'll conflict like it already does. And this isn't unsound because all of the conflicts have to be resolved at once, and the entire workspace has to be published as a unit. |
the type or the trait are in the same workspace, not just the same crate. | ||
3. Workspaces which use virtual manifests must opt into this feature by | ||
specifying `workspace.root` in `Cargo.toml`. | ||
4. Workspaces can opt out of this with `workspace.coupled = false` in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think default behavior should be considered. For instance build scripts named build.rs don't need to be named in Cargo.toml anymore.
I think we should err on the side of opt in rather than opt out, but I really do like this in general and would clean up some of my codebases if this was available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an artefact of the fact that I wasn't sure what the default behaviour should be when writing this; in the guide-level explanation I don't list the default but in the reference-level I do.
I'll fix this later today; I agree that it should be opt-in, as it prevents the workspace from allowing multiple versions of crates.
cc @SergioBenitez - isn't this somewhat the "crate groups" idea? |
Can this be opt-in per trait, rather than for a crate/workspace as a whole? i.e. |
@kornelski I don't think this would be useful; once crates are coupled, their versions are locked together too. All that coupling allows is the ability to provide extra impls for traits, not necessarily a requirement to do so. |
cc @rust-lang/cargo |
@Centril This is indeed in the same vain as what I've dubbed "crate friends". In fact, this RFC can be mostly subsumed by crate friends. Crate friends also offer a greater level of flexibility and allow for some important scenarios. Crate friends allows you to mark specific crates as friends in Friend relationships must be reciprocal. Crates I expect the syntax for declaring crate friends to be similar to the syntax for declaring dependencies. Imagine, for instance, that Rocket's [friends]
serde_json = "1.0"
[friends]
rocket = "*" Removing a friend is a breaking change. If all members of a workspace are considered friends by default, this RFC is mostly subsumed. The exception is the provision in this RFC that would allow all members of a friend group to access an item declared as |
I'm not opposed to the idea of crate friends, but I'm also unsure why in that particular case |
@clarcharr See rwf2/Rocket#547 (in particular rwf2/Rocket#547 (comment)) and serde-rs/json#407 for details on that particular issue. |
I was thinking about this a bit, and one particularly big downside to crate friends (imo) is that it feels a bit more like crate cliques in the sense that some of the larger crates may be able to more easily interact, whereas smaller ones won't. Why should Rocket have preferential access to To me it just seems like some APIs may need to be exposed differently, or crates should be split to allow interaction with lower-level error types but not higher-level ones. Of course, this is only after a glimpse into the situation you described, and I'm still open to reworking this RFC to make use cases like that more easy to work with. |
With #1133 or it's successor, I'd hope standard library crates would not be pre-built in their own workspace but regular deps like any other of crates in the user's workspace. Then this trick wouldn't work for I rather expose built-in types with |
I'm glad someone brought up the issue of version synchronization for all crates in a workspace, as that is a feature that I do miss coming originally from Maven. However, I don't see how any of the other features are actually useful or reasonable. Crates are not meant to be tightly coupled to each other; if you are trying to do that, those features probably belong in the same crate. Crates are meant to either start from scratch or build on top of existing crates in an acyclical way. I don't think this is the right way to resolve the "mess" that we have with If this were to be implemented in Cargo as it is currently proposed, it would probably mean that the entire workspace would have to be treated as a single crate, which means "crates" would now just be glorified modules. Skip the extra complexity and turn your codependent crates into modules, or even better, improve your design by removing such cycles. |
We discussed this RFC in the Cargo team meeting, and have decided to move to postpone this. This will likely require deep changes, and we do not think there is the necessary bandwidth or priority to move forward with this at this time. @rfcbot fcp postpone |
Team member @ehuss has proposed to postpone this. The next step is review by the rest of the tagged team members:
No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
@rfcbot reviewed |
1 similar comment
@rfcbot reviewed |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period, with a disposition to postpone, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. The RFC is now postponed. |
This is a way to more tightly couple crates within a cargo workspace, allowing inherent impls and blanket trait impls across multiple crates in the same project. Its primary use case is for the standard library, but the feature is extended so that it can be used by the entire crate ecosystem.
Rendered