Skip to content
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

Closed
phil-opp opened this issue Oct 12, 2016 · 8 comments · Fixed by #3443 or #3837
Closed

Workspaces: Add a way to disable transitive inclusion of path dependencies #3192

phil-opp opened this issue Oct 12, 2016 · 8 comments · Fixed by #3443 or #3837

Comments

@phil-opp
Copy link
Contributor

phil-opp commented Oct 12, 2016

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:

├── our_library
│   ├── Cargo.toml
│   └── src
├── executable_1
│   ├── Cargo.toml
│   └── src
└── executable_2
    ├── Cargo.toml
    └── src

Now we want to make the executables workspace roots. This leads to the following errors:

error: workspace member /home/…/our_library/Cargo.toml is not hierarchically below the workspace root /home/…/executable_{1,2}/Cargo.toml

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.

@alexcrichton
Copy link
Member

Thanks for the report!

@Boscop
Copy link

Boscop commented Oct 30, 2016

Upvote!
I run into this problem frequently.
The easiest solution would be to only make those imported crates that are in a subfolder of the workspace members of that workspace.
Especially if the workspace members are explicitly specified, there should be no confusion!
Anyone would intuitively assume that a workspace can only include crates in the subfolders.

@whitequark
Copy link
Member

whitequark commented Jan 12, 2017

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:

  • do a commit in the external crate
  • get its git hash
  • update Cargo.toml of the crate inside the workspace
  • rebuild
  • not forget to remove the dummy commits before pushing

@SergioBenitez
Copy link
Contributor

SergioBenitez commented Jan 15, 2017

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.

bors added a commit that referenced this issue Jan 18, 2017
Path deps outside workspace are not members

closes #3192

This implements @Boscop suggestion: path dependencies pointing outside the workspace are never members.

Not sure that it handled #3192 fully: you can't exclude a path dependency within workspace. Not sure this is super useful though...
@alexcrichton
Copy link
Member

Ah I didn't think this was entirely closed out with #3443, so I'm going to reopen. (manual annotations are still not implemented)

@alexcrichton alexcrichton reopened this Jan 18, 2017
bors added a commit that referenced this issue Feb 2, 2017
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.
@alexcrichton
Copy link
Member

Ok, so here's a thought of how to fix this. Add a new key to Cargo.toml:

[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 [workspace] you're not considered part of that workspace.

Thoughts?

@Boscop
Copy link

Boscop commented Mar 7, 2017

I like that, if all non-excluded crates in subfolders are automatically members of the workspace.

alexcrichton added a commit to alexcrichton/cargo that referenced this issue Mar 16, 2017
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
@alexcrichton
Copy link
Member

I've opened #3837 as a sample implementation of my idea to close this issue. Feedback would be much appreciated!

bors added a commit that referenced this issue Mar 23, 2017
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants