1CARGO-METADATA(1)                                            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                               /* A string of the URL of the registry this dependency is from.
84                                  If not specified or null, the dependency is from the default
85                                  registry (crates.io).
86                               */
87                               "registry": null
88                           }
89                       ],
90                       /* Array of Cargo targets. */
91                       "targets": [
92                           {
93                               /* Array of target kinds.
94                                  - lib targets list the `crate-type` values from the
95                                    manifest such as "lib", "rlib", "dylib",
96                                    "proc-macro", etc. (default ["lib"])
97                                  - binary is ["bin"]
98                                  - example is ["example"]
99                                  - integration test is ["test"]
100                                  - benchmark is ["bench"]
101                                  - build script is ["custom-build"]
102                               */
103                               "kind": [
104                                   "bin"
105                               ],
106                               /* Array of crate types.
107                                  - lib and example libraries list the `crate-type` values
108                                    from the manifest such as "lib", "rlib", "dylib",
109                                    "proc-macro", etc. (default ["lib"])
110                                  - all other target kinds are ["bin"]
111                               */
112                               "crate_types": [
113                                   "bin"
114                               ],
115                               /* The name of the target. */
116                               "name": "my-package",
117                               /* Absolute path to the root source file of the target. */
118                               "src_path": "/path/to/my-package/src/main.rs",
119                               /* The Rust edition of the target.
120                                  Defaults to the package edition.
121                               */
122                               "edition": "2018",
123                               /* Array of required features.
124                                  This property is not included if no required features are set.
125                               */
126                               "required-features": ["feat1"],
127                               /* Whether or not this target has doc tests enabled, and
128                                  the target is compatible with doc testing.
129                               */
130                               "doctest": false
131                           }
132                       ],
133                       /* Set of features defined for the package.
134                          Each feature maps to an array of features or dependencies it
135                          enables.
136                       */
137                       "features": {
138                           "default": [
139                               "feat1"
140                           ],
141                           "feat1": [],
142                           "feat2": []
143                       },
144                       /* Absolute path to this package's manifest. */
145                       "manifest_path": "/path/to/my-package/Cargo.toml",
146                       /* Package metadata.
147                          This is null if no metadata is specified.
148                       */
149                       "metadata": {
150                           "docs": {
151                               "rs": {
152                                   "all-features": true
153                               }
154                           }
155                       },
156                       /* List of registries to which this package may be published.
157                          Publishing is unrestricted if null, and forbidden if an empty array. */
158                       "publish": [
159                           "crates-io"
160                       ],
161                       /* Array of authors from the manifest.
162                          Empty array if no authors specified.
163                       */
164                       "authors": [
165                           "Jane Doe <user@example.com>"
166                       ],
167                       /* Array of categories from the manifest. */
168                       "categories": [
169                           "command-line-utilities"
170                       ],
171                       /* Array of keywords from the manifest. */
172                       "keywords": [
173                           "cli"
174                       ],
175                       /* The readme value from the manifest or null if not specified. */
176                       "readme": "README.md",
177                       /* The repository value from the manifest or null if not specified. */
178                       "repository": "https://github.com/rust-lang/cargo",
179                       /* The default edition of the package.
180                          Note that individual targets may have different editions.
181                       */
182                       "edition": "2018",
183                       /* Optional string that is the name of a native library the package
184                          is linking to.
185                       */
186                       "links": null,
187                   }
188               ],
189               /* Array of members of the workspace.
190                  Each entry is the Package ID for the package.
191               */
192               "workspace_members": [
193                   "my-package 0.1.0 (path+file:///path/to/my-package)",
194               ],
195               // The resolved dependency graph for the entire workspace. The enabled
196               // features are based on the enabled features for the "current" package.
197               // Inactivated optional dependencies are not listed.
198               //
199               // This is null if --no-deps is specified.
200               //
201               // By default, this includes all dependencies for all target platforms.
202               // The `--filter-platform` flag may be used to narrow to a specific
203               // target triple.
204               "resolve": {
205                   /* Array of nodes within the dependency graph.
206                      Each node is a package.
207                   */
208                   "nodes": [
209                       {
210                           /* The Package ID of this node. */
211                           "id": "my-package 0.1.0 (path+file:///path/to/my-package)",
212                           /* The dependencies of this package, an array of Package IDs. */
213                           "dependencies": [
214                               "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)"
215                           ],
216                           /* The dependencies of this package. This is an alternative to
217                              "dependencies" which contains additional information. In
218                              particular, this handles renamed dependencies.
219                           */
220                           "deps": [
221                               {
222                                   /* The name of the dependency's library target.
223                                      If this is a renamed dependency, this is the new
224                                      name.
225                                   */
226                                   "name": "bitflags",
227                                   /* The Package ID of the dependency. */
228                                   "pkg": "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
229                                   /* Array of dependency kinds. Added in Cargo 1.40. */
230                                   "dep_kinds": [
231                                       {
232                                           /* The dependency kind.
233                                              "dev", "build", or null for a normal dependency.
234                                           */
235                                           "kind": null,
236                                           /* The target platform for the dependency.
237                                              null if not a target dependency.
238                                           */
239                                           "target": "cfg(windows)"
240                                       }
241                                   ]
242                               }
243                           ],
244                           /* Array of features enabled on this package. */
245                           "features": [
246                               "default"
247                           ]
248                       }
249                   ],
250                   /* The root package of the workspace.
251                      This is null if this is a virtual workspace. Otherwise it is
252                      the Package ID of the root package.
253                   */
254                   "root": "my-package 0.1.0 (path+file:///path/to/my-package)"
255               },
256               /* The absolute path to the build directory where Cargo places its output. */
257               "target_directory": "/path/to/my-package/target",
258               /* The version of the schema for this metadata structure.
259                  This will be changed if incompatible changes are ever made.
260               */
261               "version": 1,
262               /* The absolute path to the root of the workspace. */
263               "workspace_root": "/path/to/my-package"
264           }
265

OPTIONS

267   Output Options
268       --no-deps
269           Output information only about the workspace members and don’t fetch
270           dependencies.
271
272       --format-version VERSION
273           Specify the version of the output format to use. Currently 1 is the
274           only possible value.
275
276       --filter-platform TRIPLE
277           This filters the resolve output to only include dependencies for
278           the given target triple. Without this flag, the resolve includes
279           all targets.
280
281           Note that the dependencies listed in the "packages" array still
282           includes all dependencies. Each package definition is intended to
283           be an unaltered reproduction of the information within Cargo.toml.
284
285   Feature Selection
286       The feature flags allow you to control the enabled features for the
287       "current" package. The "current" package is the package in the current
288       directory, or the one specified in --manifest-path. If running in the
289       root of a virtual workspace, then the default features are selected for
290       all workspace members, or all features if --all-features is specified.
291
292       When no feature options are given, the default feature is activated for
293       every selected package.
294
295       --features FEATURES
296           Space or comma separated list of features to activate. These
297           features only apply to the current directory’s package. Features of
298           direct dependencies may be enabled with <dep-name>/<feature-name>
299           syntax. This flag may be specified multiple times, which enables
300           all specified features.
301
302       --all-features
303           Activate all available features of all selected packages.
304
305       --no-default-features
306           Do not activate the default feature of the current directory’s
307           package.
308
309   Display Options
310       -v, --verbose
311           Use verbose output. May be specified twice for "very verbose"
312           output which includes extra output such as dependency warnings and
313           build script output. May also be specified with the term.verbose
314           config value
315           <https://doc.rust-lang.org/cargo/reference/config.html>.
316
317       -q, --quiet
318           No output printed to stdout.
319
320       --color WHEN
321           Control when colored output is used. Valid values:
322
323           ·   auto (default): Automatically detect if color support is
324               available on the terminal.
325
326           ·   always: Always display colors.
327
328           ·   never: Never display colors.
329
330           May also be specified with the term.color config value
331           <https://doc.rust-lang.org/cargo/reference/config.html>.
332
333   Manifest Options
334       --manifest-path PATH
335           Path to the Cargo.toml file. By default, Cargo searches for the
336           Cargo.toml file in the current directory or any parent directory.
337
338       --frozen, --locked
339           Either of these flags requires that the Cargo.lock file is
340           up-to-date. If the lock file is missing, or it needs to be updated,
341           Cargo will exit with an error. The --frozen flag also prevents
342           Cargo from attempting to access the network to determine if it is
343           out-of-date.
344
345           These may be used in environments where you want to assert that the
346           Cargo.lock file is up-to-date (such as a CI build) or want to avoid
347           network access.
348
349       --offline
350           Prevents Cargo from accessing the network for any reason. Without
351           this flag, Cargo will stop with an error if it needs to access the
352           network and the network is not available. With this flag, Cargo
353           will attempt to proceed without the network if possible.
354
355           Beware that this may result in different dependency resolution than
356           online mode. Cargo will restrict itself to crates that are
357           downloaded locally, even if there might be a newer version as
358           indicated in the local copy of the index. See the cargo-fetch(1)
359           command to download dependencies before going offline.
360
361           May also be specified with the net.offline config value
362           <https://doc.rust-lang.org/cargo/reference/config.html>.
363
364   Common Options
365       -h, --help
366           Prints help information.
367
368       -Z FLAG...
369           Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
370           details.
371

ENVIRONMENT

373       See the reference
374       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
375       for details on environment variables that Cargo reads.
376

EXIT STATUS

378       0
379           Cargo succeeded.
380
381       101
382           Cargo failed to complete.
383

EXAMPLES

385        1. Output JSON about the current package:
386
387               cargo metadata --format-version=1
388

SEE ALSO

390       cargo(1)
391
392
393
394                                  2020-02-24                 CARGO-METADATA(1)
Impressum