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

OPTIONS

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

ENVIRONMENT

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

EXIT STATUS

404       ·  0: Cargo succeeded.
405
406       ·  101: Cargo failed to complete.
407

EXAMPLES

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

SEE ALSO

414       cargo(1)
415
416
417
418                                                             CARGO-METADATA(1)
Impressum