CARGO-METADATA(1)
π¦ CARGO-METADATA(1) β General Commands Manual, but make it cute
okay bestie, welcome to the cargo-metadata manual page π this is the machine-readable one, the one that speaks JSON, and it's lowkey iconic for tooling.
β¨ NAME β¨
cargo-metadata β Machine-readable metadata about the current package
β¨ SYNOPSIS β¨
cargo metadata [options]
β¨ DESCRIPTION β¨
So basically, this command dumps JSON to stdout with all the info about your workspace members and the resolved dependencies of the current package. It's giving "let the robots read it" energy π€β¨
Heads up bestie: the format of that output is subject to change in future versions of Cargo. So the recommendation is to pass the --format-version flag to future-proof your code and make sure you get the output in the format you're expecting. For more on what you can expect, see βCompatibilityβ below.
There's also a Rust API for reading the metadata, the cargo_metadata crate, living at https://crates.io/crates/cargo_metadata π¦
π OUTPUT FORMAT π
π Compatibility π
Within the same output format version, compatibility is maintained β except in some scenarios. The following is a non-exhaustive list of changes that are not considered 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 this format, and yes we're showing you the whole thing:
{
/* 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 and that's where part 1 ends bestie, the JSON block literally keeps going β more parts coming, don't go anywhere π«Ά
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-typevalues 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-typevalues 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 } ], / 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, } ], / 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-platformflag 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 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": "file:///path/to/my-package#0.1.0",
},
/* 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
}
}
}
}
okay so quick notes before we move on π
- For the
"id"field syntax, you gotta go read Package ID Specifications <https://doc.rust-lang.org/cargo/reference/pkgid-spec.html> over in the reference. That's where the lore lives, bestie.
β¨ OPTIONS β¨
π Output Options
--no-depsβ only spits out info about your workspace members, and does not fetch dependencies. Keep it local, keep it cozy.--format-version versionβ tells Cargo which version of the output format you want. Right now1is the only possible value. That's it. That's the whole menu. π--filter-platform tripleβ 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 is just likeβ¦ every target, all at once, no filter, no chill.
heads up though: the dependencies listed in the "packages" array still include all dependencies. Each package definition is meant to be an unaltered reproduction of the info inside Cargo.toml. So like, don't get it twisted β the filter hits the resolve, not the packages. π
πΈ Feature Selection
The feature flags are your remote control for which features get enabled. When you give no feature options at all, the default feature gets activated for every selected package. periodt.
More deets in the features documentation <https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options> if you want the full tea.
-F features,--features featuresβ a space or comma separated list of features to activate. Features of workspace members can be enabled withpackage-name/feature-namesyntax. And you can pass this flag multiple times, which enables all the specified features. stacking privileges, love that for you β¨--all-featuresβ activates every available feature of all selected packages. all of them. the whole buffet. π--no-default-featuresβ do not activate the default feature of the selected packages. we're going rogue, we're customising. π
π Display Options
-v,--verboseβ use verbose output. You can pass it twice for "very verbose" output, which throws in extra stuff like dependency warnings and build script output. May also be specified with theterm.verboseconfig value <https://doc.rust-lang.org/cargo/reference/config.html>.-q,--quietβ do not print cargo log messages. May also be specified with theterm.quietconfig value <https://doc.rust-lang.org/cargo/reference/config.html>. shhh, silence, we're being mysterious π§--color whenβ controls when colored output is used. valid values are:auto(default): automatically detects whether the terminal supports color. let it read the room.always: always display colors. full rainbow, no apologies.never: never display colors. greyscale era.
May also be specified with the term.color config value <https://doc.rust-lang.org/cargo/reference/config.html>.
π Manifest Options
--manifest-path pathβ path to theCargo.tomlfile. By default, Cargo goes searching for theCargo.tomlfile in the current directory or any parent directory. it's giving "mom, where's my manifest" π«Ά--lockedβ asserts that the exact same dependencies and versions are used as when the existingCargo.lockfile was originally generated. Cargo will exit with an error when either of these scenarios shows up:- The lock file is missing.
- Cargo attempted to change the lock file due to a different dependency resolution.
It can be used in environments where deterministic builds are wanted, like in CI pipelines. reproducibility queen π
--offlineβ stops Cargo from accessing the network for any reason. Without this flag, Cargo will stop with an error if it needs the network and the network isn't available. With this flag, Cargo will attempt to proceed without the network if it can.
beware: this may result in a 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 <https://doc.rust-lang.org/cargo/reference/config.html>.
--frozenβ equivalent to specifying both--lockedand--offline. two-for-one special, iconic.
β Common Options
+toolchainβ if Cargo has been installed with rustup, and the first argument to cargo begins with+, it'll be interpreted as a rustup toolchain name (like+stableor+nightly). See the rustup documentation <https://rust-lang.github.io/rustup/overrides.html> for more info on how toolchain overrides work.--config KEY=VALUE or PATHβ overrides a Cargo configuration value. The argument should be in TOML syntax ofKEY=VALUE, or provided as a path to an extra configuration file. This flag may be specified multiple times. See the command-line overrides section <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides> for more info.-C PATHβ 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), as well as the directories searched for discovering.cargo/config.toml, for example. This option has to appear before the command name, likecargo -C path/to/my-project build.
okay so this one is only available on the nightly channel <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and it requires the -Z unstable-options flag to enable (see #10098 <https://github.com/rust-lang/cargo/issues/10098>). bleeding edge behaviour, handle with care π
-h,--helpβ prints help information. your bestie when you're lost.-Z flagβ unstable (nightly-only) flags to Cargo. Runcargo -Z helpfor details. the forbidden zone, only for the brave π¦
π± ENVIRONMENT
See the reference <https://doc.rust-lang.org/cargo/reference/environment-variables.html> for details on the environment variables that Cargo reads. it reads them. it knows things. π
π EXIT STATUS
0: Cargo succeeded. slay!! β¨101: Cargo failed to complete. it's not you, it's the build π
π 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 π this one's CARGO-METADATA(1) from the Cargo source and docs, dated 2025-01-16 (or whatever date your local copy of the source was built from β check your SOURCE/version line, iykyk). go forth and pipe JSON into jq, you absolute icon π
π¦ where this page comes from
- ubuntu jammy: cargo-1.80 1.80.1+dfsg0ubuntu1~bpo0-0ubuntu0.22.04.1 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.80 1.80.1+dfsg0ubuntu1-0ubuntu0.24.04.01 Β· 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