1CARGO-TREE(1)               General Commands Manual              CARGO-TREE(1)
2
3
4

NAME

6       cargo-tree - Display a tree visualization of a dependency graph
7

SYNOPSIS

9       cargo tree [options]
10

DESCRIPTION

12       This command will display a tree of dependencies to the terminal. An
13       example of a simple project that depends on the "rand" package:
14
15           myproject v0.1.0 (/myproject)
16           `-- rand v0.7.3
17               |-- getrandom v0.1.14
18               |   |-- cfg-if v0.1.10
19               |   `-- libc v0.2.68
20               |-- libc v0.2.68 (*)
21               |-- rand_chacha v0.2.2
22               |   |-- ppv-lite86 v0.2.6
23               |   `-- rand_core v0.5.1
24               |       `-- getrandom v0.1.14 (*)
25               `-- rand_core v0.5.1 (*)
26           [build-dependencies]
27           `-- cc v1.0.50
28
29       Packages marked with (*) have been "de-duplicated". The dependencies
30       for the package have already been shown elsewhere in the graph, and so
31       are not repeated. Use the --no-dedupe option to repeat the duplicates.
32
33       The -e flag can be used to select the dependency kinds to display. The
34       "features" kind changes the output to display the features enabled by
35       each dependency. For example, cargo tree -e features:
36
37           myproject v0.1.0 (/myproject)
38           `-- log feature "serde"
39               `-- log v0.4.8
40                   |-- serde v1.0.106
41                   `-- cfg-if feature "default"
42                       `-- cfg-if v0.1.10
43
44       In this tree, myproject depends on log with the serde feature. log in
45       turn depends on cfg-if with "default" features. When using -e features
46       it can be helpful to use -i flag to show how the features flow into a
47       package. See the examples below for more detail.
48
49   Feature Unification
50       This command shows a graph much closer to a feature-unified graph Cargo
51       will build, rather than what you list in Cargo.toml. For instance, if
52       you specify the same dependency in both [dependencies] and
53       [dev-dependencies] but with different features on. This command may
54       merge all features and show a (*) on one of the dependency to indicate
55       the duplicate.
56
57       As a result, for a mostly equivalent overview of what cargo build does,
58       cargo tree -e normal,build is pretty close; for a mostly equivalent
59       overview of what cargo test does, cargo tree is pretty close. However,
60       it doesn't guarantee the exact equivalence to what Cargo is going to
61       build, since a compilation is complex and depends on lots of different
62       factors.
63
64       To learm more about feature unification, check out this dedicated
65       section
66       <https://doc.rust-lang.org/cargo/reference/features.html#feature-unification>.
67

OPTIONS

69   Tree Options
70       -i spec, --invert spec
71           Show the reverse dependencies for the given package. This flag will
72           invert the tree and display the packages that depend on the given
73           package.
74
75           Note that in a workspace, by default it will only display the
76           package's reverse dependencies inside the tree of the workspace
77           member in the current directory. The --workspace flag can be used
78           to extend it so that it will show the package's reverse
79           dependencies across the entire workspace. The -p flag can be used
80           to display the package's reverse dependencies only with the subtree
81           of the package given to -p.
82
83       --prune spec
84           Prune the given package from the display of the dependency tree.
85
86       --depth depth
87           Maximum display depth of the dependency tree. A depth of 1 displays
88           the direct dependencies, for example.
89
90       --no-dedupe
91           Do not de-duplicate repeated dependencies. Usually, when a package
92           has already displayed its dependencies, further occurrences will
93           not re-display its dependencies, and will include a (*) to indicate
94           it has already been shown. This flag will cause those duplicates to
95           be repeated.
96
97       -d, --duplicates
98           Show only dependencies which come in multiple versions (implies
99           --invert). When used with the -p flag, only shows duplicates within
100           the subtree of the given package.
101
102           It can be beneficial for build times and executable sizes to avoid
103           building that same package multiple times. This flag can help
104           identify the offending packages. You can then investigate if the
105           package that depends on the duplicate with the older version can be
106           updated to the newer version so that only one instance is built.
107
108       -e kinds, --edges kinds
109           The dependency kinds to display. Takes a comma separated list of
110           values:
111
112all — Show all edge kinds.
113
114normal — Show normal dependencies.
115
116build — Show build dependencies.
117
118dev — Show development dependencies.
119
120features — Show features enabled by each dependency. If this is
121               the only kind given, then it will automatically include the
122               other dependency kinds.
123
124no-normal — Do not include normal dependencies.
125
126no-build — Do not include build dependencies.
127
128no-dev — Do not include development dependencies.
129
130no-proc-macro — Do not include procedural macro dependencies.
131
132           The normal, build, dev, and all dependency kinds cannot be mixed
133           with no-normal, no-build, or no-dev dependency kinds.
134
135           The default is normal,build,dev.
136
137       --target triple
138           Filter dependencies matching the given target-triple. The default
139           is the host platform. Use the value all to include all targets.
140
141   Tree Formatting Options
142       --charset charset
143           Chooses the character set to use for the tree. Valid values are
144           "utf8" or "ascii". Default is "utf8".
145
146       -f format, --format format
147           Set the format string for each package. The default is "{p}".
148
149           This is an arbitrary string which will be used to display each
150           package. The following strings will be replaced with the
151           corresponding value:
152
153{p} — The package name.
154
155{l} — The package license.
156
157{r} — The package repository URL.
158
159{f} — Comma-separated list of package features that are enabled.
160
161{lib} — The name, as used in a use statement, of the package's
162               library.
163
164       --prefix prefix
165           Sets how each line is displayed. The prefix value can be one of:
166
167indent (default) — Shows each line indented as a tree.
168
169depth — Show as a list, with the numeric depth printed before
170               each entry.
171
172none — Show as a flat list.
173
174   Package Selection
175       By default, when no package selection options are given, the packages
176       selected depend on the selected manifest file (based on the current
177       working directory if --manifest-path is not given). If the manifest is
178       the root of a workspace then the workspaces default members are
179       selected, otherwise only the package defined by the manifest will be
180       selected.
181
182       The default members of a workspace can be set explicitly with the
183       workspace.default-members key in the root manifest. If this is not set,
184       a virtual workspace will include all workspace members (equivalent to
185       passing --workspace), and a non-virtual workspace will include only the
186       root crate itself.
187
188       -p spec..., --package spec...
189           Display only the specified packages. See cargo-pkgid(1) for the
190           SPEC format. This flag may be specified multiple times and supports
191           common Unix glob patterns like *, ? and []. However, to avoid your
192           shell accidentally expanding glob patterns before Cargo handles
193           them, you must use single quotes or double quotes around each
194           pattern.
195
196       --workspace
197           Display all members in the workspace.
198
199       --exclude SPEC...
200           Exclude the specified packages. Must be used in conjunction with
201           the --workspace flag. This flag may be specified multiple times and
202           supports common Unix glob patterns like *, ? and []. However, to
203           avoid your shell accidentally expanding glob patterns before Cargo
204           handles them, you must use single quotes or double quotes around
205           each pattern.
206
207   Manifest Options
208       --manifest-path path
209           Path to the Cargo.toml file. By default, Cargo searches for the
210           Cargo.toml file in the current directory or any parent directory.
211
212       --frozen, --locked
213           Either of these flags requires that the Cargo.lock file is
214           up-to-date. If the lock file is missing, or it needs to be updated,
215           Cargo will exit with an error. The --frozen flag also prevents
216           Cargo from attempting to access the network to determine if it is
217           out-of-date.
218
219           These may be used in environments where you want to assert that the
220           Cargo.lock file is up-to-date (such as a CI build) or want to avoid
221           network access.
222
223       --offline
224           Prevents Cargo from accessing the network for any reason. Without
225           this flag, Cargo will stop with an error if it needs to access the
226           network and the network is not available. With this flag, Cargo
227           will attempt to proceed without the network if possible.
228
229           Beware that this may result in different dependency resolution than
230           online mode. Cargo will restrict itself to crates that are
231           downloaded locally, even if there might be a newer version as
232           indicated in the local copy of the index. See the cargo-fetch(1)
233           command to download dependencies before going offline.
234
235           May also be specified with the net.offline config value
236           <https://doc.rust-lang.org/cargo/reference/config.html>.
237
238   Feature Selection
239       The feature flags allow you to control which features are enabled. When
240       no feature options are given, the default feature is activated for
241       every selected package.
242
243       See the features documentation
244       <https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options>
245       for more details.
246
247       -F features, --features features
248           Space or comma separated list of features to activate. Features of
249           workspace members may be enabled with package-name/feature-name
250           syntax. This flag may be specified multiple times, which enables
251           all specified features.
252
253       --all-features
254           Activate all available features of all selected packages.
255
256       --no-default-features
257           Do not activate the default feature of the selected packages.
258
259   Display Options
260       -v, --verbose
261           Use verbose output. May be specified twice for "very verbose"
262           output which includes extra output such as dependency warnings and
263           build script output. May also be specified with the term.verbose
264           config value
265           <https://doc.rust-lang.org/cargo/reference/config.html>.
266
267       -q, --quiet
268           Do not print cargo log messages. May also be specified with the
269           term.quiet config value
270           <https://doc.rust-lang.org/cargo/reference/config.html>.
271
272       --color when
273           Control when colored output is used. Valid values:
274
275auto (default): Automatically detect if color support is
276               available on the terminal.
277
278always: Always display colors.
279
280never: Never display colors.
281
282           May also be specified with the term.color config value
283           <https://doc.rust-lang.org/cargo/reference/config.html>.
284
285   Common Options
286       +toolchain
287           If Cargo has been installed with rustup, and the first argument to
288           cargo begins with +, it will be interpreted as a rustup toolchain
289           name (such as +stable or +nightly). See the rustup documentation
290           <https://rust-lang.github.io/rustup/overrides.html> for more
291           information about how toolchain overrides work.
292
293       --config KEY=VALUE or PATH
294           Overrides a Cargo configuration value. The argument should be in
295           TOML syntax of KEY=VALUE, or provided as a path to an extra
296           configuration file. This flag may be specified multiple times. See
297           the command-line overrides section
298           <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides>
299           for more information.
300
301       -h, --help
302           Prints help information.
303
304       -Z flag
305           Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
306           details.
307

ENVIRONMENT

309       See the reference
310       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
311       for details on environment variables that Cargo reads.
312

EXIT STATUS

3140: Cargo succeeded.
315
316101: Cargo failed to complete.
317

EXAMPLES

319        1. Display the tree for the package in the current directory:
320
321               cargo tree
322
323        2. Display all the packages that depend on the syn package:
324
325               cargo tree -i syn
326
327        3. Show the features enabled on each package:
328
329               cargo tree --format "{p} {f}"
330
331        4. Show all packages that are built multiple times. This can happen if
332           multiple semver-incompatible versions appear in the tree (like
333           1.0.0 and 2.0.0).
334
335               cargo tree -d
336
337        5. Explain why features are enabled for the syn package:
338
339               cargo tree -e features -i syn
340
341           The -e features flag is used to show features. The -i flag is used
342           to invert the graph so that it displays the packages that depend on
343           syn. An example of what this would display:
344
345               syn v1.0.17
346               |-- syn feature "clone-impls"
347               |   `-- syn feature "default"
348               |       `-- rustversion v1.0.2
349               |           `-- rustversion feature "default"
350               |               `-- myproject v0.1.0 (/myproject)
351               |                   `-- myproject feature "default" (command-line)
352               |-- syn feature "default" (*)
353               |-- syn feature "derive"
354               |   `-- syn feature "default" (*)
355               |-- syn feature "full"
356               |   `-- rustversion v1.0.2 (*)
357               |-- syn feature "parsing"
358               |   `-- syn feature "default" (*)
359               |-- syn feature "printing"
360               |   `-- syn feature "default" (*)
361               |-- syn feature "proc-macro"
362               |   `-- syn feature "default" (*)
363               `-- syn feature "quote"
364                   |-- syn feature "printing" (*)
365                   `-- syn feature "proc-macro" (*)
366
367           To read this graph, you can follow the chain for each feature from
368           the root to see why it is included. For example, the "full" feature
369           is added by the rustversion crate which is included from myproject
370           (with the default features), and myproject is the package selected
371           on the command-line. All of the other syn features are added by the
372           "default" feature ("quote" is added by "printing" and "proc-macro",
373           both of which are default features).
374
375           If you're having difficulty cross-referencing the de-duplicated (*)
376           entries, try with the --no-dedupe flag to get the full output.
377

SEE ALSO

379       cargo(1), cargo-metadata(1)
380
381
382
383                                                                 CARGO-TREE(1)
Impressum