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 output format is subject to change in future versions of Cargo. It
is recommended to include the --format-version flag to future-proof your code
and ensure the output is in the format you are expecting. For more on the
expectations, see "Compatibility".
See the cargo_metadata crate 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 considered 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:
Notes:
- For
"id"field syntax, see Package ID Specifications in the reference.
OPTIONS
Output Options
--no-depsOutput information only about the workspace members and don’t fetch dependencies.
--format-versionversionSpecify the version of the output format to use. Currently
1is the only possible value.--filter-platformtripleThis filters the
resolveoutput to only include dependencies for the given target triple. A literal"host-tuple"can be used, which will internally be substituted by the host’s target. 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 for more details.
-Ffeatures--featuresfeaturesSpace or comma separated list of features to activate. Features of workspace members may be enabled with
package-name/feature-namesyntax. This flag may be specified multiple times, which enables all specified features.--all-featuresActivate all available features of all selected packages.
--no-default-featuresDo not activate the
defaultfeature of the selected packages.
Display Options
-v--verboseUse verbose output. May be specified twice for “very verbose” output which includes extra output such as dependency warnings and build script output. May also be specified with the
term.verboseconfig value.-q--quietDo not print cargo log messages. May also be specified with the
term.quietconfig value.--colorwhenControl when colored output is used. Valid values:
auto(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.colorconfig value.
Manifest Options
--manifest-pathpathPath to the
Cargo.tomlfile. By default, Cargo searches for theCargo.tomlfile in the current directory or any parent directory.--lockedAsserts that the exact same dependencies and versions are used as when the existing
Cargo.lockfile was originally generated. Cargo will exit with an error when either of the following scenarios arises:- The lock file is missing.
- Cargo attempted to change the lock file due to a different dependency resolution.
It may be used in environments where deterministic builds are desired, such as in CI pipelines.
--offlinePrevents Cargo from accessing the network for any reason. Without this flag, Cargo will stop with an error if it needs to access the network and the network is not available. With this flag, Cargo will attempt to proceed without the network if possible.
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.offlineconfig value.--frozenEquivalent to specifying both
--lockedand--offline.
Common Options
+toolchainIf Cargo has been installed with rustup, and the first argument to
cargobegins with+, it will be interpreted as a rustup toolchain name (such as+stableor+nightly). See the rustup documentation for more information about how toolchain overrides work.--configKEY=VALUE or PATHOverrides a Cargo configuration value. The argument should be in TOML syntax of
KEY=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.-CPATHChanges the current working directory before executing any specified operations. This affects things like where cargo looks by default for the project manifest (
Cargo.toml), as well as the directories searched for discovering.cargo/config.toml, for example. This option must appear before the command name, for examplecargo -C path/to/my-project build.This option is only available on the nightly channel and requires the
-Z unstable-optionsflag to enable (see #10098).-h--helpPrints help information.
-ZflagUnstable (nightly-only) flags to Cargo. Run
cargo -Z helpfor details.
ENVIRONMENT
See the reference for details on environment variables that Cargo reads.
EXIT STATUS
0: Cargo succeeded.101: Cargo failed to complete.
EXAMPLES
-
Output JSON about the current package:
cargo metadata --format-version=1
SEE ALSO
cargo(1), cargo-pkgid(1), Package ID Specifications, JSON messages