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       It is recommended to include the --format-version flag to future-proof
16       your code to ensure the output is in the format you are expecting.
17
18       See the cargo_metadata crate <https://crates.io/crates/cargo_metadata>
19       for a Rust API for reading the metadata.
20

OUTPUT FORMAT

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

OPTIONS

293   Output Options
294       --no-deps
295           Output information only about the workspace members and don't fetch
296           dependencies.
297
298       --format-version version
299           Specify the version of the output format to use. Currently 1 is the
300           only possible value.
301
302       --filter-platform triple
303           This filters the resolve output to only include dependencies for
304           the given target triple. Without this flag, the resolve includes
305           all targets.
306
307           Note that the dependencies listed in the "packages" array still
308           includes all dependencies. Each package definition is intended to
309           be an unaltered reproduction of the information within Cargo.toml.
310
311   Feature Selection
312       The feature flags allow you to control which features are enabled. When
313       no feature options are given, the default feature is activated for
314       every selected package.
315
316       See the features documentation
317       <https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options>
318       for more details.
319
320       -F features, --features features
321           Space or comma separated list of features to activate. Features of
322           workspace members may be enabled with package-name/feature-name
323           syntax. This flag may be specified multiple times, which enables
324           all specified features.
325
326       --all-features
327           Activate all available features of all selected packages.
328
329       --no-default-features
330           Do not activate the default feature of the selected packages.
331
332   Display Options
333       -v, --verbose
334           Use verbose output. May be specified twice for "very verbose"
335           output which includes extra output such as dependency warnings and
336           build script output. May also be specified with the term.verbose
337           config value
338           <https://doc.rust-lang.org/cargo/reference/config.html>.
339
340       -q, --quiet
341           Do not print cargo log messages. May also be specified with the
342           term.quiet config value
343           <https://doc.rust-lang.org/cargo/reference/config.html>.
344
345       --color when
346           Control when colored output is used. Valid values:
347
348auto (default): Automatically detect if color support is
349               available on the terminal.
350
351always: Always display colors.
352
353never: Never display colors.
354
355           May also be specified with the term.color config value
356           <https://doc.rust-lang.org/cargo/reference/config.html>.
357
358   Manifest Options
359       --manifest-path path
360           Path to the Cargo.toml file. By default, Cargo searches for the
361           Cargo.toml file in the current directory or any parent directory.
362
363       --frozen, --locked
364           Either of these flags requires that the Cargo.lock file is
365           up-to-date. If the lock file is missing, or it needs to be updated,
366           Cargo will exit with an error. The --frozen flag also prevents
367           Cargo from attempting to access the network to determine if it is
368           out-of-date.
369
370           These may be used in environments where you want to assert that the
371           Cargo.lock file is up-to-date (such as a CI build) or want to avoid
372           network access.
373
374       --offline
375           Prevents Cargo from accessing the network for any reason. Without
376           this flag, Cargo will stop with an error if it needs to access the
377           network and the network is not available. With this flag, Cargo
378           will attempt to proceed without the network if possible.
379
380           Beware that this may result in different dependency resolution than
381           online mode. Cargo will restrict itself to crates that are
382           downloaded locally, even if there might be a newer version as
383           indicated in the local copy of the index. See the cargo-fetch(1)
384           command to download dependencies before going offline.
385
386           May also be specified with the net.offline config value
387           <https://doc.rust-lang.org/cargo/reference/config.html>.
388
389   Common Options
390       +toolchain
391           If Cargo has been installed with rustup, and the first argument to
392           cargo begins with +, it will be interpreted as a rustup toolchain
393           name (such as +stable or +nightly). See the rustup documentation
394           <https://rust-lang.github.io/rustup/overrides.html> for more
395           information about how toolchain overrides work.
396
397       --config KEY=VALUE or PATH
398           Overrides a Cargo configuration value. The argument should be in
399           TOML syntax of KEY=VALUE, or provided as a path to an extra
400           configuration file. This flag may be specified multiple times. See
401           the command-line overrides section
402           <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides>
403           for more information.
404
405       -h, --help
406           Prints help information.
407
408       -Z flag
409           Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
410           details.
411

ENVIRONMENT

413       See the reference
414       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
415       for details on environment variables that Cargo reads.
416

EXIT STATUS

4180: Cargo succeeded.
419
420101: Cargo failed to complete.
421

EXAMPLES

423        1. Output JSON about the current package:
424
425               cargo metadata --format-version=1
426

SEE ALSO

428       cargo(1)
429
430
431
432                                                             CARGO-METADATA(1)
Impressum