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

NAME

6       cargo-metadata — Machine-readable metadata about the current package
7

SYNOPSIS

9       cargo metadata [options]
10

DESCRIPTION

12       Output JSON to stdout containing information about the workspace
13       members and resolved dependencies of the current package.
14
15       The format of the output is subject to change in futures versions of
16       Cargo. It is recommended to include the --format-version flag to
17       future-proof your code to ensure the output is in the format you are
18       expecting. For more on the expectations, see “Compatibility”.
19
20       See the cargo_metadata crate <https://crates.io/crates/cargo_metadata>
21       for a Rust API for reading the metadata.
22

OUTPUT FORMAT

24   Compatibility
25       Within the same output format version, the compatibility is maintained,
26       except some scenarios. The following is a non-exhaustive list of
27       changes that are not considersed as incompatible:
28
29Adding new fields — New fields will be added when needed. Reserving
30           this helps Cargo evolve without bumping the format version too
31           often.
32
33Adding new values for enum-like fields — Same as adding new fields.
34           It keeps metadata evolving without stagnation.
35
36Changing opaque representations — The inner representations of some
37           fields are implementation details. For example, fields related to
38           “Package ID” or “Source ID” are treated as opaque identifiers to
39           differentiate packages or sources. Consumers shouldn’t rely on
40           those representations unless specified.
41
42   JSON format
43       The JSON output has the following format:
44
45           {
46               /* Array of all packages in the workspace.
47                  It also includes all feature-enabled dependencies unless --no-deps is used.
48               */
49               "packages": [
50                   {
51                       /* The name of the package. */
52                       "name": "my-package",
53                       /* The version of the package. */
54                       "version": "0.1.0",
55                       /* The Package ID, an opaque and unique identifier for referring to the
56                          package. See "Compatibility" above for the stability guarantee.
57                       */
58                       "id": "my-package 0.1.0 (path+file:///path/to/my-package)",
59                       /* The license value from the manifest, or null. */
60                       "license": "MIT/Apache-2.0",
61                       /* The license-file value from the manifest, or null. */
62                       "license_file": "LICENSE",
63                       /* The description value from the manifest, or null. */
64                       "description": "Package description.",
65                       /* The source ID of the package, an "opaque" identifier representing
66                          where a package is retrieved from. See "Compatibility" above for
67                          the stability guarantee.
68
69                          This is null for path dependencies and workspace members.
70
71                          For other dependencies, it is a string with the format:
72                          - "registry+URL" for registry-based dependencies.
73                            Example: "registry+https://github.com/rust-lang/crates.io-index"
74                          - "git+URL" for git-based dependencies.
75                            Example: "git+https://github.com/rust-lang/cargo?rev=5e85ba14aaa20f8133863373404cb0af69eeef2c#5e85ba14aaa20f8133863373404cb0af69eeef2c"
76                          - "sparse+URL" for dependencies from a sparse registry
77                            Example: "sparse+https://my-sparse-registry.org"
78
79                          The value after the `+` is not explicitly defined, and may change
80                          between versions of Cargo and may not directly correlate to other
81                          things, such as registry definitions in a config file. New source
82                          kinds may be added in the future which will have different `+`
83                          prefixed identifiers.
84                       */
85                       "source": null,
86                       /* Array of dependencies declared in the package's manifest. */
87                       "dependencies": [
88                           {
89                               /* The name of the dependency. */
90                               "name": "bitflags",
91                               /* The source ID of the dependency. May be null, see
92                                  description for the package source.
93                               */
94                               "source": "registry+https://github.com/rust-lang/crates.io-index",
95                               /* The version requirement for the dependency.
96                                  Dependencies without a version requirement have a value of "*".
97                               */
98                               "req": "^1.0",
99                               /* The dependency kind.
100                                  "dev", "build", or null for a normal dependency.
101                               */
102                               "kind": null,
103                               /* If the dependency is renamed, this is the new name for
104                                  the dependency as a string. null if it is not renamed.
105                               */
106                               "rename": null,
107                               /* Boolean of whether or not this is an optional dependency. */
108                               "optional": false,
109                               /* Boolean of whether or not default features are enabled. */
110                               "uses_default_features": true,
111                               /* Array of features enabled. */
112                               "features": [],
113                               /* The target platform for the dependency.
114                                  null if not a target dependency.
115                               */
116                               "target": "cfg(windows)",
117                               /* The file system path for a local path dependency.
118                                  not present if not a path dependency.
119                               */
120                               "path": "/path/to/dep",
121                               /* A string of the URL of the registry this dependency is from.
122                                  If not specified or null, the dependency is from the default
123                                  registry (crates.io).
124                               */
125                               "registry": null
126                           }
127                       ],
128                       /* Array of Cargo targets. */
129                       "targets": [
130                           {
131                               /* Array of target kinds.
132                                  - lib targets list the `crate-type` values from the
133                                    manifest such as "lib", "rlib", "dylib",
134                                    "proc-macro", etc. (default ["lib"])
135                                  - binary is ["bin"]
136                                  - example is ["example"]
137                                  - integration test is ["test"]
138                                  - benchmark is ["bench"]
139                                  - build script is ["custom-build"]
140                               */
141                               "kind": [
142                                   "bin"
143                               ],
144                               /* Array of crate types.
145                                  - lib and example libraries list the `crate-type` values
146                                    from the manifest such as "lib", "rlib", "dylib",
147                                    "proc-macro", etc. (default ["lib"])
148                                  - all other target kinds are ["bin"]
149                               */
150                               "crate_types": [
151                                   "bin"
152                               ],
153                               /* The name of the target. */
154                               "name": "my-package",
155                               /* Absolute path to the root source file of the target. */
156                               "src_path": "/path/to/my-package/src/main.rs",
157                               /* The Rust edition of the target.
158                                  Defaults to the package edition.
159                               */
160                               "edition": "2018",
161                               /* Array of required features.
162                                  This property is not included if no required features are set.
163                               */
164                               "required-features": ["feat1"],
165                               /* Whether the target should be documented by `cargo doc`. */
166                               "doc": true,
167                               /* Whether or not this target has doc tests enabled, and
168                                  the target is compatible with doc testing.
169                               */
170                               "doctest": false,
171                               /* Whether or not this target should be built and run with `--test`
172                               */
173                               "test": true
174                           }
175                       ],
176                       /* Set of features defined for the package.
177                          Each feature maps to an array of features or dependencies it
178                          enables.
179                       */
180                       "features": {
181                           "default": [
182                               "feat1"
183                           ],
184                           "feat1": [],
185                           "feat2": []
186                       },
187                       /* Absolute path to this package's manifest. */
188                       "manifest_path": "/path/to/my-package/Cargo.toml",
189                       /* Package metadata.
190                          This is null if no metadata is specified.
191                       */
192                       "metadata": {
193                           "docs": {
194                               "rs": {
195                                   "all-features": true
196                               }
197                           }
198                       },
199                       /* List of registries to which this package may be published.
200                          Publishing is unrestricted if null, and forbidden if an empty array. */
201                       "publish": [
202                           "crates-io"
203                       ],
204                       /* Array of authors from the manifest.
205                          Empty array if no authors specified.
206                       */
207                       "authors": [
208                           "Jane Doe <user@example.com>"
209                       ],
210                       /* Array of categories from the manifest. */
211                       "categories": [
212                           "command-line-utilities"
213                       ],
214                       /* Optional string that is the default binary picked by cargo run. */
215                       "default_run": null,
216                       /* Optional string that is the minimum supported rust version */
217                       "rust_version": "1.56",
218                       /* Array of keywords from the manifest. */
219                       "keywords": [
220                           "cli"
221                       ],
222                       /* The readme value from the manifest or null if not specified. */
223                       "readme": "README.md",
224                       /* The repository value from the manifest or null if not specified. */
225                       "repository": "https://github.com/rust-lang/cargo",
226                       /* The homepage value from the manifest or null if not specified. */
227                       "homepage": "https://rust-lang.org",
228                       /* The documentation value from the manifest or null if not specified. */
229                       "documentation": "https://doc.rust-lang.org/stable/std",
230                       /* The default edition of the package.
231                          Note that individual targets may have different editions.
232                       */
233                       "edition": "2018",
234                       /* Optional string that is the name of a native library the package
235                          is linking to.
236                       */
237                       "links": null,
238                   }
239               ],
240               /* Array of members of the workspace.
241                  Each entry is the Package ID for the package.
242               */
243               "workspace_members": [
244                   "my-package 0.1.0 (path+file:///path/to/my-package)",
245               ],
246               /* Array of default members of the workspace.
247                  Each entry is the Package ID for the package.
248               */
249               "workspace_default_members": [
250                   "my-package 0.1.0 (path+file:///path/to/my-package)",
251               ],
252               // The resolved dependency graph for the entire workspace. The enabled
253               // features are based on the enabled features for the "current" package.
254               // Inactivated optional dependencies are not listed.
255               //
256               // This is null if --no-deps is specified.
257               //
258               // By default, this includes all dependencies for all target platforms.
259               // The `--filter-platform` flag may be used to narrow to a specific
260               // target triple.
261               "resolve": {
262                   /* Array of nodes within the dependency graph.
263                      Each node is a package.
264                   */
265                   "nodes": [
266                       {
267                           /* The Package ID of this node. */
268                           "id": "my-package 0.1.0 (path+file:///path/to/my-package)",
269                           /* The dependencies of this package, an array of Package IDs. */
270                           "dependencies": [
271                               "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)"
272                           ],
273                           /* The dependencies of this package. This is an alternative to
274                              "dependencies" which contains additional information. In
275                              particular, this handles renamed dependencies.
276                           */
277                           "deps": [
278                               {
279                                   /* The name of the dependency's library target.
280                                      If this is a renamed dependency, this is the new
281                                      name.
282                                   */
283                                   "name": "bitflags",
284                                   /* The Package ID of the dependency. */
285                                   "pkg": "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
286                                   /* Array of dependency kinds. Added in Cargo 1.40. */
287                                   "dep_kinds": [
288                                       {
289                                           /* The dependency kind.
290                                              "dev", "build", or null for a normal dependency.
291                                           */
292                                           "kind": null,
293                                           /* The target platform for the dependency.
294                                              null if not a target dependency.
295                                           */
296                                           "target": "cfg(windows)"
297                                       }
298                                   ]
299                               }
300                           ],
301                           /* Array of features enabled on this package. */
302                           "features": [
303                               "default"
304                           ]
305                       }
306                   ],
307                   /* The root package of the workspace.
308                      This is null if this is a virtual workspace. Otherwise it is
309                      the Package ID of the root package.
310                   */
311                   "root": "my-package 0.1.0 (path+file:///path/to/my-package)"
312               },
313               /* The absolute path to the build directory where Cargo places its output. */
314               "target_directory": "/path/to/my-package/target",
315               /* The version of the schema for this metadata structure.
316                  This will be changed if incompatible changes are ever made.
317               */
318               "version": 1,
319               /* The absolute path to the root of the workspace. */
320               "workspace_root": "/path/to/my-package"
321               /* Workspace metadata.
322                  This is null if no metadata is specified. */
323               "metadata": {
324                   "docs": {
325                       "rs": {
326                           "all-features": true
327                       }
328                   }
329               }
330           }
331

OPTIONS

333   Output Options
334       --no-deps
335           Output information only about the workspace members and don’t fetch
336           dependencies.
337
338       --format-version version
339           Specify the version of the output format to use. Currently 1 is the
340           only possible value.
341
342       --filter-platform triple
343           This filters the resolve output to only include dependencies for
344           the given target triple
345           <https://doc.rust-lang.org/cargo/appendix/glossary.html#target>.
346           Without this flag, the resolve includes all targets.
347
348           Note that the dependencies listed in the “packages” array still
349           includes all dependencies. Each package definition is intended to
350           be an unaltered reproduction of the information within Cargo.toml.
351
352   Feature Selection
353       The feature flags allow you to control which features are enabled. When
354       no feature options are given, the default feature is activated for
355       every selected package.
356
357       See the features documentation
358       <https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options>
359       for more details.
360
361       -F features, --features features
362           Space or comma separated list of features to activate. Features of
363           workspace members may be enabled with package-name/feature-name
364           syntax. This flag may be specified multiple times, which enables
365           all specified features.
366
367       --all-features
368           Activate all available features of all selected packages.
369
370       --no-default-features
371           Do not activate the default feature of the selected packages.
372
373   Display Options
374       -v, --verbose
375           Use verbose output. May be specified twice for “very verbose”
376           output which includes extra output such as dependency warnings and
377           build script output. May also be specified with the term.verbose
378           config value
379           <https://doc.rust-lang.org/cargo/reference/config.html>.
380
381       -q, --quiet
382           Do not print cargo log messages. May also be specified with the
383           term.quiet config value
384           <https://doc.rust-lang.org/cargo/reference/config.html>.
385
386       --color when
387           Control when colored output is used. Valid values:
388
389auto (default): Automatically detect if color support is
390               available on the terminal.
391
392always: Always display colors.
393
394never: Never display colors.
395
396           May also be specified with the term.color config value
397           <https://doc.rust-lang.org/cargo/reference/config.html>.
398
399   Manifest Options
400       --manifest-path path
401           Path to the Cargo.toml file. By default, Cargo searches for the
402           Cargo.toml file in the current directory or any parent directory.
403
404       --frozen, --locked
405           Either of these flags requires that the Cargo.lock file is
406           up-to-date. If the lock file is missing, or it needs to be updated,
407           Cargo will exit with an error. The --frozen flag also prevents
408           Cargo from attempting to access the network to determine if it is
409           out-of-date.
410
411           These may be used in environments where you want to assert that the
412           Cargo.lock file is up-to-date (such as a CI build) or want to avoid
413           network access.
414
415       --offline
416           Prevents Cargo from accessing the network for any reason. Without
417           this flag, Cargo will stop with an error if it needs to access the
418           network and the network is not available. With this flag, Cargo
419           will attempt to proceed without the network if possible.
420
421           Beware that this may result in different dependency resolution than
422           online mode. Cargo will restrict itself to crates that are
423           downloaded locally, even if there might be a newer version as
424           indicated in the local copy of the index. See the cargo-fetch(1)
425           command to download dependencies before going offline.
426
427           May also be specified with the net.offline config value
428           <https://doc.rust-lang.org/cargo/reference/config.html>.
429
430   Common Options
431       +toolchain
432           If Cargo has been installed with rustup, and the first argument to
433           cargo begins with +, it will be interpreted as a rustup toolchain
434           name (such as +stable or +nightly). See the rustup documentation
435           <https://rust-lang.github.io/rustup/overrides.html> for more
436           information about how toolchain overrides work.
437
438       --config KEY=VALUE or PATH
439           Overrides a Cargo configuration value. The argument should be in
440           TOML syntax of KEY=VALUE, or provided as a path to an extra
441           configuration file. This flag may be specified multiple times. See
442           the command-line overrides section
443           <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides>
444           for more information.
445
446       -C PATH
447           Changes the current working directory before executing any
448           specified operations. This affects things like where cargo looks by
449           default for the project manifest (Cargo.toml), as well as the
450           directories searched for discovering .cargo/config.toml, for
451           example. This option must appear before the command name, for
452           example cargo -C path/to/my-project build.
453
454           This option is only available on the nightly channel
455           <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
456           requires the -Z unstable-options flag to enable (see #10098
457           <https://github.com/rust-lang/cargo/issues/10098>).
458
459       -h, --help
460           Prints help information.
461
462       -Z flag
463           Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
464           details.
465

ENVIRONMENT

467       See the reference
468       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
469       for details on environment variables that Cargo reads.
470

EXIT STATUS

4720: Cargo succeeded.
473
474101: Cargo failed to complete.
475

EXAMPLES

477        1. Output JSON about the current package:
478
479               cargo metadata --format-version=1
480

SEE ALSO

482       cargo(1)
483
484
485
486                                                             CARGO-METADATA(1)
Impressum