# cargo-metadata(1)
## NAME
cargo-metadata --- Machine-readable metadata about the current package
## SYNOPSIS
`cargo metadata` [_options_]
## DESCRIPTION
Output JSON to stdout containing information about the workspace members and
resolved dependencies of the current package.
The format of the output is subject to change in futures versions of Cargo. It
is recommended to include the `--format-version` flag to future-proof your code
to ensure the output is in the format you are expecting. For more on the
expectations, see ["Compatibility"](#compatibility).
See the [cargo_metadata crate](https://crates.io/crates/cargo_metadata)
for a Rust API for reading the metadata.
## OUTPUT FORMAT
### Compatibility
Within the same output format version, the compatibility is maintained, except
some scenarios. The following is a non-exhaustive list of changes that are not
considersed as incompatible:
* **Adding new fields** — New fields will be added when needed. Reserving this
helps Cargo evolve without bumping the format version too often.
* **Adding new values for enum-like fields** — Same as adding new fields. It
keeps metadata evolving without stagnation.
* **Changing opaque representations** — The inner representations of some
fields are implementation details. For example, fields related to
"Source ID" are treated as opaque identifiers to differentiate packages or
sources. Consumers shouldn't rely on those representations unless specified.
### JSON format
The JSON output has the following format:
```javascript
{
/* Array of all packages in the workspace.
It also includes all feature-enabled dependencies unless --no-deps is used.
*/
"packages": [
{
/* The name of the package. */
"name": "my-package",
/* The version of the package. */
"version": "0.1.0",
/* The Package ID for referring to the
package within the document and as the `--package` argument to many commands
*/
"id": "file:///path/to/my-package#0.1.0",
/* The license value from the manifest, or null. */
"license": "MIT/Apache-2.0",
/* The license-file value from the manifest, or null. */
"license_file": "LICENSE",
/* The description value from the manifest, or null. */
"description": "Package description.",
/* The source ID of the package, an "opaque" identifier representing
where a package is retrieved from. See "Compatibility" above for
the stability guarantee.
This is null for path dependencies and workspace members.
For other dependencies, it is a string with the format:
- "registry+URL" for registry-based dependencies.
Example: "registry+https://github.com/rust-lang/crates.io-index"
- "git+URL" for git-based dependencies.
Example: "git+https://github.com/rust-lang/cargo?rev=5e85ba14aaa20f8133863373404cb0af69eeef2c#5e85ba14aaa20f8133863373404cb0af69eeef2c"
- "sparse+URL" for dependencies from a sparse registry
Example: "sparse+https://my-sparse-registry.org"
The value after the `+` is not explicitly defined, and may change
between versions of Cargo and may not directly correlate to other
things, such as registry definitions in a config file. New source
kinds may be added in the future which will have different `+`
prefixed identifiers.
*/
"source": null,
/* Array of dependencies declared in the package's manifest. */
"dependencies": [
{
/* The name of the dependency. */
"name": "bitflags",
/* The source ID of the dependency. May be null, see
description for the package source.
*/
"source": "registry+https://github.com/rust-lang/crates.io-index",
/* The version requirement for the dependency.
Dependencies without a version requirement have a value of "*".
*/
"req": "^1.0",
/* The dependency kind.
"dev", "build", or null for a normal dependency.
*/
"kind": null,
/* If the dependency is renamed, this is the new name for
the dependency as a string. null if it is not renamed.
*/
"rename": null,
/* Boolean of whether or not this is an optional dependency. */
"optional": false,
/* Boolean of whether or not default features are enabled. */
"uses_default_features": true,
/* Array of features enabled. */
"features": [],
/* The target platform for the dependency.
null if not a target dependency.
*/
"target": "cfg(windows)",
/* The file system path for a local path dependency.
not present if not a path dependency.
*/
"path": "/path/to/dep",
/* A string of the URL of the registry this dependency is from.
If not specified or null, the dependency is from the default
registry (crates.io).
*/
"registry": null
}
],
/* Array of Cargo targets. */
"targets": [
{
/* Array of target kinds.
- lib targets list the `crate-type` values from the
manifest such as "lib", "rlib", "dylib",
"proc-macro", etc. (default ["lib"])
- binary is ["bin"]
- example is ["example"]
- integration test is ["test"]
- benchmark is ["bench"]
- build script is ["custom-build"]
*/
"kind": [
"bin"
],
/* Array of crate types.
- lib and example libraries list the `crate-type` values
from the manifest such as "lib", "rlib", "dylib",
"proc-macro", etc. (default ["lib"])
- all other target kinds are ["bin"]
*/
"crate_types": [
"bin"
],
/* The name of the target. */
"name": "my-package",
/* Absolute path to the root source file of the target. */
"src_path": "/path/to/my-package/src/main.rs",
/* The Rust edition of the target.
Defaults to the package edition.
*/
"edition": "2018",
/* Array of required features.
This property is not included if no required features are set.
*/
"required-features": ["feat1"],
/* Whether the target should be documented by `cargo doc`. */
"doc": true,
/* Whether or not this target has doc tests enabled, and
the target is compatible with doc testing.
*/
"doctest": false,
/* Whether or not this target should be built and run with `--test`
*/
"test": true
}
],
/* Set of features defined for the package.
Each feature maps to an array of features or dependencies it
enables.
*/
"features": {
"default": [
"feat1"
],
"feat1": [],
"feat2": []
},
/* Absolute path to this package's manifest. */
"manifest_path": "/path/to/my-package/Cargo.toml",
/* Package metadata.
This is null if no metadata is specified.
*/
"metadata": {
"docs": {
"rs": {
"all-features": true
}
}
},
/* List of registries to which this package may be published.
Publishing is unrestricted if null, and forbidden if an empty array. */
"publish": [
"crates-io"
],
/* Array of authors from the manifest.
Empty array if no authors specified.
*/
"authors": [
"Jane Doe
--no-deps
--format-version
version1
is the only
possible value.--filter-platform
tripleresolve
output to only include dependencies for the
given target triple.
Without this flag, the resolve includes all targets.
Note that the dependencies listed in the “packages” array still includes all
dependencies. Each package definition is intended to be an unaltered
reproduction of the information within Cargo.toml
.
### Feature Selection
The feature flags allow you to control which features are enabled. When no
feature options are given, the `default` feature is activated for every
selected package.
See [the features documentation](../reference/features.html#command-line-feature-options)
for more details.
-F
features--features
featurespackage-name/feature-name
syntax. This flag may
be specified multiple times, which enables all specified features.--all-features
--no-default-features
default
feature of the selected packages.-v
--verbose
term.verbose
config value.-q
--quiet
term.quiet
config value.--color
whenauto
(default): Automatically detect if color support is available on the
terminal.always
: Always display colors.never
: Never display colors.May also be specified with the term.color
config value.
--manifest-path
pathCargo.toml
file. By default, Cargo searches for the
Cargo.toml
file in the current directory or any parent directory.--locked
Cargo.lock
file. Cargo will exit with an error when either of the
following scenarios arises:
Cargo.toml
file.It may be used in environments where you want to assert that the Cargo.lock
file is up-to-date for reproducibility reasons, such as in a CI build.
--offline
Beware that this may result in different dependency resolution than online mode. Cargo will restrict itself to crates that are downloaded locally, even if there might be a newer version as indicated in the local copy of the index. See the cargo-fetch(1) command to download dependencies before going offline.
May also be specified with the net.offline
config value.
--frozen
--locked
and --offline
.+
toolchaincargo
begins with +
, it will be interpreted as a rustup toolchain name (such
as +stable
or +nightly
).
See the rustup documentation
for more information about how toolchain overrides work.--config
KEY=VALUE or PATHKEY=VALUE
,
or provided as a path to an extra configuration file. This flag may be specified multiple times.
See the command-line overrides section for more information.-C
PATHCargo.toml
), as well as
the directories searched for discovering .cargo/config.toml
, for example. This option must
appear before the command name, for example cargo -C path/to/my-project build
.
This option is only available on the nightly
channel and
requires the -Z unstable-options
flag to enable (see
#10098).
-h
--help
-Z
flagcargo -Z help
for details.