CARGO-METADATA(1)
๐ cargo-metadata โ bestie edition ๐
okay so <rainbow>cargo-metadata</rainbow> โ it's the Cargo subcommand that spits out machine-readable metadata about the current package. that's it, that's the whole vibe. โจ
๐ธ NAME ๐ธ
cargo-metadata โ machine-readable metadata about the current package ๐ซถ
โญ SYNOPSIS โญ
cargo metadata [options]
๐ DESCRIPTION ๐
so what it does is: it outputs JSON to stdout stuffed with info about the workspace members and the resolved dependencies of the current package. no cap, that's the whole thing. ๐
โ ๏ธ okay listen โ the format of that output is subject to change in futures versions of Cargo. fr fr. so it's highly recommended you pass the --format-version flag to future-proof your code, so you actually get the output in the format you're expecting. for more on what to expect, go read "Compatibility" below. ๐
also, if you're a Rust girlie and want an actual API for reading the metadata instead of vibing with raw JSON, there's the cargo_metadata crate <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 are NOT considered incompatible, so don't come for us: ๐
- Adding new fields โ new fields get added whenever they're needed. reserving this lets Cargo evolve without bumping the format version too often. iconic behavior tbh.
- Adding new values for enum-like fields โ same energy as adding new fields. it keeps metadata evolving without stagnation. growth mindset ๐
- Changing opaque representations โ the inner representations of some fields are literally implementation details. for example, fields related to "Package ID" or "Source ID" are treated as opaque identifiers to differentiate packages or sources. so consumers shouldn't rely on those representations unless it's specified. periodt. ๐
๐ฆ 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, an opaque and unique identifier for referring to the
package. See "Compatibility" above for the stability guarantee.
*/
"id": "my-package 0.1.0 (path+file:///path/to/my-package)",
/* 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 `+`? bestie it is NOT explicitly defined ๐ญ it may
change between versions of Cargo, and it may not directly correlate to
other things, like registry definitions in a config file. new source
kinds may be added in the future, and those will have different `+`
prefixed identifiers.
*/
"source": null,
/* array of dependencies declared in the package's manifest. */
"dependencies": [
{
/* the name of the dependency. that's it. that's the field. */
"name": "bitflags",
/* the source ID of the dependency. it may be null, so go read the
description for the package source up above, ok?
*/
"source": "registry+https://github.com/rust-lang/crates.io-index",
/* the version requirement for the dependency.
dependencies with no version requirement just 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
}
],
โจ okay that was the deps, slay. now the targets, and this is where it gets cute:
/* array of Cargo targets. */
"targets": [
{
/* array of target kinds. okay so:
- 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
}
],
๐ฆ and then the package-level lore โ features, metadata, publish, the whole personality section:
/* 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,
}
],
and now we get to the workspace tea ๐
/* array of members of the workspace.
each entry is the Package ID for the package.
*/
"workspace_members": [
"my-package 0.1.0 (path+file:///path/to/my-package)",
],
/* array of default members of the workspace.
each entry is the Package ID for the package.
*/
"workspace_default_members": [
"my-package 0.1.0 (path+file:///path/to/my-package)",
],
// 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": "my-package 0.1.0 (path+file:///path/to/my-package)",
/* the dependencies of this package, an array of Package IDs. */
"dependencies": [
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)"
],
/* 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": "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
/* array of dependency kinds. added in Cargo 1.40. */
"dep_kinds": [
{
/* the dependency kind.
"dev", "build", or null for a normal dependency.
โฆand here's the rest of that JSON, bestie, all the way to the closing brace:
*/
"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 root package of the workspace.
This is null if this is a virtual workspace. Otherwise it is
the Package ID of the root package.
*/
"root": "my-package 0.1.0 (path+file:///path/to/my-package)"
},
/* The absolute path to the build directory where Cargo places its output. */
"target_directory": "/path/to/my-package/target",
/* 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
}
}
}
}
๐ OPTIONS ๐
โจ Output Options โจ
--no-depsโ only spill the tea about your workspace members, okay? No dependency fetching, no extra drama. Just the members. ๐ซถ--format-versionversion โ pick which version of the output format you want. Right now1is literally the only valid value, so it's giving "one option only, bestie." ๐--filter-platformtriple โ this one filters the resolve output so it only includes deps for the target triple you name (https://doc.rust-lang.org/cargo/appendix/glossary.html#target). Skip this flag and the resolve just includes all the targets, no filter, no chill.
heads up bestie ๐จ the dependencies listed in the"packages"array still include all dependencies regardless. Every package definition is meant to be an unaltered reproduction of the info insideCargo.tomlโ no edits, no touch-ups, periodt.
๐ Feature Selection ๐
The feature flags let you control which features get enabled. When you give no feature options at all, the default feature gets activated for every selected package. That's the vibe.
For the whole lore, 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. Features of workspace members can be switched on with thepackage-name/feature-namesyntax. And yes, you can pass this flag multiple times โ every specified feature gets enabled. โจ--all-featuresโ activate all the available features of all selected packages. Go feral. ๐--no-default-featuresโ do NOT activate the default feature of the selected packages. Sometimes we're in our minimalist era. ๐ธ
๐ฆ Display Options ๐ฆ
-v,--verboseโ verbose output. Pass it twice and you get "very verbose" output, which includes extra stuff like dependency warnings and build script output. You can also set it with theterm.verboseconfig value (https://doc.rust-lang.org/cargo/reference/config.html).-q,--quietโ do not print cargo log messages. Also settable with theterm.quietconfig value (https://doc.rust-lang.org/cargo/reference/config.html). Silent mode, main character energy. ๐คซ--colorwhen โ controls when colored output is used. Valid values, bestie:auto(the default): automatically detect if the terminal supports color. ๐always: always display colors. ๐never: never display colors. ๐
Can also be set with the term.color config value (https://doc.rust-lang.org/cargo/reference/config.html).
๐ธ Manifest Options ๐ธ
--manifest-pathpath โ the path to theCargo.tomlfile. By default Cargo goes hunting forCargo.tomlin the current directory or any parent directory. It's giving "I'll find it, don't worry." ๐--frozen,--lockedโ either one of these flags requires that theCargo.lockfile is up-to-date. If the lock file is missing, or it needs updating, Cargo will exit with an error. The--frozenflag also stops Cargo from even attempting to access the network to figure out if it's out-of-date.
Use these in environments where you wanna assert that Cargo.lock is up-to-date (like a CI build, slay) or where you wanna avoid network access entirely. ๐ก๏ธ
--offlineโ prevents Cargo from accessing the network for any reason whatsoever. Without this flag, Cargo just stops with an error if it needs the network and the network isn't there. With this flag, Cargo will attempt 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. Check out the cargo-fetch(1) command to download dependencies before you go offline. ๐ง
Can also be set with the net.offline config value (https://doc.rust-lang.org/cargo/reference/config.html).
๐ Common Options ๐
+toolchain โ if Cargo was installed with rustup, and the first argument tocargostarts with+, it gets interpreted as a rustup toolchain name (like+stableor+nightly). See the rustup documentation athttps://rust-lang.github.io/rustup/overrides.htmlfor more 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 athttps://doc.rust-lang.org/cargo/reference/config.html#command-line-overridesfor more. ๐-CPATH โ changes the current working directory before executing any specified operations. This affects stuff like where cargo looks by default for the project manifest (Cargo.toml), and also the directories it searches for discovering.cargo/config.toml, for example. This option has to appear before the command name, likecargo -C path/to/my-project build.
ngl this option is only available on the nightly channel (https://doc.rust-lang.org/book/appendix-07-nightly-rust.html) and it requires the-Z unstable-optionsflag to enable (see #10098 athttps://github.com/rust-lang/cargo/issues/10098). ๐ง
-h,--helpโ prints help information. The classic. ๐ซถ-Zflag โ unstable (nightly-only) flags to Cargo. Runcargo -Z helpfor the details. ๐ฎ
๐ ENVIRONMENT ๐
See the reference at https://doc.rust-lang.org/cargo/reference/environment-variables.html for the details on environment variables that Cargo reads. iykyk ๐
โญ EXIT STATUS โญ
0: Cargo succeeded. ๐ ate, no crumbs.101: Cargo failed to complete. ๐ญ it's giving tragedy.
๐ฅ EXAMPLES ๐ฅ
- Output JSON about the current package:
cargo metadata --format-version=1
๐ SEE ALSO ๐
okay that's the whole page bestie, we did it ๐ that footer at the bottom? it's just CARGO-METADATA(1) โ the Cargo manual, this very page, no cap. go forth and pipe JSON into things. ๐โจ๐ฆ
๐ฆ where this page comes from
- ubuntu jammy: cargo-1.76 1.76.0+dfsg0ubuntu1~bpo0-0ubuntu0.22.04.1 ยท Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.76 1.76.0+dfsg0ubuntu1-0ubuntu0.24.04.2 ยท 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