CARGO-TREE(1)
π CARGO-TREE(1) β like, the whole manual, bestie π
okay so this is the manual page for cargo-tree, which lives in the General Commands Manual section of your man pages. it's giving "here's how you look at your dependency graph and feel something." let's get into it β¨
πΈ NAME
cargo-tree β displays a tree visualization of a dependency graph. that's it. that's the whole job. and she does it gorgeously. π
β¨ SYNOPSIS
cargo tree [options]
literally just that. <purple>options</purple> are where all the fun lives, and there are a LOT of them (iykyk). π
π¦ DESCRIPTION
so bestie, this command shows you a tree of dependencies right there in your terminal. picture a simple project that depends on the rand package β here's what that looks like:
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 little (*) marks? π packages marked with (*) have been "de-duplicated". translation: the dependencies for that package have already been shown somewhere else in the graph, so she's not about to repeat herself. if you WANT the duplicates repeated (no judgement, some people are completionists), use the --no-dedupe option. π«Ά
β¨ pro tip that is actually just a fact: the-eflag lets you pick which dependency kinds get displayed. and the"features"kind? that one changes the whole output to show you the features enabled by each dependency. iconic behaviour. 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 v1.0.10
okay so let's read this tree together: myproject depends on log with the serde feature. and log, in turn, depends on cfg-if with "default" features. cute, right? π
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. there are examples below with more detail β go look, I'll wait. π
π Feature Unification
this command shows you a graph that's much closer to a feature-unified graph β like, the one Cargo is actually going to build β rather than whatever you happened to list in Cargo.toml. for instance: say you specify the same dependency in both [dependencies] and [dev-dependencies], but with different features turned on. this command may merge all the features and show a (*) on one of the dependencies to indicate the duplicate. periodt. π
so as a result β and this is the useful part β if you want a mostly equivalent overview of what cargo build does, then cargo tree -e normal,build is pretty close. and if you want a mostly equivalent overview of what cargo test does, then plain old cargo tree is pretty close. πΈ
β οΈ however β and I need you to hear me on this β 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. do not come for her when the tree and the build disagree. she warned you fr fr. π
wanna learn more about feature unification? there's a whole dedicated section for it at:
https://doc.rust-lang.org/cargo/reference/features.html#feature-unification
go read it, it's giving educational. π¦
β¨ OPTIONS β¨
π³ Tree Options
-ispec,--invertspec β bestie, this one flips the whole thing π it shows the reverse dependencies for the package you name β so instead of "what does this need", you get "who needs this". It literally inverts the tree and displays the packages that depend on the given package.
Heads up though: in a workspace, by default it only shows the package's reverse dependencies inside the tree of the workspace member in the current directory. Want more? The--workspaceflag extends it so you get the package's reverse dependencies across the entire workspace. And the-pflag can display the package's reverse dependencies only with the subtree of the package given to-p. πΈ
--prunespec β snips the given package right out of the dependency tree display. Gone. Not invited. π--depthdepth β how deep do we go, bestie? Maximum display depth of the dependency tree. A depth of1displays the direct dependencies, for example.--no-dedupeβ ok so normally, when a package has already shown its dependencies, further occurrences won't re-display them and instead get a little(*)to say "yeah we already did this one". This flag says no ma'am, repeat those duplicates anyway. π-d,--duplicatesβ shows only dependencies that come in multiple versions (and yes, it implies--invert). When you use it with the-pflag, it only shows duplicates within the subtree of the given package.
And here's the tea β β avoiding building that same package multiple times can be genuinely beneficial for build times and executable sizes. This flag helps you identify the offending packages. Then you can go investigate whether 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. slay, efficiency π«Ά
-ekinds,--edgeskinds β which dependency kinds do we 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 withno-normal,no-build, orno-devdependency kinds. Pick a lane, bestie.
The default is normal,build,dev.
--targettriple β filters 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 β picks the character set for the tree. Valid values areutf8orascii. When unspecified, cargo will auto-select a value. It just knows. β¨-fformat,--formatformat β sets the format string for each package. The default is{p}.
This is an arbitrary string which will be used to display each package. These strings get swapped out for 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. that's just how it is, no cap π
-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 β and this is the important bit β 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. all of them. the whole squad. π«Ά--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. same energy as above fr fr
π Manifest Options
--manifest-pathpath β path to theCargo.tomlfile. By default, Cargo searches for theCargo.tomlfile in the current directory or any parent directory. it goes looking, bestie π--frozen,--lockedβ either of these flags requires that theCargo.lockfile is up-to-date. If the lock file is missing, or it needs to be updated, Cargo will exit with an error. The--frozenflag also prevents Cargo from attempting to access the network to determine if it is out-of-date.
These may be used in environments where you want to assert that the Cargo.lock file is up-to-date (such as a CI build) or want to avoid network access. π§
--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 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).
π 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. cute and simple π
See the features documentation (https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options) for more details.
-Ffeatures,--featuresfeatures β space or comma separated list of features to activate. Features of workspace members may be enabled withpackage-name/feature-namesyntax. This flag may be specified multiple times, which enables all specified features. stacking them like accessories β¨--all-featuresβ activate all available features of all selected packages. go big or go home π₯--no-default-featuresβ do not activate the default feature of the selected packages. respectfully declining π
π Display Options
-v,--verboseβ use verbose output. May be specified twice for "very verbose" output which includes extra output such as dependency warnings and build script output. May also be specified with theterm.verboseconfig value (https://doc.rust-lang.org/cargo/reference/config.html). spill the tea, twice β-q,--quietβ do not print cargo log messages. May also be specified with theterm.quietconfig value (https://doc.rust-lang.org/cargo/reference/config.html). shhh π€«--colorwhen β control when colored output is used. Valid values:auto(default): Automatically detect if color support is available on the terminal.always: Always display colors.never: Never display colors.
May also be specified with the term.color config value (https://doc.rust-lang.org/cargo/reference/config.html). π
π Common Options
+toolchainβ if Cargo has been installed with rustup, and the first argument to cargo begins with+, it will be interpreted as a rustup toolchain name (such as+stableor+nightly). See the rustup documentation (https://rust-lang.github.io/rustup/overrides.html) for more information about how toolchain overrides work.--configKEY=VALUE or PATH β overrides a Cargo configuration value. The argument should be in TOML syntax ofKEY=VALUE, or provided as a path to an extra configuration file. This flag may be specified multiple times. See the command-line overrides section (https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides) for more information.-CPATH β changes the current working directory before executing any specified operations. This affects things like where cargo looks by default for the project manifest (Cargo.toml), as well as the directories searched for discovering.cargo/config.toml, for example. This option must appear before the command name, for examplecargo -C path/to/my-project build. order matters bestie π«Ά
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 #10098https://github.com/rust-lang/cargo/issues/10098).
-h,--helpβ prints help information. when in doubt, ask π-Zflag β unstable (nightly-only) flags to Cargo. Runcargo -Z helpfor details.
π ENVIRONMENT
See the reference (https://doc.rust-lang.org/cargo/reference/environment-variables.html) for details on environment variables that Cargo reads. π
π¦ EXIT STATUS
0: Cargo succeeded. we ate. π101: Cargo failed to complete. it's giving tragedy π
β¨ EXAMPLES β¨
okay bestie this is the part where it all clicks, fr fr. five little recipes, each one a whole vibe π
- Wanna see the tree for whatever package is chillin' in your current directory? Say less:
cargo tree
- Wanna know every single package that depends on the
synpackage? Invert that graph, queen:
cargo tree -i syn
- Wanna peek at which features are enabled on each package? We're showing off today:
cargo tree --format "{p} {f}"
- Wanna catch all the packages that get built multiple times? π This can happen when multiple semver-incompatible versions show up in the tree (like
1.0.0and2.0.0) β so they just both gotta be there, no cap.
cargo tree -d
- Wanna explain why features are enabled for the
synpackage? This is the main character move:
cargo tree -e features -i syn
The -e features flag is what shows the features, and the -i flag is what inverts the graph so it displays the packages that depend on syn instead of the ones syn depends on. Here's an example of what that 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 (and btw βquoteβ is added by βprintingβ and βproc-macroβ, both of which are default features). It's giving detective work πβ¨
If you're having difficulty cross-referencing the de-duplicated(*)entries, try with the--no-dedupeflag to get the full output. That's your rescue, bestie π«Ά
πΈ SEE ALSO πΈ
okay that's the whole page, and the lil footer at the very bottom just says CARGO-TREE(1) β that's the source/version tag and the date slot, and honestly? she ate. π
no notes. go forth and tree your dependencies, bestie, you got this ππ
π¦ where this page comes from
- ubuntu jammy: cargo-1.78 1.78.0+dfsg1ubuntu1~bpo0-0ubuntu0.22.04.1 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.78 1.78.0+dfsg1ubuntu1-0ubuntu0.24.04.2 Β· MIT OR Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms