regexident/cargo-modules

Building up a holistic understanding of a larger Rust system

Closed this issue · 2 comments

When the context of dependencies and analyzing them, the need is most burning in the larger project. Just recently, Microsoft opensourced OneFuzz, Rust based fuzzing tool, that has quite a bunch of crates.

However, I cannot get the dependency graphs extracted with cargo-modules from OneFuzz. There is a big number of Cargo.toml files and I cannot figure out how to use cargo-modules properly to get the dependencies extracted from all of the crates to build up a holistic dependency data model of that project.

Below shell excerpt shows how I can improve the result of the data by removing main level Cargo.toml file but am still out of clue how to get stuff executed properly to identify all the dependencies between each create.

➜  onefuzz git:(main) cargo modules -p -o tree

atexit : crate
 ├── asan : orphan
 ├── az_copy : orphan
 ├── blob : orphan
 ├── cmd : orphan
 ├── expand : orphan
 ├── fs : orphan
 ├── input_tester : orphan
 ├── libfuzzer : orphan
 ├── machine_id : orphan
 ├── monitor : orphan
 ├── sha256 : orphan
 ├── system : orphan
 ├── telemetry : orphan
 ├── triage : orphan
 └── uploader : orphan

➜  onefuzz git:(main) rm ../Cargo.toml 
➜  onefuzz git:(main) ✗ cargo modules -p -o tree

onefuzz : crate
 ├── asan : public
 ├── az_copy : public
 ├── blob : public
 │   ├── client : orphan
 │   └── url : orphan
 ├── cmd : public
 ├── expand : public
 ├── fs : public
 ├── input_tester : public
 ├── libfuzzer : public
 ├── machine_id : public
 ├── monitor : public
 ├── sha256 : public
 ├── system : public
 ├── telemetry : public
 ├── triage : public @ #[cfg(target_os = "linux")]
 └── uploader : public

Sorry for my mediocre Rust competence here. I am seeking for something similar like madge but for Rust, that would enable easy extraction of the dependency data from Rust projects.

Hi @villelaitila!

It seems that you are interested in the inter-crate dependencies (i.e. crate -> crate)?

cargo-modules is for intra-crate module structure and use-dependencies (i.e. mod -> mod).

As such you may want to try cargo-tree, cargo-deps instead.


Regarding you usage of cargo-modules: The transition from Rust 2015 to Rust 2018 made path resolution quite a bit more complicated and hasn't been resolved fully in cargo-modules, yet. Also workspaces aren't properly supported yet, unfortunately. As such cargo-modules needs to be run from a package's root directory, directly. It's not you, it's us.

Thanks for helping me to the right direction.