CARGO-TREE(1)
π cargo-tree(1) π
okay bestie, pull up a chair π this is the manual page for cargo-tree from the General Commands Manual β yes, the whole thing, and yes, we're reading it together, no skimming allowed π«Ά
πΈ NAME πΈ
cargo-tree β display a tree visualization of a dependency graph π³β¨
πΈ SYNOPSIS πΈ
cargo tree [options]
πΈ DESCRIPTION πΈ
so basically? this command prints a whole tree of dependencies right into your terminal. iconic behavior, honestly π
here's what it looks like for a lil baby 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
see those lil (*) stars? those packages have been "de-duplicated" π« the deal is: their dependencies already got shown somewhere else in the graph, so Cargo is NOT repeating them, it's just pointing at them like "yeah, been there, done that." if you want the duplicates repeated anyway (chaos! love that for you), hit it with the --no-dedupe option.
and then!! the -e flag lets you pick which dependency kinds get shown. the features kind is the fun one β it flips the output so you can see the features enabled by each dependency. watch:
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 v1.0.10
in this tree, myproject depends on log with the serde feature. and log, in turn, depends on cfg-if with "default" features. β¨ when you're using -e features, it can be super helpful to also use the -i flag so you can see how the features flow into a package π β check the examples below for more on that.
π Feature Unification π
okay so here's the tea β: this command shows you a graph that's way closer to the feature-unified graph Cargo will actually build, not just whatever you scribbled into Cargo.toml. like, say you list the same dependency in both [dependencies] and [dev-dependencies] but with different features turned on. this command may merge all those features together and drop a (*) on one of the dependencies to flag it as the duplicate. sneaky but honest π
so 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. BUT β and this is important β it does not guarantee exact equivalence to what Cargo is actually going to build, because a compilation is complicated and depends on a whole pile of different factors. no cap.
want to learn more about feature unification? there's a dedicated section for it right here: https://doc.rust-lang.org/cargo/reference/features.html#feature-unification π¦
β¨ OPTIONS β¨
π³ Tree Options π³
-ispec,--invertspec β show the reverse dependencies for the given package. this flag inverts the whole tree and shows you the packages that depend on the one you named π
heads up: in a workspace, by default it will only show the package's reverse dependencies inside the tree of the workspace member in the current directory. you can use the --workspace flag to extend that so it shows the package's reverse dependencies across the entire workspace. and the -p flag can be used to show the package's reverse dependencies only within the subtree of the package you gave to -p.
--prunespec β prune the given package from the display of the dependency tree βοΈ--depthdepth β maximum display depth of the dependency tree. a depth of1displays the direct dependencies, for example π--no-dedupeβ do not de-duplicate repeated dependencies. usually, when a package has already displayed its dependencies, further occurrences won't re-display its dependencies, and they'll get a(*)to show it's already been shown. this flag makes those duplicates get repeated anyway π-d,--duplicatesβ show only dependencies which come in multiple versions (this implies--invert). when used with the-pflag, it only shows duplicates within the subtree of the given package.
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 π
-ekinds,--edgeskinds β the dependency kinds to display. takes a comma separated list of values:allβ show all edge kinds.normalβ show normal dependencies.buildβ show build dependencies.devβ show development dependencies.featuresβ show features enabled by each dependency. if this is the only kind given, then it will automatically include the other dependency kinds.no-normalβ do not include normal dependencies.no-buildβ do not include build dependencies.no-devβ do not include development dependencies.no-proc-macroβ do not include procedural macro dependencies.
β οΈ thenormal,build,dev, andalldependency kinds cannot be mixed with theno-normal,no-build, orno-devdependency kinds. pick a lane bestie π
the default is normal,build,dev.
--targettriple β filter dependencies matching the given target triple (https://doc.rust-lang.org/cargo/appendix/glossary.html#target). the default is the host platform. use the valueallto include all targets π―
π¨ Tree Formatting Options π¨
--charsetcharset β chooses the character set to use for the tree. valid values are "utf8" or "ascii". when unspecified, cargo will auto-select a value ποΈ-fformat,--formatformat β set the format string for each package. the default is"{p}".
this is an arbitrary string which will be used to display each package. the following strings will be replaced with the corresponding value:
{p}β the package name.{l}β the package license.{r}β the package repository URL.{f}β comma-separated list of package features that are enabled.{lib}β the name, as used in ausestatement, of the package's library.
--prefixprefix β sets how each line is displayed. the prefix value can be one of:indent(default) β shows each line indented as a tree π²depthβ show as a list, with the numeric depth printed before each entry π’noneβ show as a flat list π
π¦ 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 workspace's 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*β¦ β display only the specified packages. seecargo-pkgid(1)for the SPEC format. this flag may be specified multiple times and supports common Unix glob patterns like*,?and[]. however, to avoid your shell accidentally expanding glob patterns before Cargo handles them, you must use single quotes or double quotes around each pattern π--workspaceβ display all members in the workspace π--exclude*SPEC*β¦ β exclude the specified packages. must be used in conjunction with the--workspaceflag. this flag may be specified multiple times and supports common Unix glob patterns like*,?and[]. however, to avoid your shell accidentally expanding glob patterns before Cargo handles them, you must use single quotes or double quotes around each pattern π«
π Manifest Options π
--manifest-pathpath β path to theCargo.tomlfile. by default, Cargo searches for theCargo.tomlfile in the current directory or any parent directory π--lockedβ asserts that the exact same dependencies and versions are used as when the existingCargo.lockfile was originally generated. Cargo will exit with an error when either of the following scenarios arises:- the lock file is missing.
- Cargo attempted to change the lock file due to a different dependency resolution.
it may be used in environments where deterministic builds are desired, such as in CI pipelines π€
--offlineβ prevents Cargo from accessing the network for any reason. without this flag, Cargo will stop with an error if it needs to access the network and the network is not available. with this flag, Cargo will attempt to proceed without the network if possible.
π¨ beware! 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β equivalent to specifying both--lockedand--offlineβοΈ--lockfile-pathPATH β changes the path of the lockfile from the default (<workspace_root>/Cargo.lock) to PATH. PATH must end withCargo.lock(e.g.--lockfile-path /tmp/temporary-lockfile/Cargo.lock). note that providing--lockfile-pathwill ignore the existing lockfile at the default path, and instead will either use the lockfile from PATH, or write a new lockfile into the provided PATH if it doesn't exist. this flag can be used to run most commands in read-only directories, writing the lockfile into the provided 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-optionsflag to enable (see #14421https://github.com/rust-lang/cargo/issues/14421).
π Feature Selection π
the feature flags let you 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β the β¨featuresβ¨ you want turned on, separated by spaces or commas. Wanna poke a feature inside a workspace member? Use thepackage-name/feature-namesyntax. And bestie, you can drop this flag more than once β every feature you name gets activated. Obsessed.--all-featuresβ literally turn on every available feature of every selected package. Go big or go home π--no-default-featuresβ nope, we are NOT activating the default feature of the selected packages. Skipping it, periodt.
π Display Options π
-v,--verboseβ wants the tea? This gives verbose output. Say it twice for "very verbose" β that one spills extra stuff like dependency warnings and build script output. You can also set it with theterm.verboseconfig value <https://doc.rust-lang.org/cargo/reference/config.html>.-q,--quietβ do not print cargo log messages. Silence, iconic. You can also set it with theterm.quietconfig value <https://doc.rust-lang.org/cargo/reference/config.html>.--colorwhen β controls when colored output shows up. The valid values, bestie:auto(default): automatically detect if the terminal can handle color.always: always display colors. rainbow mode πnever: never display colors. monochrome era.
You can also set it with the term.color config value <https://doc.rust-lang.org/cargo/reference/config.html>.
π Common Options π
+toolchainβ if Cargo was installed with rustup and the first argument to cargo starts with+, it gets read as a rustup toolchain name (like+stableor+nightly). Peep the rustup documentation <https://rust-lang.github.io/rustup/overrides.html> for the whole lore on how toolchain overrides work.--configKEY=VALUE or PATH β overrides a Cargo configuration value. The argument is either TOML-syntaxKEY=VALUE, or a path to an extra configuration file. Can be specified multiple times. See the command-line overrides section <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides> for more.-CPATH β changes the current working directory before running any specified operations. This affects stuff like where cargo looks by default for the project manifest (Cargo.toml), and which directories it searches to discover.cargo/config.toml. Heads up: this option has to come before the command name, likecargo -C path/to/my-project build.
β οΈ This one is only available on the nightly channel <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and needs the -Z unstable-options flag to enable (see #10098 <https://github.com/rust-lang/cargo/issues/10098>). So, y'know, unstable behavior vibes.
-h,--helpβ prints help information. self-explanatory bestie π«Ά-Zflag β unstable (nightly-only) flags for Cargo. Runcargo -Z helpfor the deets.
πΈ ENVIRONMENT πΈ
See the reference <https://doc.rust-lang.org/cargo/reference/environment-variables.html> for all the details on environment variables that Cargo reads.
β¨ EXIT STATUS β¨
0: Cargo succeeded. slay π101: Cargo failed to complete. π
π¦ EXAMPLES π¦
- Display the tree for the package in the current directory:
cargo tree
- Display all the packages that depend on the
synpackage:
cargo tree -i syn
- Show the features enabled on each package:
cargo tree --format "{p} {f}"
- Show all packages that are built multiple times. This can happen if multiple semver-incompatible versions appear in the tree (like
1.0.0and2.0.0).
cargo tree -d
- Explain why features are enabled for the
synpackage:
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, follow the chain for each feature from the root to see why it's 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 the --no-dedupe flag to get the full output. iykyk π
π SEE ALSO π
and that's a wrap bestie π
this was CARGO-TREE(1), the manpage for the tree command, and yeah β the date is stamped right there at the bottom of the original. kisses, go read your dependency tree, it's giving main character energy π
π¦ where this page comes from
- ubuntu jammy: cargo-1.82 1.82.0+dfsg0ubuntu0~jammy-0ubuntu0.22.04.1 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.82 1.82.0+dfsg0ubuntu0-0ubuntu0.24.04.1 Β· Apache-2.0 WITH LLVM exception
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms