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

Improve workspace discovery logic #3030

Merged

Conversation

illicitonion
Copy link
Collaborator

Previously we were assuming that any crate with a path dep lives in a
workspace, and any that doesn't isn't.

This isn't correct logic.
https://doc.rust-lang.org/cargo/reference/workspaces.html describes the
specification. We do filesystem traversal to detect implicit members.
This is a little more expensive, but much more correct.

This is a precursor for supporting path dependencies - the current
incorrect logic incorrectly identifies any Cargo.toml file containing a
path dependency as expecting to live in a workspace, which breaks some
use-cases.

@illicitonion illicitonion force-pushed the splicer-workspace-membership branch 12 times, most recently from 942e367 to 736eef6 Compare December 5, 2024 01:55
@illicitonion illicitonion marked this pull request as ready for review December 5, 2024 01:55
@illicitonion illicitonion force-pushed the splicer-workspace-membership branch from 736eef6 to 11c0025 Compare December 5, 2024 01:57
@illicitonion illicitonion mentioned this pull request Dec 5, 2024
Previously we were assuming that any crate with a path dep lives in a
workspace, and any that doesn't isn't.

This isn't correct logic.
https://doc.rust-lang.org/cargo/reference/workspaces.html describes the
specification. We do filesystem traversal to detect implicit members.
This is a little more expensive, but much more correct.

This helps supporting path dependencies - the current
incorrect logic incorrectly identifies any Cargo.toml file containing a
path dependency as expecting to live in a workspace, which breaks some
use-cases.
@illicitonion illicitonion force-pushed the splicer-workspace-membership branch from 11c0025 to 6d0d74e Compare December 5, 2024 09:41
@@ -1,6 +1,46 @@
[workspace]
members = ["tools/cross_installer", "tools/urls_generator"]
exclude = ["test_data"]
exclude = [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be a wild-card?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately not: rust-lang/cargo#6009

@@ -1208,9 +1157,6 @@ mod test {

[lib]
path = "lib.rs"

[dependencies]
neighbor = { path = "../neighbor" }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a unit test that shows path dependencies working correctly now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unit tests at the bottom of crate_universe/src/metadata/workspace_discoverer.rs which use the sample workspaces in crate_universe/test_data/workspace_examples show this behaviour is working.

Then there are integration tests through examples in examples/crate_universe_local_path

if [[ "$(uname)" == "Darwin" ]]; then
sed_i=(sed -i '')
fi
"${sed_i[@]}" -e 's#manifests = \["//crates_from_workspace:Cargo\.toml"\],#manifests = ["//crates_from_workspace:Cargo.toml", "//crates_from_workspace:'"$1"'/Cargo.toml"],#g' WORKSPACE.bazel
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this to support vendoring more things?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We run this example in two modes, and this script is for setting up the test data.

If you don't supply an arg to this script, it just vendors into a tmpdir somewhere external to the repo and pulls that in as a path dependency.

This line is to support the other mode - if you specify a relative path within this repo, it will vendor the crate into that path. Now that we correctly detect that vendored crate as a member of the workspace, we need to add it to the manifests of the repo rules :)

Copy link
Collaborator

@UebelAndre UebelAndre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@illicitonion illicitonion added this pull request to the merge queue Dec 5, 2024
Merged via the queue into bazelbuild:main with commit 72556e5 Dec 5, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants