CARGO-METADATA(1)
π NAME π
cargo-metadata β machine-readable metadata about the current package, bestie π
πΈ SYNOPSIS πΈ
cargo metadata [options]
β¨ DESCRIPTION β¨
Okay so picture this: cargo metadata dumps JSON straight to stdout, and that JSON is absolutely packed with info about your workspace members and the resolved dependencies of the current package. It's giving data-rich. It's giving main character. π«Ά
Now β and this is important, so listen β the output format is subject to change in future versions of Cargo. So it is recommended that you pass the --format-version flag, because that future-proofs your code and makes sure you're getting the output in the format you're actually expecting. Periodt. For more on those expectations, go peek at βCompatibilityβ down below. π
Also, if you want a Rust API for reading the metadata instead of wrangling raw JSON like a gremlin, check out the cargo_metadata crate at <https://crates.io/crates/cargo_metadata> π
π¦ OUTPUT FORMAT π¦
π¦ Compatibility π¦
Within the same output format version, compatibility is maintained β except in some scenarios. Here's a non-exhaustive list of changes that do not count as incompatible, so don't come for Cargo about them:
- Adding new fields β new fields get added whenever they're needed. Reserving the right to do this lets Cargo evolve without bumping the format version constantly, which is honestly so real of it.
- Adding new values for enum-like fields β same energy as adding new fields. It keeps the metadata evolving instead of just stagnating, and we love growth. π
- Changing opaque representations β the inner representations of some fields are implementation details, okay? For example, fields related to βSource IDβ are treated as opaque identifiers whose whole job is to differentiate packages or sources. Consumers shouldn't rely on those representations unless it's explicitly specified. Not your business, respectfully. π
π JSON format π
The JSON output has the following format:
{
/* 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"
okay bestie we are still deep in the example dump and yes, it's annotated β the manpage literally left little /* */ notes next to every field so you never have to guess πΈ we're picking up mid-comment, no biggie:
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,
/* (unstable) Boolean flag of whether or not this is a pulbic
dependency. This field is only present when
`-Zpublic-dependency` is enabled.
*/
"public": false
}
],
heads up: that"public"field is unstable and only shows up when-Zpublic-dependencyis on. don't go looking for it in stable output, she's shy π
and then the targets array, which is basically the receipts for every single thing Cargo knows how to build π₯:
/* 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.
For lib targets, dashes will be replaced with underscores.
*/
"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
}
],
the way that required-features just doesn't exist if you didn't set anyβ¦ absent, not empty. noted, moving on π
next up: features, manifest path, metadata, publish, and honestly the whole "who am I as a person" section of the package β authors, categories, keywords, all the links, the edition, the whole glow-up π¦:
/* 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 <user@example.com>"
],
/* Array of categories from the manifest. */
"categories": [
"command-line-utilities"
],
/* Optional string that is the default binary picked by cargo run. */
"default_run": null,
/* Optional string that is the minimum supported rust version */
"rust_version": "1.56",
/* Array of keywords from the manifest. */
"keywords": [
"cli"
],
/* The readme value from the manifest or null if not specified. */
"readme": "README.md",
/* The repository value from the manifest or null if not specified. */
"repository": "https://github.com/rust-lang/cargo",
/* The homepage value from the manifest or null if not specified. */
"homepage": "https://rust-lang.org",
/* The documentation value from the manifest or null if not specified. */
"documentation": "https://doc.rust-lang.org/stable/std",
/* The default edition of the package.
Note that individual targets may have different editions.
*/
"edition": "2018",
/* Optional string that is the name of a native library the package
is linking to.
*/
"links": null,
}
],
read the publish line twice: null means publishing is unrestricted, and an empty array means publishing is forbidden. two completely different vibes, do not confuse them π
and now the workspace-level stuff plus resolve, aka the whole dependency graph, which is only there if you didn't ask for --no-deps π:
/* Array of members of the workspace.
Each entry is the Package ID for the package.
*/
"workspace_members": [
"file:///path/to/my-package#0.1.0",
],
/* Array of default members of the workspace.
Each entry is the Package ID for the package.
*/
"workspace_default_members": [
"file:///path/to/my-package#0.1.0",
],
// The resolved dependency graph for the entire workspace. The enabled
// features are based on the enabled features for the "current" package.
// Inactivated optional dependencies are not listed.
//
// This is null if --no-deps is specified.
//
// By default, this includes all dependencies for all target platforms.
// The `--filter-platform` flag may be used to narrow to a specific
// target triple.
"resolve": {
/* Array of nodes within the dependency graph.
Each node is a package.
*/
"nodes": [
{
/* The Package ID of this node. */
"id": "file:///path/to/my-package#0.1.0",
/* The dependencies of this package, an array of Package IDs. */
"dependencies": [
"https://github.com/rust-lang/crates.io-index#bitflags@1.0.4"
],
/* The dependencies of this package. This is an alternative to
"dependencies" which contains additional information. In
particular, this handles renamed dependencies.
*/
"deps": [
{
/* The name of the dependency's library target.
If this is a renamed dependency, this is the new
name.
*/
"name": "bitflags",
/* The Package ID of the dependency. */
"pkg": "https://github.com/rust-lang/crates.io-index#bitflags@1.0.4"
/* Array of dependency kinds. Added in Cargo 1.40. */
"dep_kinds": [
{
/* The dependency kind.
"dev", "build", or null for a normal dependency.
*/
"kind": null,
/* The target platform for the dependency.
null if not a target dependency.
*/
"target": "cfg(windows)"
}
]
}
],
/* Array of features enabled on this package. */
"features": [
"default"
]
}
],
/* The package in the current working directory (if --manifest-path is not given).
This is null if there is a virtual workspace. Otherwise it is
the Package ID of the package.
*/
"root": "file:///path/to/my-package#0.1.0",
},
/* The absolute path to the target directory where Cargo places its output. */
"target_directory": "/path/to/my-package/target",
/* The absolute path to the build directory where Cargo places intermediate build artifacts. (unstable) */
"build_directory": "/path/to/my-package/build-dir",
/* The version of the schema for this metadata structure.
This will be changed if incompatible changes are ever made.
*/
"version": 1,
/* The absolute path to the root of the workspace. */
"workspace_root": "/path/to/my-package"
/* Workspace metadata.
This is null if no metadata is specified. */
"metadata": {
"docs": {
"rs": {
"all-features": true
}
}
}
}
π Notes:
- For
"id"field syntax, see Package ID Specifications at https://doc.rust-lang.org/cargo/reference/pkgid-spec.html in the reference.
β¨ OPTIONS β¨
ποΈ Output Options
--no-depsβ bestie, this one's for when you only care about your stuff. It outputs info about the workspace members and nothing else, and it doesn't fetch dependencies at all. No network drama, no waiting π--format-versionversion β tells Cargo which version of the output format you want. Right now,1is literally the only value that exists. That's it, that's the whole menu π--filter-platformtriple β this filters the resolve output so it only includes deps for the given target triple (https://doc.rust-lang.org/cargo/appendix/glossary.html#target). Skip this flag and the resolve just includes all targets, no filter, no mercy.
β οΈ heads up: the dependencies listed in the"packages"array still include all dependencies regardless. Each package definition is meant to be an unaltered reproduction of the info insideCargo.toml. So don't come for that array expecting it to be filtered, ok? π
πΈ Feature Selection
The feature flags are how you control which features get enabled. And here's the default behavior, no cap: when you give no feature options at all, the default feature is activated for every selected package β¨
For the whole story, see the features documentation at https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options.
-Ffeatures,--featuresfeatures β a space or comma separated list of features to activate. You can also enable features of workspace members usingpackage-name/feature-namesyntax π«Ά And yes, this flag may be specified multiple times β do that and all the specified features get enabled. Stack 'em.--all-featuresβ activate all available features of all selected packages. Go big or go home, main character energy π--no-default-featuresβ do not activate the default feature of the selected packages. Sometimes you just wanna opt out, and that's valid πΈ
π Display Options
-v,--verboseβ verbose output. You can specify it twice for "very verbose" output, which throws in extra stuff like dependency warnings and build script output π₯ It may also be set with theterm.verboseconfig value at https://doc.rust-lang.org/cargo/reference/config.html.-q,--quietβ do not print cargo log messages. Silence, but make it chic β¨ May also be set with theterm.quietconfig value at https://doc.rust-lang.org/cargo/reference/config.html.--colorwhen β controls when colored output gets used. Valid values, bestie:auto(default): automatically detect if color support is available on the terminal πalways: always display colors, always, periodt πnever: never display colors, plain and simple
May also be set with the term.color config value at https://doc.rust-lang.org/cargo/reference/config.html.
π Manifest Options
--manifest-pathpath β the path to theCargo.tomlfile. By default, Cargo goes searching for theCargo.tomlfile in the current directory or any parent directory. It'll find it, it always does π--lockedβ this one asserts that the exact same dependencies and versions get used as when the existingCargo.lockfile was originally generated. Cargo will exit with an error when either of these scenarios pops up:- The lock file is missing π
- Cargo attempted to change the lock file because of a different dependency resolution
Use it wherever you want deterministic builds, like in CI pipelines. Consistency is the vibe π
--offlineβ prevents Cargo from accessing the network for any reason. Without this flag, Cargo stops with an error if it needs the network and the network isn't there. With this flag, Cargo will try to proceed without the network if it possibly can π¦
β οΈ beware, bestie: this may result in different dependency resolution than online mode. Cargo restricts 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. Plan ahead π
May also be set with the net.offline config value at https://doc.rust-lang.org/cargo/reference/config.html.
--frozenβ equivalent to specifying both--lockedand--offline. Two-for-one, iconic combo π--lockfile-pathPATH β changes the path of the lockfile from the default (<workspace_root>/Cargo.lock) to PATH. PATH must end withCargo.lock(e.g.--lockfile-path /tmp/temporary-lockfile/Cargo.lock). Note that providing--lockfile-pathwill ignore the existing lockfile at the default path, and instead will either use the lockfile from PATH, or write a new lockfile into the provided PATH if it doesn't exist. This flag can be used to run most commands in read-only directories, writing the lockfile into the provided PATH π§
β οΈ this option is only available on the nightly channel (https://doc.rust-lang.org/book/appendix-07-nightly-rust.html) and requires the -Z unstable-options flag to enable (see #14421 at https://github.com/rust-lang/cargo/issues/14421).
π« Common Options
+toolchainβ if Cargo was installed with rustup, and the first argument tocargobegins with+, it gets interpreted as a rustup toolchain name (like+stableor+nightly) π οΈ See the rustup documentation at https://rust-lang.github.io/rustup/overrides.html for more info on how toolchain overrides work.--configKEY=VALUE or PATH β overrides a Cargo configuration value. The argument should be in TOML syntax ofKEY=VALUE, or given as a path to an extra configuration file. This flag may be specified multiple times π See the command-line overrides section at https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides for more.-CPATH β changes the current working directory before executing any specified operations. This affects things like where cargo looks by default for the project manifest (Cargo.toml), and also the directories searched when discovering.cargo/config.toml, for example. This option must appear before the command name, like:
cargo -C path/to/my-project build
β οΈ this option is only available on the nightly channel (https://doc.rust-lang.org/book/appendix-07-nightly-rust.html) and requires the -Z unstable-options flag to enable (see #10098 at https://github.com/rust-lang/cargo/issues/10098).
-h,--helpβ prints help information. When in doubt, ask for help, always valid π-Zflag β unstable (nightly-only) flags to Cargo. Runcargo -Z helpfor details. The forbidden knowledge zone π
π ENVIRONMENT π
See the reference at https://doc.rust-lang.org/cargo/reference/environment-variables.html for details on environment variables that Cargo reads. Yes, Cargo reads them. Yes, you should go look π±
π¦ EXIT STATUS π¦
0: Cargo succeeded π slay101: 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 β https://doc.rust-lang.org/cargo/reference/pkgid-spec.html
- JSON messages β https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages
and that's the whole page, bestie!! you made it to the bottom of the Cargo manual's CARGO-METADATA(1) page π go forth and read your workspace's metadata like the absolute icon you are β¨ ππ¦π
π¦ where this page comes from
- ubuntu resolute: cargo-1.92 1.92.0+dfsg-0ubuntu2 Β· MIT OR Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms