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