table of contents
CARGO-TREE(1) | General Commands Manual | CARGO-TREE(1) |
NAME¶
cargo-tree — Display a tree visualization of a dependency graph
SYNOPSIS¶
cargo tree [options]
DESCRIPTION¶
This command will display a tree of dependencies to the terminal. An example of a simple project that depends on the “rand” package:
myproject v0.1.0 (/myproject) `-- rand v0.7.3
|-- getrandom v0.1.14
| |-- cfg-if v0.1.10
| `-- libc v0.2.68
|-- libc v0.2.68 (*)
|-- rand_chacha v0.2.2
| |-- ppv-lite86 v0.2.6
| `-- rand_core v0.5.1
| `-- getrandom v0.1.14 (*)
`-- rand_core v0.5.1 (*) [build-dependencies] `-- cc v1.0.50
Packages marked with (*) have been “de-duplicated”. The dependencies for the package have already been shown elsewhere in the graph, and so are not repeated. Use the --no-dedupe option to repeat the duplicates.
The -e flag can be used to select the dependency kinds to display. The “features” kind changes the output to display the features enabled by each dependency. For example, cargo tree -e features:
myproject v0.1.0 (/myproject) `-- log feature "serde"
`-- log v0.4.8
|-- serde v1.0.106
`-- cfg-if feature "default"
`-- cfg-if v0.1.10
In this tree, myproject depends on log with the serde feature. log in turn depends on cfg-if with “default” features. When using -e features it can be helpful to use -i flag to show how the features flow into a package. See the examples below for more detail.
Feature Unification¶
This command shows a graph much closer to a feature-unified graph Cargo will build, rather than what you list in Cargo.toml. For instance, if you specify the same dependency in both [dependencies] and [dev-dependencies] but with different features on. This command may merge all features and show a (*) on one of the dependency to indicate the duplicate.
As a result, for a mostly equivalent overview of what cargo build does, cargo tree -e normal,build is pretty close; for a mostly equivalent overview of what cargo test does, cargo tree is pretty close. However, it doesn’t guarantee the exact equivalence to what Cargo is going to build, since a compilation is complex and depends on lots of different factors.
To learn more about feature unification, check out this dedicated section <https://doc.rust-lang.org/cargo/reference/features.html#feature-unification>.
OPTIONS¶
Tree Options¶
-i spec, --invert spec
Note that in a workspace, by default it will only display the package’s reverse dependencies inside the tree of the workspace member in the current directory. The --workspace flag can be used to extend it so that it will show the package’s reverse dependencies across the entire workspace. The -p flag can be used to display the package’s reverse dependencies only with the subtree of the package given to -p.
--prune spec
--depth depth
--no-dedupe
-d, --duplicates
It can be beneficial for build times and executable sizes to avoid building that same package multiple times. This flag can help identify the offending packages. You can then investigate if the package that depends on the duplicate with the older version can be updated to the newer version so that only one instance is built.
-e kinds, --edges kinds
The normal, build, dev, and all dependency kinds cannot be mixed with no-normal, no-build, or no-dev dependency kinds.
The default is normal,build,dev.
--target triple
Tree Formatting Options¶
--charset charset
-f format, --format format
This is an arbitrary string which will be used to display each package. The following strings will be replaced with the corresponding value:
--prefix prefix
Package Selection¶
By default, when no package selection options are given, the packages selected depend on the selected manifest file (based on the current working directory if --manifest-path is not given). If the manifest is the root of a workspace then the workspaces default members are selected, otherwise only the package defined by the manifest will be selected.
The default members of a workspace can be set explicitly with the workspace.default-members key in the root manifest. If this is not set, a virtual workspace will include all workspace members (equivalent to passing --workspace), and a non-virtual workspace will include only the root crate itself.
-p spec…, --package spec…
--workspace
--exclude SPEC…
Manifest Options¶
--manifest-path path
--locked
It may be used in environments where deterministic builds are desired, such as in CI pipelines.
--offline
Beware that this may result in different dependency resolution than online mode. Cargo will restrict itself to crates that are downloaded locally, even if there might be a newer version as indicated in the local copy of the index. See the cargo-fetch(1) command to download dependencies before going offline.
May also be specified with the net.offline config value <https://doc.rust-lang.org/cargo/reference/config.html>.
--frozen
--lockfile-path PATH
This option is only available on the nightly channel <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and requires the -Z unstable-options flag to enable (see #14421 <https://github.com/rust-lang/cargo/issues/14421>).
Feature Selection¶
The feature flags allow you to control which features are enabled. When no feature options are given, the default feature is activated for every selected package.
See the features documentation <https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options> for more details.
-F features, --features features
--all-features
--no-default-features
Display Options¶
-v, --verbose
-q, --quiet
--color when
May also be specified with the term.color config value <https://doc.rust-lang.org/cargo/reference/config.html>.
Common Options¶
+toolchain
--config KEY=VALUE or PATH
-C PATH
This option is only available on the nightly channel <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and requires the -Z unstable-options flag to enable (see #10098 <https://github.com/rust-lang/cargo/issues/10098>).
-h, --help
-Z flag
ENVIRONMENT¶
See the reference <https://doc.rust-lang.org/cargo/reference/environment-variables.html> for details on environment variables that Cargo reads.
EXIT STATUS¶
EXAMPLES¶
cargo tree
cargo tree -i syn
cargo tree --format "{p} {f}"
cargo tree -d
cargo tree -e features -i syn
The -e features flag is used to show features. The -i flag is used to invert the graph so that it displays the packages that depend on syn. An example of what this would display:
syn v1.0.17 |-- syn feature "clone-impls" | `-- syn feature "default" | `-- rustversion v1.0.2 | `-- rustversion feature "default" | `-- myproject v0.1.0 (/myproject) | `-- myproject feature "default" (command-line) |-- syn feature "default" (*) |-- syn feature "derive" | `-- syn feature "default" (*) |-- syn feature "full" | `-- rustversion v1.0.2 (*) |-- syn feature "parsing" | `-- syn feature "default" (*) |-- syn feature "printing" | `-- syn feature "default" (*) |-- syn feature "proc-macro" | `-- syn feature "default" (*) `-- syn feature "quote"
|-- syn feature "printing" (*)
`-- syn feature "proc-macro" (*)
To read this graph, you can follow the chain for each feature from the root to see why it is included. For example, the “full” feature is added by the rustversion crate which is included from myproject (with the default features), and myproject is the package selected on the command-line. All of the other syn features are added by the “default” feature (“quote” is added by “printing” and “proc-macro”, both of which are default features).
If you’re having difficulty cross-referencing the de-duplicated (*) entries, try with the --no-dedupe flag to get the full output.