1CARGO-TREE(1) General Commands Manual CARGO-TREE(1)
2
3
4
6 cargo-tree — Display a tree visualization of a dependency graph
7
9 cargo tree [options]
10
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 learn more about feature unification, check out this dedicated
65 section
66 <https://doc.rust-lang.org/cargo/reference/features.html#feature-unification>.
67
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
112 • all — Show all edge kinds.
113
114 • normal — Show normal dependencies.
115
116 • build — Show build dependencies.
117
118 • dev — Show development dependencies.
119
120 • features — 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
124 • no-normal — Do not include normal dependencies.
125
126 • no-build — Do not include build dependencies.
127
128 • no-dev — Do not include development dependencies.
129
130 • no-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
139 <https://doc.rust-lang.org/cargo/appendix/glossary.html#target>.
140 The default is the host platform. Use the value all to include all
141 targets.
142
143 Tree Formatting Options
144 --charset charset
145 Chooses the character set to use for the tree. Valid values are
146 “utf8” or “ascii”. Default is “utf8”.
147
148 -f format, --format format
149 Set the format string for each package. The default is “{p}”.
150
151 This is an arbitrary string which will be used to display each
152 package. The following strings will be replaced with the
153 corresponding value:
154
155 • {p} — The package name.
156
157 • {l} — The package license.
158
159 • {r} — The package repository URL.
160
161 • {f} — Comma-separated list of package features that are enabled.
162
163 • {lib} — The name, as used in a use statement, of the package’s
164 library.
165
166 --prefix prefix
167 Sets how each line is displayed. The prefix value can be one of:
168
169 • indent (default) — Shows each line indented as a tree.
170
171 • depth — Show as a list, with the numeric depth printed before
172 each entry.
173
174 • none — Show as a flat list.
175
176 Package Selection
177 By default, when no package selection options are given, the packages
178 selected depend on the selected manifest file (based on the current
179 working directory if --manifest-path is not given). If the manifest is
180 the root of a workspace then the workspaces default members are
181 selected, otherwise only the package defined by the manifest will be
182 selected.
183
184 The default members of a workspace can be set explicitly with the
185 workspace.default-members key in the root manifest. If this is not set,
186 a virtual workspace will include all workspace members (equivalent to
187 passing --workspace), and a non-virtual workspace will include only the
188 root crate itself.
189
190 -p spec…, --package spec…
191 Display only the specified packages. See cargo-pkgid(1) for the
192 SPEC format. This flag may be specified multiple times and supports
193 common Unix glob patterns like *, ? and []. However, to avoid your
194 shell accidentally expanding glob patterns before Cargo handles
195 them, you must use single quotes or double quotes around each
196 pattern.
197
198 --workspace
199 Display all members in the workspace.
200
201 --exclude SPEC…
202 Exclude the specified packages. Must be used in conjunction with
203 the --workspace flag. This flag may be specified multiple times and
204 supports common Unix glob patterns like *, ? and []. However, to
205 avoid your shell accidentally expanding glob patterns before Cargo
206 handles them, you must use single quotes or double quotes around
207 each pattern.
208
209 Manifest Options
210 --manifest-path path
211 Path to the Cargo.toml file. By default, Cargo searches for the
212 Cargo.toml file in the current directory or any parent directory.
213
214 --frozen, --locked
215 Either of these flags requires that the Cargo.lock file is
216 up-to-date. If the lock file is missing, or it needs to be updated,
217 Cargo will exit with an error. The --frozen flag also prevents
218 Cargo from attempting to access the network to determine if it is
219 out-of-date.
220
221 These may be used in environments where you want to assert that the
222 Cargo.lock file is up-to-date (such as a CI build) or want to avoid
223 network access.
224
225 --offline
226 Prevents Cargo from accessing the network for any reason. Without
227 this flag, Cargo will stop with an error if it needs to access the
228 network and the network is not available. With this flag, Cargo
229 will attempt to proceed without the network if possible.
230
231 Beware that this may result in different dependency resolution than
232 online mode. Cargo will restrict itself to crates that are
233 downloaded locally, even if there might be a newer version as
234 indicated in the local copy of the index. See the cargo-fetch(1)
235 command to download dependencies before going offline.
236
237 May also be specified with the net.offline config value
238 <https://doc.rust-lang.org/cargo/reference/config.html>.
239
240 Feature Selection
241 The feature flags allow you to control which features are enabled. When
242 no feature options are given, the default feature is activated for
243 every selected package.
244
245 See the features documentation
246 <https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options>
247 for more details.
248
249 -F features, --features features
250 Space or comma separated list of features to activate. Features of
251 workspace members may be enabled with package-name/feature-name
252 syntax. This flag may be specified multiple times, which enables
253 all specified features.
254
255 --all-features
256 Activate all available features of all selected packages.
257
258 --no-default-features
259 Do not activate the default feature of the selected packages.
260
261 Display Options
262 -v, --verbose
263 Use verbose output. May be specified twice for “very verbose”
264 output which includes extra output such as dependency warnings and
265 build script output. May also be specified with the term.verbose
266 config value
267 <https://doc.rust-lang.org/cargo/reference/config.html>.
268
269 -q, --quiet
270 Do not print cargo log messages. May also be specified with the
271 term.quiet config value
272 <https://doc.rust-lang.org/cargo/reference/config.html>.
273
274 --color when
275 Control when colored output is used. Valid values:
276
277 • auto (default): Automatically detect if color support is
278 available on the terminal.
279
280 • always: Always display colors.
281
282 • never: Never display colors.
283
284 May also be specified with the term.color config value
285 <https://doc.rust-lang.org/cargo/reference/config.html>.
286
287 Common Options
288 +toolchain
289 If Cargo has been installed with rustup, and the first argument to
290 cargo begins with +, it will be interpreted as a rustup toolchain
291 name (such as +stable or +nightly). See the rustup documentation
292 <https://rust-lang.github.io/rustup/overrides.html> for more
293 information about how toolchain overrides work.
294
295 --config KEY=VALUE or PATH
296 Overrides a Cargo configuration value. The argument should be in
297 TOML syntax of KEY=VALUE, or provided as a path to an extra
298 configuration file. This flag may be specified multiple times. See
299 the command-line overrides section
300 <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides>
301 for more information.
302
303 -C PATH
304 Changes the current working directory before executing any
305 specified operations. This affects things like where cargo looks by
306 default for the project manifest (Cargo.toml), as well as the
307 directories searched for discovering .cargo/config.toml, for
308 example. This option must appear before the command name, for
309 example cargo -C path/to/my-project build.
310
311 This option is only available on the nightly channel
312 <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
313 requires the -Z unstable-options flag to enable (see #10098
314 <https://github.com/rust-lang/cargo/issues/10098>).
315
316 -h, --help
317 Prints help information.
318
319 -Z flag
320 Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
321 details.
322
324 See the reference
325 <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
326 for details on environment variables that Cargo reads.
327
329 • 0: Cargo succeeded.
330
331 • 101: Cargo failed to complete.
332
334 1. Display the tree for the package in the current directory:
335
336 cargo tree
337
338 2. Display all the packages that depend on the syn package:
339
340 cargo tree -i syn
341
342 3. Show the features enabled on each package:
343
344 cargo tree --format "{p} {f}"
345
346 4. Show all packages that are built multiple times. This can happen if
347 multiple semver-incompatible versions appear in the tree (like
348 1.0.0 and 2.0.0).
349
350 cargo tree -d
351
352 5. Explain why features are enabled for the syn package:
353
354 cargo tree -e features -i syn
355
356 The -e features flag is used to show features. The -i flag is used
357 to invert the graph so that it displays the packages that depend on
358 syn. An example of what this would display:
359
360 syn v1.0.17
361 |-- syn feature "clone-impls"
362 | `-- syn feature "default"
363 | `-- rustversion v1.0.2
364 | `-- rustversion feature "default"
365 | `-- myproject v0.1.0 (/myproject)
366 | `-- myproject feature "default" (command-line)
367 |-- syn feature "default" (*)
368 |-- syn feature "derive"
369 | `-- syn feature "default" (*)
370 |-- syn feature "full"
371 | `-- rustversion v1.0.2 (*)
372 |-- syn feature "parsing"
373 | `-- syn feature "default" (*)
374 |-- syn feature "printing"
375 | `-- syn feature "default" (*)
376 |-- syn feature "proc-macro"
377 | `-- syn feature "default" (*)
378 `-- syn feature "quote"
379 |-- syn feature "printing" (*)
380 `-- syn feature "proc-macro" (*)
381
382 To read this graph, you can follow the chain for each feature from
383 the root to see why it is included. For example, the “full” feature
384 is added by the rustversion crate which is included from myproject
385 (with the default features), and myproject is the package selected
386 on the command-line. All of the other syn features are added by the
387 “default” feature (“quote” is added by “printing” and “proc-macro”,
388 both of which are default features).
389
390 If you’re having difficulty cross-referencing the de-duplicated (*)
391 entries, try with the --no-dedupe flag to get the full output.
392
394 cargo(1), cargo-metadata(1)
395
396
397
398 CARGO-TREE(1)