CARGO-METADATA(1)
π cargo-metadata β bestie edition π
okay so. the manual page is CARGO-METADATA(1) and it lives in the General Commands Manual section, and honestly? it's the one that spills ALL the tea about your package. let's get into it. β¨
πΈ NAME πΈ
cargo-metadata β machine-readable metadata about the current package. that's it. that's the whole vibe. it's giving "tell me everything, but in JSON so my code can read it". π
π¦ SYNOPSIS π¦
cargo metadata [options]
literally that simple, no cap. just cargo metadata plus whatever [options] you're feeling. π
β¨ 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. like, everything your tooling could possibly want to know, in one big pretty blob. π
IMPORTANT bestie moment: the output format is subject to change in future versions of Cargo. so it is recommended that you include the --format-version flag, to future-proof your code and make sure you're getting the format you're actually expecting. do it. protect your peace. π«Ά for more on what "expecting" even means here, go read "Compatibility" (it's further down, don't worry, i got you).
also, if you're a Rust girly and you want an actual API for reading the metadata instead of hand-parsing JSON like a gremlin, there's the cargo_metadata crate at <https://crates.io/crates/cargo_metadata> π (it's a link in the original page, i'm just telling you where it points, iykyk).
π OUTPUT FORMAT π
π Compatibility π
so within the same output format version, compatibility is maintained β EXCEPT in some scenarios. and the list of things that are not considered incompatible is non-exhaustive, meaning there's more where this came from. here's what the page gives us:
- Adding new fields β new fields get added when they're needed. reserving the right to do this is what helps Cargo evolve without bumping the format version every five minutes. β¨
- Adding new values for enum-like fields β same energy as adding new fields. it keeps the metadata evolving instead of stagnating. growth mindset fr fr. π±
- Changing opaque representations β okay so the inner representations of some fields are implementation details. for example, fields related to "Source ID" are treated as opaque identifiers, just there to tell packages or sources apart. so consumers shouldn't rely on those representations unless it's actually specified. don't be nosy about the internals, bestie, it's not your business. π
π¦ JSON format π¦
the JSON output looks like this, and yes it has comments in it, and yes that's just for you, the JSON itself doesn't ship comments, calm down:
{
/* 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,
/* (unstable) Boolean flag of whether or not this is a pulbic
dependency. This field is only present when
`-Zpublic-dependency` is enabled.
*/
"public": false
}
],
okay bestie, one dependencies entry, fully dissected π each dep rolls with name, source (can be null β the package-source description up top explains what that means), req (and if there's no version requirement at all it's just "*"), kind ("dev", "build", or null for a normal dep), rename (the new name if it got renamed, null if not), optional, uses_default_features, features, target (null when it's not a target dependency), path (only shows up for local path deps), and registry (unspecified or null = default registry, i.e. crates.io). And then there's public, which is (unstable) and only appears when -Zpublic-dependency is on. π
/* 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 targets era β¨ kind is an array of target kinds β lib targets list the crate-type values from the manifest like "lib", "rlib", "dylib", "proc-macro", etc. (default ["lib"]), a binary is ["bin"], an example is ["example"], an integration test is ["test"], a benchmark is ["bench"], and a build script is ["custom-build"]. crate_types says the same story: lib and example libraries use crate-type values, every other target kind is ["bin"]. name gets its dashes swapped for underscores if it's a lib target, src_path is absolute, edition defaults to the package edition, and required-features just straight up isn't included when you haven't set any. doc, doctest, and test are the booleans doing their little thing. π¦
/* 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 that's a whole package object, fully unfurled πΈ features maps every feature name to the array of features or dependencies it enables. manifest_path is absolute. metadata is null when you didn't write any. And publish is the one to clock: publishing is unrestricted if it's null, and forbidden if it's an empty array. Also authors is an empty array if you listed nobody, readme / repository / homepage / documentation are all null if you never specified them, default_run is the optional default binary that cargo run picks, rust_version is the optional MSRV string, and edition is the package default β individual targets can still have different editions, bestie. π
/* 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",
],
workspace o'clock π both workspace_members and workspace_default_members are arrays of Package IDs, one entry per package, no notes. And now the main event:
// 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. */
β¦and here's the rest of that JSON, bestie, picked up right where we left off, no cap π
"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, bestie, real quick:
- For
"id"field syntax, go look at Package ID Specifications over athttps://doc.rust-lang.org/cargo/reference/pkgid-spec.htmlin the reference. π
β¨ OPTIONS β¨
π Output Options π
--no-depsβ only spills the tea about your workspace members, and it does not go fetch dependencies. Staying in your lane, iconic.--format-version versionβ pick which version of the output format you want. Right now1is literally the only possible value. That's it. That's the whole menu. π--filter-platform tripleβ filters the resolve output so it only includes dependencies for the target triple you named (https://doc.rust-lang.org/cargo/appendix/glossary.html#target). You can pass the literal string"host-tuple"and it gets swapped internally for the host's target. Leave the flag off and the resolve includes all the targets.- Heads up though: the dependencies listed in the
"packages"array still include everything. Each package definition is meant to be an unaltered reproduction of the info sitting insideCargo.toml. So like, don't come for that array expecting it to be filtered, bestie. π
- Heads up though: the dependencies listed in the
πΈ Feature Selection πΈ
The feature flags let you control which features are enabled. When you give no feature options at all, the default feature gets activated for every single selected package.
Want the full lore? The features documentation lives at https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options. π
-F features,--features featuresβ a space- or comma-separated list of features to activate. Features of workspace members can be turned on withpackage-name/feature-namesyntax. You can throw this flag multiple times and it enables all the features you specified.--all-featuresβ activate every available feature of all selected packages. all of them. no crumbs left. π₯--no-default-featuresβ do not activate the default feature of the selected packages. bye default, you're not invited.
π Display Options π
-v,--verboseβ verbose output. Say it twice and you get "very verbose" output, which drags in extra stuff like dependency warnings and build script output. Can also be set with theterm.verboseconfig value (https://doc.rust-lang.org/cargo/reference/config.html). π¦-q,--quietβ do not print cargo log messages. Can also be set with theterm.quietconfig value (https://doc.rust-lang.org/cargo/reference/config.html). shhh, silence era.--color whenβ controls when colored output is used. Valid values are:auto(default): auto-detects whether the terminal supports color. she checks the vibe first.always: always displays colors. πnever: never displays colors. greyscale moment.- Can also be set with the
term.colorconfig value (https://doc.rust-lang.org/cargo/reference/config.html).
π«Ά Manifest Options π«Ά
--manifest-path pathβ the path to theCargo.tomlfile. By default Cargo goes looking forCargo.tomlin the current directory, or any parent directory. it will find it, she always does. π--lockedβ asserts that the exact same dependencies and versions are used as when the existingCargo.lockfile was originally generated. Cargo bails with an error whenever either of these situations shows up:- The lock file is missing.
- Cargo attempted to change the lock file because of a different dependency resolution.
- Use this in environments where you want deterministic builds, like CI pipelines. it's giving β¨reproducibilityβ¨.
--offlineβ stops Cargo from touching the network for any reason. Without this flag, Cargo will stop with an error if it needs the network and the network isn't there. With this flag, Cargo tries to carry on without the network if it can.
Beware, bestie: this may give you a different dependency resolution than online mode. Cargo restricts itself to crates downloaded locally, even if there might be a newer version according to the local copy of the index. Go peep cargo-fetch(1) to download dependencies before you head offline. π
- Can also be set with the
net.offlineconfig value (https://doc.rust-lang.org/cargo/reference/config.html).
--frozenβ equivalent to specifying both--lockedand--offline. two-for-one, slay.--lockfile-path PATHβ changes the path of the lockfile from the default (<workspace_root>/Cargo.lock) toPATH.PATHmust end withCargo.lock(e.g.--lockfile-path /tmp/temporary-lockfile/Cargo.lock). Note that giving--lockfile-pathwill ignore any existing lockfile at the default path, and instead it'll either use the lockfile fromPATH, or write a brand new lockfile into thePATHyou provided if one doesn't exist yet. You can use this flag to run most commands in read-only directories, writing the lockfile into thePATHyou handed over. π
Nightly only, queen: 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 #14421 athttps://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). The rustup documentation athttps://rust-lang.github.io/rustup/overrides.htmlhas more 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 given as a path to an extra configuration file. This flag can be specified multiple times. See the command-line overrides section athttps://doc.rust-lang.org/cargo/reference/config.html#command-line-overridesfor more. π-C PATHβ 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), plus the directories searched for discovering.cargo/config.toml, for example. This option must appear before the command name, likecargo -C path/to/my-project build.
Nightly only, queen: 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. when in doubt, ask for help. no shame. π-Z flagβ unstable (nightly-only) flags for Cargo. Runcargo -Z helpfor the details. π
π ENVIRONMENT π
See the reference at https://doc.rust-lang.org/cargo/reference/environment-variables.html for all the details on the environment variables that Cargo reads. π
β EXIT STATUS β
0: Cargo succeeded. ate and left no crumbs. π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 β
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 end π«Ά this absolute icon of a manual page is CARGO-METADATA(1) from the Cargo docs, so go forth and cargo metadata responsibly. periodt. π
β¨
π¦ where this page comes from
- ubuntu resolute: cargo-1.93 1.93.1+dfsg-0ubuntu6 Β· 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