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

Respect the members field of a workspace Cargo.toml #97

Open
nipunn1313 opened this issue Dec 13, 2023 · 2 comments
Open

Respect the members field of a workspace Cargo.toml #97

nipunn1313 opened this issue Dec 13, 2023 · 2 comments

Comments

@nipunn1313
Copy link

https://doc.rust-lang.org/cargo/reference/workspaces.html#the-members-and-exclude-fields

For example if the workspace Cargo.toml has

[workspace]
members = ["crates/*", "crates_private/*"]

Then ideally cargo-machete only searches the crates/ and crates_private/ directories.
This is particularly useful in monorepos where there are a large number of files not included in the workspace.

Thanks for the tool - it's great!

@bnjbvr
Copy link
Owner

bnjbvr commented Dec 14, 2023

Thanks for opening an issue. I, for one, quite like that I could run the tool independently of workspaces in a directory that contained multiple Rust projects (unrelated to each other, i.e. no workspaces). And it'd be an API breaking change. So maybe we can introduce a CLI flag that respects the workspace by default.

Out of curiosity, you're saying it's useful in monorepos. Right now cargo-machete will look only for Cargo.toml file, so it only depends on the number of directories; do you see a large difference in runtime, when comparing:

  • running from the root
  • sum of (running in each directory belonging to the workspace)

@de-vri-es
Copy link

How about: find all Cargo.toml files at or below the current working directory, but to not crawl subdirectories if a Cargo.toml is found. Instead call cargo-metadata to find the workspace members and check those.

On problem I have now is that generated crates in the target directory also get checked. For example, trybuild generates a crate to run compile-fail tests. These may easily end up using less dependencies, but the generated crate copies all dependencies, just in case.

Alternatively, but more difficult I think: find all Cargo.toml files, but ignore target directories of workspaces. However, this still requires something like cargo-metadata to correctly identify the target directory.

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

No branches or pull requests

3 participants