fork/cargo

git clone https://git.julia.blue/fork/cargo

Weihang Lodocs(metadata): Added build_directory to cargo metadata documentation (#15410)210ebb5d1

0.91.0
25.3 KiB519 linesraw
1CARGO-METADATA(1)
2
3NAME
4       cargo-metadata — Machine-readable metadata about the current package
5
6SYNOPSIS
7       cargo metadata [options]
8
9DESCRIPTION
10       Output JSON to stdout containing information about the workspace members
11       and resolved dependencies of the current package.
12
13       The output format is subject to change in future versions of Cargo. It
14       is recommended to include the --format-version flag to future-proof your
15       code and ensure the output is in the format you are expecting. For more
16       on the expectations, see “Compatibility”.
17
18       See the cargo_metadata crate <https://crates.io/crates/cargo_metadata>
19       for a Rust API for reading the metadata.
20
21OUTPUT FORMAT
22   Compatibility
23       Within the same output format version, the compatibility is maintained,
24       except some scenarios. The following is a non-exhaustive list of changes
25       that are not considered as incompatible:
26
27       o  Adding new fields — New fields will be added when needed. Reserving
28          this helps Cargo evolve without bumping the format version too often.
29
30       o  Adding new values for enum-like fields — Same as adding new fields.
31          It keeps metadata evolving without stagnation.
32
33       o  Changing opaque representations — The inner representations of some
34          fields are implementation details. For example, fields related to
35          “Source ID” are treated as opaque identifiers to differentiate
36          packages or sources. Consumers shouldn’t rely on those
37          representations unless specified.
38
39   JSON format
40       The JSON output has the following format:
41
42           {
43               /* Array of all packages in the workspace.
44                  It also includes all feature-enabled dependencies unless --no-deps is used.
45               */
46               "packages": [
47                   {
48                       /* The name of the package. */
49                       "name": "my-package",
50                       /* The version of the package. */
51                       "version": "0.1.0",
52                       /* The Package ID for referring to the
53                          package within the document and as the `--package` argument to many commands
54                       */
55                       "id": "file:///path/to/my-package#0.1.0",
56                       /* The license value from the manifest, or null. */
57                       "license": "MIT/Apache-2.0",
58                       /* The license-file value from the manifest, or null. */
59                       "license_file": "LICENSE",
60                       /* The description value from the manifest, or null. */
61                       "description": "Package description.",
62                       /* The source ID of the package, an "opaque" identifier representing
63                          where a package is retrieved from. See "Compatibility" above for
64                          the stability guarantee.
65           
66                          This is null for path dependencies and workspace members.
67           
68                          For other dependencies, it is a string with the format:
69                          - "registry+URL" for registry-based dependencies.
70                            Example: "registry+https://github.com/rust-lang/crates.io-index"
71                          - "git+URL" for git-based dependencies.
72                            Example: "git+https://github.com/rust-lang/cargo?rev=5e85ba14aaa20f8133863373404cb0af69eeef2c#5e85ba14aaa20f8133863373404cb0af69eeef2c"
73                          - "sparse+URL" for dependencies from a sparse registry
74                            Example: "sparse+https://my-sparse-registry.org"
75           
76                          The value after the `+` is not explicitly defined, and may change
77                          between versions of Cargo and may not directly correlate to other
78                          things, such as registry definitions in a config file. New source
79                          kinds may be added in the future which will have different `+`
80                          prefixed identifiers.
81                       */
82                       "source": null,
83                       /* Array of dependencies declared in the package's manifest. */
84                       "dependencies": [
85                           {
86                               /* The name of the dependency. */
87                               "name": "bitflags",
88                               /* The source ID of the dependency. May be null, see
89                                  description for the package source.
90                               */
91                               "source": "registry+https://github.com/rust-lang/crates.io-index",
92                               /* The version requirement for the dependency.
93                                  Dependencies without a version requirement have a value of "*".
94                               */
95                               "req": "^1.0",
96                               /* The dependency kind.
97                                  "dev", "build", or null for a normal dependency.
98                               */
99                               "kind": null,
100                               /* If the dependency is renamed, this is the new name for
101                                  the dependency as a string.  null if it is not renamed.
102                               */
103                               "rename": null,
104                               /* Boolean of whether or not this is an optional dependency. */
105                               "optional": false,
106                               /* Boolean of whether or not default features are enabled. */
107                               "uses_default_features": true,
108                               /* Array of features enabled. */
109                               "features": [],
110                               /* The target platform for the dependency.
111                                  null if not a target dependency.
112                               */
113                               "target": "cfg(windows)",
114                               /* The file system path for a local path dependency.
115                                  not present if not a path dependency.
116                               */
117                               "path": "/path/to/dep",
118                               /* A string of the URL of the registry this dependency is from.
119                                  If not specified or null, the dependency is from the default
120                                  registry (crates.io).
121                               */
122                               "registry": null,
123                               /* (unstable) Boolean flag of whether or not this is a pulbic
124                                  dependency. This field is only present when
125                                  `-Zpublic-dependency` is enabled.
126                               */
127                               "public": false
128                           }
129                       ],
130                       /* Array of Cargo targets. */
131                       "targets": [
132                           {
133                               /* Array of target kinds.
134                                  - lib targets list the `crate-type` values from the
135                                    manifest such as "lib", "rlib", "dylib",
136                                    "proc-macro", etc. (default ["lib"])
137                                  - binary is ["bin"]
138                                  - example is ["example"]
139                                  - integration test is ["test"]
140                                  - benchmark is ["bench"]
141                                  - build script is ["custom-build"]
142                               */
143                               "kind": [
144                                   "bin"
145                               ],
146                               /* Array of crate types.
147                                  - lib and example libraries list the `crate-type` values
148                                    from the manifest such as "lib", "rlib", "dylib",
149                                    "proc-macro", etc. (default ["lib"])
150                                  - all other target kinds are ["bin"]
151                               */
152                               "crate_types": [
153                                   "bin"
154                               ],
155                               /* The name of the target.
156                                  For lib targets, dashes will be replaced with underscores.
157                               */
158                               "name": "my-package",
159                               /* Absolute path to the root source file of the target. */
160                               "src_path": "/path/to/my-package/src/main.rs",
161                               /* The Rust edition of the target.
162                                  Defaults to the package edition.
163                               */
164                               "edition": "2018",
165                               /* Array of required features.
166                                  This property is not included if no required features are set.
167                               */
168                               "required-features": ["feat1"],
169                               /* Whether the target should be documented by `cargo doc`. */
170                               "doc": true,
171                               /* Whether or not this target has doc tests enabled, and
172                                  the target is compatible with doc testing.
173                               */
174                               "doctest": false,
175                               /* Whether or not this target should be built and run with `--test`
176                               */
177                               "test": true
178                           }
179                       ],
180                       /* Set of features defined for the package.
181                          Each feature maps to an array of features or dependencies it
182                          enables.
183                       */
184                       "features": {
185                           "default": [
186                               "feat1"
187                           ],
188                           "feat1": [],
189                           "feat2": []
190                       },
191                       /* Absolute path to this package's manifest. */
192                       "manifest_path": "/path/to/my-package/Cargo.toml",
193                       /* Package metadata.
194                          This is null if no metadata is specified.
195                       */
196                       "metadata": {
197                           "docs": {
198                               "rs": {
199                                   "all-features": true
200                               }
201                           }
202                       },
203                       /* List of registries to which this package may be published.
204                          Publishing is unrestricted if null, and forbidden if an empty array. */
205                       "publish": [
206                           "crates-io"
207                       ],
208                       /* Array of authors from the manifest.
209                          Empty array if no authors specified.
210                       */
211                       "authors": [
212                           "Jane Doe <user@example.com>"
213                       ],
214                       /* Array of categories from the manifest. */
215                       "categories": [
216                           "command-line-utilities"
217                       ],
218                       /* Optional string that is the default binary picked by cargo run. */
219                       "default_run": null,
220                       /* Optional string that is the minimum supported rust version */
221                       "rust_version": "1.56",
222                       /* Array of keywords from the manifest. */
223                       "keywords": [
224                           "cli"
225                       ],
226                       /* The readme value from the manifest or null if not specified. */
227                       "readme": "README.md",
228                       /* The repository value from the manifest or null if not specified. */
229                       "repository": "https://github.com/rust-lang/cargo",
230                       /* The homepage value from the manifest or null if not specified. */
231                       "homepage": "https://rust-lang.org",
232                       /* The documentation value from the manifest or null if not specified. */
233                       "documentation": "https://doc.rust-lang.org/stable/std",
234                       /* The default edition of the package.
235                          Note that individual targets may have different editions.
236                       */
237                       "edition": "2018",
238                       /* Optional string that is the name of a native library the package
239                          is linking to.
240                       */
241                       "links": null,
242                   }
243               ],
244               /* Array of members of the workspace.
245                  Each entry is the Package ID for the package.
246               */
247               "workspace_members": [
248                   "file:///path/to/my-package#0.1.0",
249               ],
250               /* Array of default members of the workspace.
251                  Each entry is the Package ID for the package.
252               */
253               "workspace_default_members": [
254                   "file:///path/to/my-package#0.1.0",
255               ],
256               // The resolved dependency graph for the entire workspace. The enabled
257               // features are based on the enabled features for the "current" package.
258               // Inactivated optional dependencies are not listed.
259               //
260               // This is null if --no-deps is specified.
261               //
262               // By default, this includes all dependencies for all target platforms.
263               // The `--filter-platform` flag may be used to narrow to a specific
264               // target triple.
265               "resolve": {
266                   /* Array of nodes within the dependency graph.
267                      Each node is a package.
268                   */
269                   "nodes": [
270                       {
271                           /* The Package ID of this node. */
272                           "id": "file:///path/to/my-package#0.1.0",
273                           /* The dependencies of this package, an array of Package IDs. */
274                           "dependencies": [
275                               "https://github.com/rust-lang/crates.io-index#bitflags@1.0.4"
276                           ],
277                           /* The dependencies of this package. This is an alternative to
278                              "dependencies" which contains additional information. In
279                              particular, this handles renamed dependencies.
280                           */
281                           "deps": [
282                               {
283                                   /* The name of the dependency's library target.
284                                      If this is a renamed dependency, this is the new
285                                      name.
286                                   */
287                                   "name": "bitflags",
288                                   /* The Package ID of the dependency. */
289                                   "pkg": "https://github.com/rust-lang/crates.io-index#bitflags@1.0.4"
290                                   /* Array of dependency kinds. Added in Cargo 1.40. */
291                                   "dep_kinds": [
292                                       {
293                                           /* The dependency kind.
294                                              "dev", "build", or null for a normal dependency.
295                                           */
296                                           "kind": null,
297                                           /* The target platform for the dependency.
298                                              null if not a target dependency.
299                                           */
300                                           "target": "cfg(windows)"
301                                       }
302                                   ]
303                               }
304                           ],
305                           /* Array of features enabled on this package. */
306                           "features": [
307                               "default"
308                           ]
309                       }
310                   ],
311                   /* The package in the current working directory (if --manifest-path is not given).
312                      This is null if there is a virtual workspace. Otherwise it is
313                      the Package ID of the package.
314                   */
315                   "root": "file:///path/to/my-package#0.1.0",
316               },
317               /* The absolute path to the target directory where Cargo places its output. */
318               "target_directory": "/path/to/my-package/target",
319               /* The absolute path to the build directory where Cargo places intermediate build artifacts. (unstable) */
320               "build_directory": "/path/to/my-package/build-dir",
321               /* The version of the schema for this metadata structure.
322                  This will be changed if incompatible changes are ever made.
323               */
324               "version": 1,
325               /* The absolute path to the root of the workspace. */
326               "workspace_root": "/path/to/my-package"
327               /* Workspace metadata.
328                  This is null if no metadata is specified. */
329               "metadata": {
330                   "docs": {
331                       "rs": {
332                           "all-features": true
333                       }
334                   }
335               }
336           }
337
338       Notes:
339
340       o  For "id" field syntax, see Package ID Specifications
341          <https://doc.rust-lang.org/cargo/reference/pkgid-spec.html> in the
342          reference.
343
344OPTIONS
345   Output Options
346       --no-deps
347           Output information only about the workspace members and don’t
348           fetch dependencies.
349
350       --format-version version
351           Specify the version of the output format to use. Currently 1 is the
352           only possible value.
353
354       --filter-platform triple
355           This filters the resolve output to only include dependencies for the
356           given target triple
357           <https://doc.rust-lang.org/cargo/appendix/glossary.html#target>.
358           Without this flag, the resolve includes all targets.
359
360           Note that the dependencies listed in the “packages” array still
361           includes all dependencies. Each package definition is intended to be
362           an unaltered reproduction of the information within Cargo.toml.
363
364   Feature Selection
365       The feature flags allow you to control which features are enabled. When
366       no feature options are given, the default feature is activated for every
367       selected package.
368
369       See the features documentation
370       <https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options>
371       for more details.
372
373       -F features, --features features
374           Space or comma separated list of features to activate. Features of
375           workspace members may be enabled with package-name/feature-name
376           syntax. This flag may be specified multiple times, which enables all
377           specified features.
378
379       --all-features
380           Activate all available features of all selected packages.
381
382       --no-default-features
383           Do not activate the default feature of the selected packages.
384
385   Display Options
386       -v, --verbose
387           Use verbose output. May be specified twice for “very verbose”
388           output which includes extra output such as dependency warnings and
389           build script output. May also be specified with the term.verbose
390           config value
391           <https://doc.rust-lang.org/cargo/reference/config.html>.
392
393       -q, --quiet
394           Do not print cargo log messages. May also be specified with the
395           term.quiet config value
396           <https://doc.rust-lang.org/cargo/reference/config.html>.
397
398       --color when
399           Control when colored output is used. Valid values:
400
401           o  auto (default): Automatically detect if color support is
402              available on the terminal.
403
404           o  always: Always display colors.
405
406           o  never: Never display colors.
407
408           May also be specified with the term.color config value
409           <https://doc.rust-lang.org/cargo/reference/config.html>.
410
411   Manifest Options
412       --manifest-path path
413           Path to the Cargo.toml file. By default, Cargo searches for the
414           Cargo.toml file in the current directory or any parent directory.
415
416       --locked
417           Asserts that the exact same dependencies and versions are used as
418           when the existing Cargo.lock file was originally generated. Cargo
419           will exit with an error when either of the following scenarios
420           arises:
421
422           o  The lock file is missing.
423
424           o  Cargo attempted to change the lock file due to a different
425              dependency resolution.
426
427           It may be used in environments where deterministic builds are
428           desired, such as in CI pipelines.
429
430       --offline
431           Prevents Cargo from accessing the network for any reason. Without
432           this flag, Cargo will stop with an error if it needs to access the
433           network and the network is not available. With this flag, Cargo will
434           attempt to proceed without the network if possible.
435
436           Beware that this may result in different dependency resolution than
437           online mode. Cargo will restrict itself to crates that are
438           downloaded locally, even if there might be a newer version as
439           indicated in the local copy of the index. See the cargo-fetch(1)
440           command to download dependencies before going offline.
441
442           May also be specified with the net.offline config value
443           <https://doc.rust-lang.org/cargo/reference/config.html>.
444
445       --frozen
446           Equivalent to specifying both --locked and --offline.
447
448       --lockfile-path PATH
449           Changes the path of the lockfile from the default
450           (<workspace_root>/Cargo.lock) to PATH. PATH must end with Cargo.lock
451           (e.g. --lockfile-path /tmp/temporary-lockfile/Cargo.lock). Note that
452           providing --lockfile-path will ignore existing lockfile at the
453           default path, and instead will either use the lockfile from PATH, or
454           write a new lockfile into the provided PATH if it doesn’t exist.
455           This flag can be used to run most commands in read-only directories,
456           writing lockfile into the provided PATH.
457
458           This option is only available on the nightly channel
459           <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
460           requires the -Z unstable-options flag to enable (see #14421
461           <https://github.com/rust-lang/cargo/issues/14421>).
462
463   Common Options
464       +toolchain
465           If Cargo has been installed with rustup, and the first argument to
466           cargo begins with +, it will be interpreted as a rustup toolchain
467           name (such as +stable or +nightly). See the rustup documentation
468           <https://rust-lang.github.io/rustup/overrides.html> for more
469           information about how toolchain overrides work.
470
471       --config KEY=VALUE or PATH
472           Overrides a Cargo configuration value. The argument should be in
473           TOML syntax of KEY=VALUE, or provided as a path to an extra
474           configuration file. This flag may be specified multiple times. See
475           the command-line overrides section
476           <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides>
477           for more information.
478
479       -C PATH
480           Changes the current working directory before executing any specified
481           operations. This affects things like where cargo looks by default
482           for the project manifest (Cargo.toml), as well as the directories
483           searched for discovering .cargo/config.toml, for example. This
484           option must appear before the command name, for example cargo -C
485           path/to/my-project build.
486
487           This option is only available on the nightly channel
488           <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
489           requires the -Z unstable-options flag to enable (see #10098
490           <https://github.com/rust-lang/cargo/issues/10098>).
491
492       -h, --help
493           Prints help information.
494
495       -Z flag
496           Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
497           details.
498
499ENVIRONMENT
500       See the reference
501       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
502       for details on environment variables that Cargo reads.
503
504EXIT STATUS
505       o  0: Cargo succeeded.
506
507       o  101: Cargo failed to complete.
508
509EXAMPLES
510       1. Output JSON about the current package:
511
512              cargo metadata --format-version=1
513
514SEE ALSO
515       cargo(1), cargo-pkgid(1), Package ID Specifications
516       <https://doc.rust-lang.org/cargo/reference/pkgid-spec.html>, JSON
517       messages
518       <https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages>
519