Skip to content
Cargo subcommand for building dependency graphs of Rust projects
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.
tests fix error when depth is specified and deps have been excluded Feb 22, 2020
.travis.yml forbid unsafe code and add badge Sep 9, 2019 update version to 1.4.1 Feb 22, 2020
Cargo.toml update version to 1.4.1 Feb 22, 2020
LICENSE-MIT update version to 1.4.0 Feb 22, 2020
safe-client-libs.png add --subgraph option Feb 23, 2019
tokei.png fix a bug where root dependency kinds were being overwritten Feb 23, 2019


Build Status Documentation unsafe forbidden Downloads Issues LoC Coverage Status License: MIT

Table of Contents


Cargo subcommand for building dependency graphs of Rust projects.

This project is an improvement on the unmaintained and buggy cargo-graph.


safe_app dependencies


cargo-deps can be installed with cargo install:

cargo install cargo-deps


First, make sure you have graphviz installed.

Next, just cd into the Rust project directory you want to graph and run:

cargo deps | dot -Tpng > graph.png

That's it! graph.png will contain the graph (you can change its name, of course!)

Note that > may not work if the output file already exists, in which case you can try >|.

Dependency Kinds

The default behavior is to exclude optional, dev, and build dependencies. To see all dependencies, pass --all-deps:

cargo deps --all-deps | dot -Tpng > graph.png

Dependencies are colored depending on their kind:

  • Black: regular dependency
  • Purple: build dependency
  • Blue: dev dependency
  • Red: optional dependency

A dependency can be of more than one kind. In such cases, it is colored with the following priority:

Regular -> Build -> Dev -> Optional

For example, if a dependency is both a build and a dev dependency, then it will be colored as a build dependency. If, however, you pass the --dev-deps option instead of --all-deps, the dependency will be colored as a dev dependency (as the build-dependency graph will not be shown).


Some Rust projects have really big dependency trees and maybe you just want to display certain dependencies, like the ones in the same workspace. Fortunately, cargo-deps provides the --filter option for this use case. Unfortunately, you have to explicitly list all the dependencies you want to keep, and cargo-deps doesn't detect workspaces just yet.


It can be useful to exclude certain crates from the final graph. This can be achieved with the --exclude flag taking the undesired crates as arguments.


In order to constrain the size of graphs and make them cleaner, it is possible to limit the output to dependencies within a certain depth using the --depth option.

Filtering transitive edges

For large dependency graphs, the --no-transitive-deps option can be used to filter out edges that are "covered" by a transitive dependency, which can make visual parsing a little easier by omitting some redundant edges. For example, if crate A depends directly on crate B and C, and crate B depends directly on crate C, this option would omit the edge from A to C. To illustrate, compare the default dependency graph for Tokei, generated by cargo deps, to the graph with transitive edges removed, generated by cargo deps --no-transitive-deps.


You can visually group a set of dependencies by using the --subgraph command.


Tokei -- graph

This was generated using the command:

cargo deps -I --all-deps --no-regular-deps | dot -Tpng > tokei.png

SAFE Client Libs -- graph

This was generated using the following whopper of a command to display only MaidSafe dependencies:

cargo deps --all-deps --include-orphans --subgraph safe_app safe_app_jni safe_authenticator safe_authenticator_jni safe_core --subgraph-name "SAFE Client Libs" --filter accumulator config_file_handler crust ffi_utils fake_clock lru_time_cache maidsafe_utilities parsec resource_proof routing rust_sodium safe_app safe_app_jni safe_authenticator safe_authenticator_jni safe_bindgen safe_core safe_crypto safe_vault secure_serialisation self_encryption system_uri tokio_utp --manifest-path safe_app/Cargo.toml | dot -Tpng -Nfontname=Iosevka -Gfontname=Iosevka > safe-client-libs.png

More info

Run cargo deps -h to see all available options.


cargo-deps is released under the terms of the MIT license. See the LICENSE-MIT file for the details.


cargo-deps dependencies



You can’t perform that action at this time.