fork/cargo

git clone https://git.julia.blue/fork/cargo

Weihang Lofeat(tree): Support long forms for --format variables (#16204)cd9002621

master
17.7 KiB419 linesraw
1CARGO-TREE(1)
2
3NAME
4       cargo-tree — Display a tree visualization of a dependency graph
5
6SYNOPSIS
7       cargo tree [options]
8
9DESCRIPTION
10       This command will display a tree of dependencies to the terminal. An
11       example of a simple project that depends on the “rand” package:
12
13           myproject v0.1.0 (/myproject)
14           └── rand v0.7.3
15               ├── getrandom v0.1.14
16               │   ├── cfg-if v0.1.10
17               │   └── libc v0.2.68
18               ├── libc v0.2.68 (*)
19               ├── rand_chacha v0.2.2
20               │   ├── ppv-lite86 v0.2.6
21               │   └── rand_core v0.5.1
22               │       └── getrandom v0.1.14 (*)
23               └── rand_core v0.5.1 (*)
24           [build-dependencies]
25           └── cc v1.0.50
26
27       Packages marked with (*) have been “de-duplicated”. The dependencies
28       for the package have already been shown elsewhere in the graph, and so
29       are not repeated. Use the --no-dedupe option to repeat the duplicates.
30
31       The -e flag can be used to select the dependency kinds to display. The
32       “features” kind changes the output to display the features enabled
33       by each dependency. For example, cargo tree -e features:
34
35           myproject v0.1.0 (/myproject)
36           └── log feature "serde"
37               └── log v0.4.8
38                   ├── serde v1.0.106
39                   └── cfg-if feature "default"
40                       └── cfg-if v0.1.10
41
42       In this tree, myproject depends on log with the serde feature. log in
43       turn depends on cfg-if with “default” features. When using -e
44       features it can be helpful to use -i flag to show how the features flow
45       into a package. See the examples below for more detail.
46
47   Feature Unification
48       This command shows a graph much closer to a feature-unified graph Cargo
49       will build, rather than what you list in Cargo.toml. For instance, if
50       you specify the same dependency in both [dependencies] and
51       [dev-dependencies] but with different features on. This command may
52       merge all features and show a (*) on one of the dependency to indicate
53       the duplicate.
54
55       As a result, for a mostly equivalent overview of what cargo build does,
56       cargo tree -e normal,build is pretty close; for a mostly equivalent
57       overview of what cargo test does, cargo tree is pretty close. However,
58       it doesn’t guarantee the exact equivalence to what Cargo is going to
59       build, since a compilation is complex and depends on lots of different
60       factors.
61
62       To learn more about feature unification, check out this dedicated
63       section
64       <https://doc.rust-lang.org/cargo/reference/features.html#feature-unification>.
65
66OPTIONS
67   Tree Options
68       -i spec, --invert spec
69           Show the reverse dependencies for the given package. This flag will
70           invert the tree and display the packages that depend on the given
71           package.
72
73           Note that in a workspace, by default it will only display the
74           package’s reverse dependencies inside the tree of the workspace
75           member in the current directory. The --workspace flag can be used to
76           extend it so that it will show the package’s reverse dependencies
77           across the entire workspace. The -p flag can be used to display the
78           package’s reverse dependencies only with the subtree of the
79           package given to -p.
80
81       --prune spec
82           Prune the given package from the display of the dependency tree.
83
84       --depth depth
85           Maximum display depth of the dependency tree. A depth of 1 displays
86           the direct dependencies, for example.
87
88           If the given value is workspace, only shows the dependencies that
89           are member of the current workspace, instead.
90
91       --no-dedupe
92           Do not de-duplicate repeated dependencies. Usually, when a package
93           has already displayed its dependencies, further occurrences will not
94           re-display its dependencies, and will include a (*) to indicate it
95           has already been shown. This flag will cause those duplicates to be
96           repeated.
97
98       -d, --duplicates
99           Show only dependencies which come in multiple versions (implies
100           --invert). When used with the -p flag, only shows duplicates within
101           the subtree of the given package.
102
103           It can be beneficial for build times and executable sizes to avoid
104           building that same package multiple times. This flag can help
105           identify the offending packages. You can then investigate if the
106           package that depends on the duplicate with the older version can be
107           updated to the newer version so that only one instance is built.
108
109       -e kinds, --edges kinds
110           The dependency kinds to display. Takes a comma separated list of
111           values:
112
113           o  all — Show all edge kinds.
114
115           o  normal — Show normal dependencies.
116
117           o  build — Show build dependencies.
118
119           o  dev — Show development dependencies.
120
121           o  features — Show features enabled by each dependency. If this is
122              the only kind given, then it will automatically include the other
123              dependency kinds.
124
125           o  no-normal — Do not include normal dependencies.
126
127           o  no-build — Do not include build dependencies.
128
129           o  no-dev — Do not include development dependencies.
130
131           o  no-proc-macro — Do not include procedural macro dependencies.
132
133           The normal, build, dev, and all dependency kinds cannot be mixed
134           with no-normal, no-build, or no-dev dependency kinds.
135
136           The default is normal,build,dev.
137
138       --target triple
139           Filter dependencies matching the given target triple
140           <https://doc.rust-lang.org/cargo/appendix/glossary.html#target>. The
141           default is the host platform. Use the value all to include all
142           targets.
143
144   Tree Formatting Options
145       --charset charset
146           Chooses the character set to use for the tree. Valid values are
147           “utf8” or “ascii”. When unspecified, cargo will auto-select
148           a value.
149
150       -f format, --format format
151           Set the format string for each package. The default is “{p}”.
152
153           This is an arbitrary string which will be used to display each
154           package. The following strings will be replaced with the
155           corresponding value:
156
157           o  {p}, {package} — The package name.
158
159           o  {l}, {license} — The package license.
160
161           o  {r}, {repository} — The package repository URL.
162
163           o  {f}, {features} — Comma-separated list of package features that
164              are enabled.
165
166           o  {lib} — The name, as used in a use statement, of the
167              package’s library.
168
169       --prefix prefix
170           Sets how each line is displayed. The prefix value can be one of:
171
172           o  indent (default) — Shows each line indented as a tree.
173
174           o  depth — Show as a list, with the numeric depth printed before
175              each entry.
176
177           o  none — Show as a flat list.
178
179   Package Selection
180       By default, when no package selection options are given, the packages
181       selected depend on the selected manifest file (based on the current
182       working directory if --manifest-path is not given). If the manifest is
183       the root of a workspace then the workspaces default members are
184       selected, otherwise only the package defined by the manifest will be
185       selected.
186
187       The default members of a workspace can be set explicitly with the
188       workspace.default-members key in the root manifest. If this is not set,
189       a virtual workspace will include all workspace members (equivalent to
190       passing --workspace), and a non-virtual workspace will include only the
191       root crate itself.
192
193       -p spec…, --package spec…
194           Display only the specified packages. See cargo-pkgid(1) for the SPEC
195           format. This flag may be specified multiple times and supports
196           common Unix glob patterns like *, ? and []. However, to avoid your
197           shell accidentally expanding glob patterns before Cargo handles
198           them, you must use single quotes or double quotes around each
199           pattern.
200
201       --workspace
202           Display all members in the workspace.
203
204       --exclude SPEC…
205           Exclude the specified packages. Must be used in conjunction with the
206           --workspace flag. This flag may be specified multiple times and
207           supports common Unix glob patterns like *, ? and []. However, to
208           avoid your shell accidentally expanding glob patterns before Cargo
209           handles them, you must use single quotes or double quotes around
210           each pattern.
211
212   Manifest Options
213       --manifest-path path
214           Path to the Cargo.toml file. By default, Cargo searches for the
215           Cargo.toml file in the current directory or any parent directory.
216
217       --locked
218           Asserts that the exact same dependencies and versions are used as
219           when the existing Cargo.lock file was originally generated. Cargo
220           will exit with an error when either of the following scenarios
221           arises:
222
223           o  The lock file is missing.
224
225           o  Cargo attempted to change the lock file due to a different
226              dependency resolution.
227
228           It may be used in environments where deterministic builds are
229           desired, such as in CI pipelines.
230
231       --offline
232           Prevents Cargo from accessing the network for any reason. Without
233           this flag, Cargo will stop with an error if it needs to access the
234           network and the network is not available. With this flag, Cargo will
235           attempt to proceed without the network if possible.
236
237           Beware that this may result in different dependency resolution than
238           online mode. Cargo will restrict itself to crates that are
239           downloaded locally, even if there might be a newer version as
240           indicated in the local copy of the index. See the cargo-fetch(1)
241           command to download dependencies before going offline.
242
243           May also be specified with the net.offline config value
244           <https://doc.rust-lang.org/cargo/reference/config.html>.
245
246       --frozen
247           Equivalent to specifying both --locked and --offline.
248
249       --lockfile-path PATH
250           Changes the path of the lockfile from the default
251           (<workspace_root>/Cargo.lock) to PATH. PATH must end with Cargo.lock
252           (e.g. --lockfile-path /tmp/temporary-lockfile/Cargo.lock). Note that
253           providing --lockfile-path will ignore existing lockfile at the
254           default path, and instead will either use the lockfile from PATH, or
255           write a new lockfile into the provided PATH if it doesn’t exist.
256           This flag can be used to run most commands in read-only directories,
257           writing lockfile into the provided PATH.
258
259           This option is only available on the nightly channel
260           <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
261           requires the -Z unstable-options flag to enable (see #14421
262           <https://github.com/rust-lang/cargo/issues/14421>).
263
264   Feature Selection
265       The feature flags allow you to control which features are enabled. When
266       no feature options are given, the default feature is activated for every
267       selected package.
268
269       See the features documentation
270       <https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options>
271       for more details.
272
273       -F features, --features features
274           Space or comma separated list of features to activate. Features of
275           workspace members may be enabled with package-name/feature-name
276           syntax. This flag may be specified multiple times, which enables all
277           specified features.
278
279       --all-features
280           Activate all available features of all selected packages.
281
282       --no-default-features
283           Do not activate the default feature of the selected packages.
284
285   Display Options
286       -v, --verbose
287           Use verbose output. May be specified twice for “very verbose”
288           output which includes extra output such as dependency warnings and
289           build script output. May also be specified with the term.verbose
290           config value
291           <https://doc.rust-lang.org/cargo/reference/config.html>.
292
293       -q, --quiet
294           Do not print cargo log messages. May also be specified with the
295           term.quiet config value
296           <https://doc.rust-lang.org/cargo/reference/config.html>.
297
298       --color when
299           Control when colored output is used. Valid values:
300
301           o  auto (default): Automatically detect if color support is
302              available on the terminal.
303
304           o  always: Always display colors.
305
306           o  never: Never display colors.
307
308           May also be specified with the term.color config value
309           <https://doc.rust-lang.org/cargo/reference/config.html>.
310
311   Common Options
312       +toolchain
313           If Cargo has been installed with rustup, and the first argument to
314           cargo begins with +, it will be interpreted as a rustup toolchain
315           name (such as +stable or +nightly). See the rustup documentation
316           <https://rust-lang.github.io/rustup/overrides.html> for more
317           information about how toolchain overrides work.
318
319       --config KEY=VALUE or PATH
320           Overrides a Cargo configuration value. The argument should be in
321           TOML syntax of KEY=VALUE, or provided as a path to an extra
322           configuration file. This flag may be specified multiple times. See
323           the command-line overrides section
324           <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides>
325           for more information.
326
327       -C PATH
328           Changes the current working directory before executing any specified
329           operations. This affects things like where cargo looks by default
330           for the project manifest (Cargo.toml), as well as the directories
331           searched for discovering .cargo/config.toml, for example. This
332           option must appear before the command name, for example cargo -C
333           path/to/my-project build.
334
335           This option is only available on the nightly channel
336           <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
337           requires the -Z unstable-options flag to enable (see #10098
338           <https://github.com/rust-lang/cargo/issues/10098>).
339
340       -h, --help
341           Prints help information.
342
343       -Z flag
344           Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
345           details.
346
347ENVIRONMENT
348       See the reference
349       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
350       for details on environment variables that Cargo reads.
351
352EXIT STATUS
353       o  0: Cargo succeeded.
354
355       o  101: Cargo failed to complete.
356
357EXAMPLES
358       1. Display the tree for the package in the current directory:
359
360              cargo tree
361
362       2. Display all the packages that depend on the syn package:
363
364              cargo tree -i syn
365
366       3. Show the features enabled on each package:
367
368              cargo tree --format "{p} {f}"
369
370       4. Show all packages that are built multiple times. This can happen if
371          multiple semver-incompatible versions appear in the tree (like 1.0.0
372          and 2.0.0).
373
374              cargo tree -d
375
376       5. Explain why features are enabled for the syn package:
377
378              cargo tree -e features -i syn
379
380          The -e features flag is used to show features. The -i flag is used to
381          invert the graph so that it displays the packages that depend on syn.
382          An example of what this would display:
383
384              syn v1.0.17
385              ├── syn feature "clone-impls"
386              │   └── syn feature "default"
387              │       └── rustversion v1.0.2
388              │           └── rustversion feature "default"
389              │               └── myproject v0.1.0 (/myproject)
390              │                   └── myproject feature "default" (command-line)
391              ├── syn feature "default" (*)
392              ├── syn feature "derive"
393              │   └── syn feature "default" (*)
394              ├── syn feature "full"
395              │   └── rustversion v1.0.2 (*)
396              ├── syn feature "parsing"
397              │   └── syn feature "default" (*)
398              ├── syn feature "printing"
399              │   └── syn feature "default" (*)
400              ├── syn feature "proc-macro"
401              │   └── syn feature "default" (*)
402              └── syn feature "quote"
403                  ├── syn feature "printing" (*)
404                  └── syn feature "proc-macro" (*)
405
406          To read this graph, you can follow the chain for each feature from
407          the root to see why it is included. For example, the “full”
408          feature is added by the rustversion crate which is included from
409          myproject (with the default features), and myproject is the package
410          selected on the command-line. All of the other syn features are added
411          by the “default” feature (“quote” is added by “printing”
412          and “proc-macro”, both of which are default features).
413
414          If you’re having difficulty cross-referencing the de-duplicated (*)
415          entries, try with the --no-dedupe flag to get the full output.
416
417SEE ALSO
418       cargo(1), cargo-metadata(1)
419