Tool Request: Module dependency graph


I’m trying to understand a reasonably large library, and it would really help if I could plot dependencies between modules, and which modues make use of which external crates. Is there anthing that can do that? Graphviz dot files would be fine.

I suspect it’s part of the AST with some paths collapsed? Or am I completely wrong? :slight_smile:


It sounds like you’re looking for something along the lines of cargo-graph, except instead of graphing how different crates depend on each other, you’re looking at the individual components inside the crate.

I’m not sure if there are any tools out there which can do something like that just yet, although one of the debug flags for rustc may have what you want.

After running rustc -Z help I noticed this debug flag:

-Z    dump-dep-graph -- dump the dependency graph to $RUST_DEP_GRAPH (default: /tmp/dep_graph.gv)

Just out of interest I tried this out on a fairly trivial project.

$ rustc --version
rustc 1.19.0-nightly (f4209651e 2017-05-05)
$ wc src/*.rs
  69  180 1776 src/
$ cargo rustc -- -Z dump-dep-graph
$ wc dep_graph.txt
   67778   371317 20343311
   39895   767941 11455694 dep_graph.txt
  107673  1139258 31799005 total
$ dot -Tsvg > deps.svg

So far dot has been running for about 6 minutes and one of my cores is pinned at 100%, but when it’s done I’ll let you know if the graph is any use :slight_smile:


I get Error: syntax error in line 17497 :’(


Scrap that - with unstable it works, sort of. I stopped the process with SIGINT when the svg size got above 100MB. Maybe it does it for all dependencies as well, which is not what I want. I might see how the crate one works and see if it’s possible to mod the code.


Using cargo-graph to generate a crate dependency tree:

% cargo install cargo-graph
% cargo graph | dot -Tpng >depgraph.png

And if you like pretty colours, it comes with many bells and whistles
for styling the output:


I’ve used cargo tree, which also allows you to inspect licenses of all dependencies.

$ cargo install cargo-tree
$ cargo tree -f '{p} {l}'

Edit: this doesn’t produce a module dependency graph, just at crate dependency graph. So not actually an answer to your question, oops.


I know you’re looking for some kind of visual way of exploring the library here, but when I’m trying to wrap my head around a new library the first thing I do is open up the docs with cargo doc --open.

It doesn’t give you a nice pretty graph like graphviz would, but by clicking through the various modules and types or seeing what struct is returned by which function usually helps to give you a nice overview of how the crate is laid out.


I also like which is in this genre of


Thanks for the replies. If a library is well written I would also recommend docs and cargo modules. My reason for needing this tool is a confusingly laid out library with poor documentation.