-
Notifications
You must be signed in to change notification settings - Fork 2.7k
clean: Add --workspace support #16263
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
Conversation
This commit optimizes implementation of `cargo clean -p` by reducing the amount of directory walks that take place. We now batch calls to `rm_rf_prefix_list`, thus potentially avoiding multiple walks over a single subdirectory. In practice this helps us significantly reduce the runtime for clearing large workspaces (as implemented in rust-lang#16263); for Zed, `cargo clean --workspace` went down from 73 seconds to 3 seconds. We have 216 workspace members. Co-authored-by: dino <dinojoaocosta@gmail.com>
|
r? @weihanglo rustbot has assigned @weihanglo. Use |
|
Note we rather have atomic commits for when things are merged rather than having small review feedback steps, see https://doc.crates.io/contrib/process/working-on-cargo.html#submitting-a-pull-request |
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.
- During testing we've found that
Workspace::membersreturns path dependencies of workspace members as workspace members; this means thatcargo clean --workspacewill clean up artifacts of path dependencies as well. We are not sure if that's a good behaviour and would love to get some more guidance on it. ↩
This is a documented behavior, so they should be pruned as well.
All path dependencies residing in the workspace directory automatically become members. Additional members can be listed with the members key, which should be an array of strings containing directories with Cargo.toml files.
See also
cargo/src/cargo/core/workspace.rs
Lines 860 to 914 in 745aae6
| fn find_path_deps( | |
| &mut self, | |
| manifest_path: &Path, | |
| root_manifest: &Path, | |
| is_path_dep: bool, | |
| ) -> CargoResult<()> { | |
| let manifest_path = paths::normalize_path(manifest_path); | |
| if self.members.contains(&manifest_path) { | |
| return Ok(()); | |
| } | |
| if is_path_dep && self.root_maybe().is_embedded() { | |
| // Embedded manifests cannot have workspace members | |
| return Ok(()); | |
| } | |
| if is_path_dep | |
| && !manifest_path.parent().unwrap().starts_with(self.root()) | |
| && self.find_root(&manifest_path)? != self.root_manifest | |
| { | |
| // If `manifest_path` is a path dependency outside of the workspace, | |
| // don't add it, or any of its dependencies, as a members. | |
| return Ok(()); | |
| } | |
| if let WorkspaceConfig::Root(ref root_config) = | |
| *self.packages.load(root_manifest)?.workspace_config() | |
| { | |
| if root_config.is_excluded(&manifest_path) { | |
| return Ok(()); | |
| } | |
| } | |
| debug!("find_path_deps - {}", manifest_path.display()); | |
| self.members.push(manifest_path.clone()); | |
| let candidates = { | |
| let pkg = match *self.packages.load(&manifest_path)? { | |
| MaybePackage::Package(ref p) => p, | |
| MaybePackage::Virtual(_) => return Ok(()), | |
| }; | |
| self.member_ids.insert(pkg.package_id()); | |
| pkg.dependencies() | |
| .iter() | |
| .map(|d| (d.source_id(), d.package_name())) | |
| .filter(|(s, _)| s.is_path()) | |
| .filter_map(|(s, n)| s.url().to_file_path().ok().map(|p| (p, n))) | |
| .map(|(p, n)| (p.join("Cargo.toml"), n)) | |
| .collect::<Vec<_>>() | |
| }; | |
| for (path, name) in candidates { | |
| self.find_path_deps(&path, root_manifest, true) | |
| .with_context(|| format!("failed to load manifest for dependency `{}`", name)) | |
| .map_err(|err| ManifestError::new(err, manifest_path.clone()))?; | |
| } | |
| Ok(()) | |
| } |
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 see, thank you!
330e66b to
7833c38
Compare
Co-authored-by: Dino <dino@zed.dev>
7833c38 to
a2f4995
Compare
Co-authored-by: Dino <dino@zed.dev>
a2f4995 to
ecc89a8
Compare
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as resolved.
This comment was marked as resolved.
|
@rfcbot fcp merge T-cargo This adds a The style of "operate on all dependencies by default, select packages among anything within the dependency tree" model that this has mirrors what we have for |
|
Team member @epage has proposed to merge 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. |
|
🔔 This is now entering its final comment period, as per the review above. 🔔 |
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.
We likely don't need to wait the 10 days. If nothing else, we can always revert.
Update cargo submodule 7 commits in 9fa462fe3a81e07e0bfdcc75c29d312c55113ebb..2a7c4960677971f88458b0f8b461a866836dff59 2025-11-21 20:49:51 +0000 to 2025-11-25 19:58:07 +0000 - docs(config-include): prepare for doc stabilization (rust-lang/cargo#16301) - fix(config-include): remove support of single string shorthand (rust-lang/cargo#16298) - Revert "feat: Do not lock the artifact-dir for check builds" (rust-lang/cargo#16299) - clean: Add --workspace support (rust-lang/cargo#16263) - feat(tree): Add more native completions (rust-lang/cargo#16296) - fix(package): exclude target/package from backups (rust-lang/cargo#16272) - test: re-enable test since not flaky anymore (rust-lang/cargo#16287)
Update cargo submodule 7 commits in 9fa462fe3a81e07e0bfdcc75c29d312c55113ebb..2a7c4960677971f88458b0f8b461a866836dff59 2025-11-21 20:49:51 +0000 to 2025-11-25 19:58:07 +0000 - docs(config-include): prepare for doc stabilization (rust-lang/cargo#16301) - fix(config-include): remove support of single string shorthand (rust-lang/cargo#16298) - Revert "feat: Do not lock the artifact-dir for check builds" (rust-lang/cargo#16299) - clean: Add --workspace support (rust-lang/cargo#16263) - feat(tree): Add more native completions (rust-lang/cargo#16296) - fix(package): exclude target/package from backups (rust-lang/cargo#16272) - test: re-enable test since not flaky anymore (rust-lang/cargo#16287)
This commit optimizes implementation of `cargo clean -p` by reducing the amount of directory walks that take place. We now batch calls to `rm_rf_prefix_list`, thus potentially avoiding multiple walks over a single subdirectory. In practice this helps us significantly reduce the runtime for clearing large workspaces (as implemented in rust-lang#16263); for Zed, `cargo clean --workspace` went down from 73 seconds to 3 seconds. We have 216 workspace members. Co-authored-by: dino <dinojoaocosta@gmail.com>
This commit optimizes implementation of `cargo clean -p` by reducing the amount of directory walks that take place. We now batch calls to `rm_rf_prefix_list`, thus potentially avoiding multiple walks over a single subdirectory. In practice this helps us significantly reduce the runtime for clearing large workspaces (as implemented in rust-lang#16263); for Zed, `cargo clean --workspace` went down from 73 seconds to 3 seconds. We have 216 workspace members. Co-authored-by: dino <dinojoaocosta@gmail.com>
This commit optimizes implementation of `cargo clean -p` by reducing the amount of directory walks that take place. We now batch calls to `rm_rf_prefix_list`, thus potentially avoiding multiple walks over a single subdirectory. In practice this helps us significantly reduce the runtime for clearing large workspaces (as implemented in rust-lang#16263); for Zed, `cargo clean --workspace` went down from 73 seconds to 3 seconds. We have 216 workspace members. Co-authored-by: dino <dinojoaocosta@gmail.com>
This commit optimizes implementation of `cargo clean -p` by reducing the amount of directory walks that take place. We now batch calls to `rm_rf_prefix_list`, thus potentially avoiding multiple walks over a single subdirectory. In practice this helps us significantly reduce the runtime for clearing large workspaces (as implemented in rust-lang#16263); for Zed, `cargo clean --workspace` went down from 73 seconds to 3 seconds. We have 216 workspace members. Co-authored-by: dino <dinojoaocosta@gmail.com>
This commit optimizes implementation of `cargo clean -p` by reducing the amount of directory walks that take place. We now batch calls to `rm_rf_prefix_list`, thus potentially avoiding multiple walks over a single subdirectory. In practice this helps us significantly reduce the runtime for clearing large workspaces (as implemented in rust-lang#16263); for Zed, `cargo clean --workspace` went down from 73 seconds to 3 seconds. We have 216 workspace members. Co-authored-by: dino <dinojoaocosta@gmail.com>
This commit optimizes implementation of `cargo clean -p` by reducing the amount of directory walks that take place. We now batch calls to `rm_rf_prefix_list`, thus potentially avoiding multiple walks over a single subdirectory. In practice this helps us significantly reduce the runtime for clearing large workspaces (as implemented in rust-lang#16263); for Zed, `cargo clean --workspace` went down from 73 seconds to 3 seconds. We have 216 workspace members. Co-authored-by: dino <dinojoaocosta@gmail.com> Co-authored-by: Ed Page <eopage@gmail.com>
This commit optimizes implementation of `cargo clean -p` by reducing the amount of directory walks that take place. We now batch calls to `rm_rf_prefix_list`, thus potentially avoiding multiple walks over a single subdirectory. In practice this helps us significantly reduce the runtime for clearing large workspaces (as implemented in rust-lang#16263); for Zed, `cargo clean --workspace` went down from 73 seconds to 3 seconds. We have 216 workspace members. Co-authored-by: dino <dinojoaocosta@gmail.com> Co-authored-by: Ed Page <eopage@gmail.com>
This commit optimizes implementation of `cargo clean -p` by reducing the amount of directory walks that take place. We now walk each directory at most once and add to the list of files to be cleaned, step by step. In practice this helps us significantly reduce the runtime for clearing large workspaces (as implemented in rust-lang#16263); for Zed, `cargo clean --workspace` went down from 73 seconds to 3 seconds. We have 216 workspace members. Co-authored-by: dino <dinojoaocosta@gmail.com> Co-authored-by: Ed Page <eopage@gmail.com>
This commit optimizes implementation of `cargo clean -p` by reducing the amount of directory walks that take place. We now walk each directory at most once and add to the list of files to be cleaned, step by step. In practice this helps us significantly reduce the runtime for clearing large workspaces (as implemented in rust-lang#16263); for Zed, `cargo clean --workspace` went down from 73 seconds to 3 seconds. We have 216 workspace members. Co-authored-by: dino <dinojoaocosta@gmail.com> Co-authored-by: Ed Page <eopage@gmail.com>
This commit optimizes implementation of `cargo clean -p` by reducing the amount of directory walks that take place. We now walk each directory at most once and add to the list of files to be cleaned, step by step. In practice this helps us significantly reduce the runtime for clearing large workspaces (as implemented in rust-lang#16263); for Zed, `cargo clean --workspace` went down from 73 seconds to 3 seconds. We have 216 workspace members. Co-authored-by: dino <dinojoaocosta@gmail.com> Co-authored-by: Ed Page <eopage@gmail.com>
This commit optimizes implementation of `cargo clean -p` by reducing the amount of directory walks that take place. We now walk each directory at most once and add to the list of files to be cleaned, step by step. In practice this helps us significantly reduce the runtime for clearing large workspaces (as implemented in rust-lang#16263); for Zed, `cargo clean --workspace` went down from 73 seconds to 3 seconds. We have 216 workspace members. Co-authored-by: dino <dinojoaocosta@gmail.com> Co-authored-by: Ed Page <eopage@gmail.com>
This commit optimizes implementation of `cargo clean -p` by reducing the amount of directory walks that take place. We now walk each directory at most once and add to the list of files to be cleaned, step by step. In practice this helps us significantly reduce the runtime for clearing large workspaces (as implemented in rust-lang#16263); for Zed, `cargo clean --workspace` went down from 73 seconds to 3 seconds. We have 216 workspace members. Co-authored-by: dino <dinojoaocosta@gmail.com> Co-authored-by: Ed Page <eopage@gmail.com>
This commit optimizes implementation of `cargo clean -p` by reducing the amount of directory walks that take place. We now walk each directory at most once and add to the list of files to be cleaned, step by step. In practice this helps us significantly reduce the runtime for clearing large workspaces (as implemented in rust-lang#16263); for Zed, `cargo clean --workspace` went down from 73 seconds to 3 seconds. We have 216 workspace members. Co-authored-by: dino <dinojoaocosta@gmail.com> Co-authored-by: Ed Page <eopage@gmail.com>
) Co-authored-by: dino <dinojoaocosta@gmail.com> ### What does this PR try to resolve? This commit optimizes implementation of `cargo clean -p` by reducing the amount of directory walks that take place. We now batch calls to `rm_rf_prefix_list`, thus potentially avoiding multiple walks over a single subdirectory. In practice this helps us significantly reduce the runtime for clearing large workspaces (as implemented in #16263); for Zed, `cargo clean --workspace` went down from 73 seconds to 3 seconds. We have 216 workspace members. ### How to test and review this PR? We've tested it by hand, running it against `regex`, `ruff` and `zed` codebases. This PR is still marked as draft, as I don't love the code. I would also understand if y'all were against merging this, given that new build directory layout is in flight.
Co-authored-by: dino dinojoaocosta@gmail.com
What does this PR try to resolve?
Fixes #14720.
How to test and review this PR?
We tested this change manually on Ruff repository. We've also added a test1.
Footnotes
During testing we've found that
Workspace::membersreturns path dependencies of workspace members as workspace members; this means thatcargo clean --workspacewill clean up artifacts of path dependencies as well. We are not sure if that's a good behaviour and would love to get some more guidance on it. ↩