Way to grep all dependencies?

Kinda like https://github.com/rust-secure-code/cargo-geiger but for any regexes.

You can install the cargo tree command:

cargo install cargo-tree

You can then list all dependencies with

cargo tree --no-indent
1 Like

I want to grep in source of dependencies.

Once you have built it, you can find the source of all dependencies you have used in any project in ~/.cargo/registry/src/

cargo tree is now a part of unstable cargo subcommands.

Is there any plugins like cargo grep to do grepping?

Not as far as I know.

If you run cargo vendor it'll copy the source code for all your dependencies into a vendor/ directory and from there you can use grep and vim like the rest of your codebase.

I believe cargo-vendor has been merged into the cargo tool itself, so it should all Just Work. The only downside is you've now got a vendor/ directory and cargo vendor may have made some tweaks to your .cargo/config file to point cargo at the vendored code instead of crates.io. This shouldn't be a problem if you're using version control because you can blow away any of the changes (e.g. git clean).

4 Likes

I was about to suggest cargo vendor too, and yes that's a built-in command now. It doesn't directly change .cargo/config, only suggests what that should look like.

4 Likes

Wow! Work perfectly! Thanks all!

Talk a little bit about my usecases: I used panic='abort' to build
cargo-expand but expand exits immediately after running.
I want to find where the panics are catched (with catch_unwind).

Does cargo-expand have any internal logging that may help yoi? If it uses something like env_logger you may be able to set the RUST_LOG environment variable to get more verbose output (e.g. RUST_LOG=debug cargo expand ... in bash).

Otherwise I've found the Visual Studio Code debugger to work pretty well once you get it set up.

Thanks for the sugesstion. I will try it next time.

Currently I've no longer used panic=abort to build cargo-expand.
Greping catch_unwind in cargo-expand and its dependencies reveals
some panics are catched at proc-macro(2) which I'm not familiar with.

@dtolnay, Do you support building with panic=abort for cargo-expand?

No. This is tracked in alexcrichton/proc-macro2#218.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.