-
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
Workspaces: Add a way to disable transitive inclusion of path dependencies #3192
Comments
Thanks for the report! |
Upvote! |
This makes using cargo workspaces a nightmare when I need to develop a crate outside of the workspace. Currently, for any trivial change, I have to:
|
Chiming in as I've run into this as well. I believe the correct thing to do here is to assume that any path dependency that is not hierarchically below the workspace is not part of that workspace. In other words, do not implicitly include path dependencies that are not hierarchically below the workspace as members of that workspace. If a user explicitly adds such a member to the workspace, then this error can be given. Edit: Ah, looks like #3443 implements exactly this. |
Ah I didn't think this was entirely closed out with #3443, so I'm going to reopen. (manual annotations are still not implemented) |
Find workspace via `workspace_root` link in containing member This PR proposes to change the logic for determining workspace members. Here are the algorithms we used previously for this: # [RFC](https://github.com/rust-lang/rfcs/blob/master/text/1525-cargo-workspace.md) flavor If `[members]` key present, it compliantly defines the set of members. Otherwise, members are all (transitive) path dependencies. The problem with this approach is that it violates convention over configuration principle: almost always you want a path dependency to be a member, even if there are some explicit members. Listing **all** path deps is just to much work. # Original implementation So, the actual algorithm **unconditionally** included path dependencies as memebers. This is also problematic, because certain workspace configurations become impossible. In particular, you can't have a path dependency which is not a member of the workspace. This issue was reported in #3192. # Current implementation Current implementation (was merged couple of days ago) includes path dependency into the workspace only if is inside the workspace directory. This solves the problem in #3192 perfectly. However, some configuration are still impossible: you can't have a non-member path dependency inside a workspace directory. But the thinking is that if you don't want this path-dep to be a member, just don't put it inside the workspace directory. There is another problem with current imlementation. Suppose you have an explicit member which lives alongside the workspace. Suppose this member has a path-dep which lives inside the member's folder. Under current implementation, this path-dep won't be a member of the workspace. It seems logical that it should be though (but we haven't received any actual bug reports yet)! # Implementation in this PR So, with this PR, the logic is as follows: members are explicit members + all path dependencies which reside under any of the explicit members.
Ok, so here's a thought of how to fix this. Add a new key to [workspace]
exclude = [
"path1",
"path/to/dir2",
# ...
] The idea is that as a workspace root you can dictate paths which are not included in the workspace (hierarchically). That means that if you traverse upwards through one of those dirs into the Thoughts? |
I like that, if all non-excluded crates in subfolders are automatically members of the workspace. |
This commit adds a new key to the `Cargo.toml` manifest, `workspace.exclude`. This new key is a list of strings which is an array of directories that are excluded from the workspace explicitly. This is intended for use cases such as vendoring where path dependencies into a vendored directory don't want to pull in the workspace dependencies. There's a number of use cases mentioned on rust-lang#3192 which I believe should all be covered with this strategy. At a bare minimum it should suffice to `exclude` every directory and then just explicitly whitelist crates through `members` through inclusion, and that should give precise control over the structure of a workspace. Closes rust-lang#3192
I've opened #3837 as a sample implementation of my idea to close this issue. Feedback would be much appreciated! |
Add a workspace.exclude key This commit adds a new key to the `Cargo.toml` manifest, `workspace.exclude`. This new key is a list of strings which is an array of directories that are excluded from the workspace explicitly. This is intended for use cases such as vendoring where path dependencies into a vendored directory don't want to pull in the workspace dependencies. There's a number of use cases mentioned on #3192 which I believe should all be covered with this strategy. At a bare minimum it should suffice to `exclude` every directory and then just explicitly whitelist crates through `members` through inclusion, and that should give precise control over the structure of a workspace. Closes #3192
Right now, a workspace root automatically includes all of its path dependencies as workspace members. It would be nice if we could disable this somehow.
This is a follow-up to #3156.
Use case:
Assume that we have a local library crate that we don't want to publish (yet). We include it in multiple executable crates through
path = "../our_library"
dependencies:Now we want to make the executables workspace roots. This leads to the following errors:
So each executable requires that we make
our_library
a workspace member of its own workspace. But a crate can't be part of multiple workspaces.Right now, there is no way to resolve this problem, since there is no way to disable the automatic inclusion of path dependencies.
The text was updated successfully, but these errors were encountered: