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                       /* Array of keywords from the manifest. */
183                       "keywords": [
184                           "cli"
185                       ],
186                       /* The readme value from the manifest or null if not specified. */
187                       "readme": "README.md",
188                       /* The repository value from the manifest or null if not specified. */
189                       "repository": "https://github.com/rust-lang/cargo",
190                       /* The homepage value from the manifest or null if not specified. */
191                       "homepage": "https://rust-lang.org",
192                       /* The documentation value from the manifest or null if not specified. */
193                       "documentation": "https://doc.rust-lang.org/stable/std",
194                       /* The default edition of the package.
195                          Note that individual targets may have different editions.
196                       */
197                       "edition": "2018",
198                       /* Optional string that is the name of a native library the package
199                          is linking to.
200                       */
201                       "links": null,
202                   }
203               ],
204               /* Array of members of the workspace.
205                  Each entry is the Package ID for the package.
206               */
207               "workspace_members": [
208                   "my-package 0.1.0 (path+file:///path/to/my-package)",
209               ],
210               // The resolved dependency graph for the entire workspace. The enabled
211               // features are based on the enabled features for the "current" package.
212               // Inactivated optional dependencies are not listed.
213               //
214               // This is null if --no-deps is specified.
215               //
216               // By default, this includes all dependencies for all target platforms.
217               // The `--filter-platform` flag may be used to narrow to a specific
218               // target triple.
219               "resolve": {
220                   /* Array of nodes within the dependency graph.
221                      Each node is a package.
222                   */
223                   "nodes": [
224                       {
225                           /* The Package ID of this node. */
226                           "id": "my-package 0.1.0 (path+file:///path/to/my-package)",
227                           /* The dependencies of this package, an array of Package IDs. */
228                           "dependencies": [
229                               "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)"
230                           ],
231                           /* The dependencies of this package. This is an alternative to
232                              "dependencies" which contains additional information. In
233                              particular, this handles renamed dependencies.
234                           */
235                           "deps": [
236                               {
237                                   /* The name of the dependency's library target.
238                                      If this is a renamed dependency, this is the new
239                                      name.
240                                   */
241                                   "name": "bitflags",
242                                   /* The Package ID of the dependency. */
243                                   "pkg": "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
244                                   /* Array of dependency kinds. Added in Cargo 1.40. */
245                                   "dep_kinds": [
246                                       {
247                                           /* The dependency kind.
248                                              "dev", "build", or null for a normal dependency.
249                                           */
250                                           "kind": null,
251                                           /* The target platform for the dependency.
252                                              null if not a target dependency.
253                                           */
254                                           "target": "cfg(windows)"
255                                       }
256                                   ]
257                               }
258                           ],
259                           /* Array of features enabled on this package. */
260                           "features": [
261                               "default"
262                           ]
263                       }
264                   ],
265                   /* The root package of the workspace.
266                      This is null if this is a virtual workspace. Otherwise it is
267                      the Package ID of the root package.
268                   */
269                   "root": "my-package 0.1.0 (path+file:///path/to/my-package)"
270               },
271               /* The absolute path to the build directory where Cargo places its output. */
272               "target_directory": "/path/to/my-package/target",
273               /* The version of the schema for this metadata structure.
274                  This will be changed if incompatible changes are ever made.
275               */
276               "version": 1,
277               /* The absolute path to the root of the workspace. */
278               "workspace_root": "/path/to/my-package"
279               /* Workspace metadata.
280                  This is null if no metadata is specified. */
281               "metadata": {
282                   "docs": {
283                       "rs": {
284                           "all-features": true
285                       }
286                   }
287               }
288           }
289

OPTIONS

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

ENVIRONMENT

401       See the reference
402       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
403       for details on environment variables that Cargo reads.
404

EXIT STATUS

4060: Cargo succeeded.
407
408101: Cargo failed to complete.
409

EXAMPLES

411        1. Output JSON about the current package:
412
413               cargo metadata --format-version=1
414

SEE ALSO

416       cargo(1)
417
418
419
420                                                             CARGO-METADATA(1)
Impressum