CARGO-METADATA(1)
cargo-metadata(1) — fresh out of the General Commands Manual ✨
okay bestie, this one is lowkey iconic and highkey underrated, so let's get into it 🫶
💖 NAME 💖
cargo-metadata — machine-readable metadata about the current package 💅
like… it's your package, but as ✨data✨. no vibes, no prose, just facts in a shape a computer can actually chew on. periodt.
📜 SYNOPSIS 📜
cargo metadata [options]
🌸 DESCRIPTION 🌸
so what does it do? it writes JSON to stdout containing everything about the workspace members and the resolved dependencies of the current package. that's the whole job. it does the job. 💖
now listen — the output format is subject to change in future versions of Cargo 😭 so it is recommended that you include the --format-version flag, which future-proofs your code and makes sure the output is in the format you're actually expecting. for more on the expectations, go read "Compatibility" below. iykyk. 👀
also, if you're a Rust girlie and you'd rather have an actual API for reading the metadata instead of parsing JSON yourself, there's the cargo_metadata crate: https://crates.io/crates/cargo_metadata. slay. 🦋
📦 OUTPUT FORMAT 📦
🤝 Compatibility 🤝
within the same output format version, compatibility is maintained — except in some scenarios. and here is a non-exhaustive list of changes that are not considered incompatible, bestie:
- Adding new fields — new fields get added whenever they're needed. reserving this helps Cargo evolve without bumping the format version too often. 🎀
- Adding new values for enum-like fields — same energy as adding new fields. it keeps the metadata evolving without stagnation. 💫
- Changing opaque representations — the inner representations of some fields are literally 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 it's specified. no cap. 🙈
🧾 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"
and yeah that's only the beginning of the shape of it 👀 there's so much more metadata where that came from, so keep scrolling bestie, we are SO not done —
/* the value after that +? bestie, it's not explicitly defined, and 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 get 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 / "name": "bitflags", / the source ID of the dependency. May be null — peep the description for the package source. / "source": "registry+https://github.com/rust-lang/crates.io-index", / the version requirement for the dependency. Dependencies with no version requirement get 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 public dependency. This field is only present when -Zpublic-dependency is enabled. / "public": false } ], / 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 get 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 this package may be published to. Publishing is unrestricted if null, and forbidden if it's 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 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 📝:
- For `"id"` field syntax, check out Package ID Specifications <https://doc.rust-lang.org/cargo/reference/pkgid-spec.html> in the reference.
---
# 💅 OPTIONS 💅
## ✨ Output Options ✨
- **`--no-deps`** — only spill the info about the workspace members, okay? It does <red>not</red> fetch dependencies. Periodt.
- **`--format-version`** *version* — pick the version of the output format you want. RN `1` is literally the only possible value. Iconic but limited, we love that for us.
- **`--filter-platform`** *triple* — this filters the resolve output so it only includes dependencies for the given target triple <https://doc.rust-lang.org/cargo/appendix/glossary.html#target>. You can pass the literal `"host-tuple"`, 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`. No cap.
## 🌸 Feature Selection 🌸
The feature flags let you control which features are enabled. When no feature options are given, the default feature is activated for every selected package.
See the features documentation <https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options> for more details.
- **`-F`** *features*, **`--features`** *features* — space or comma separated list of features to activate. Features of workspace members may be enabled with `package-name/feature-name` syntax. This flag may be specified multiple times, which enables all specified features. Slay.
- **`--all-features`** — activate all available features of all selected packages. Go off, queen.
- **`--no-default-features`** — do not activate the default feature of the selected packages. Sometimes you gotta say no, and that’s valid.
## 🎀 Display Options 🎀
- **`-v`**, **`--verbose`** — use 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.verbose` config value <https://doc.rust-lang.org/cargo/reference/config.html>.
- **`-q`**, **`--quiet`** — do not print cargo log messages. May also be specified with the `term.quiet` config value <https://doc.rust-lang.org/cargo/reference/config.html>.
- **`--color`** *when* — control 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.color` config value <https://doc.rust-lang.org/cargo/reference/config.html>.
## 📦 Manifest Options 📦
- **`--manifest-path`** *path* — path to the `Cargo.toml` file. By default, Cargo searches for the `Cargo.toml` file in the current directory or any parent directory.
- **`--locked`** — asserts that the exact same dependencies and versions are used as when the existing `Cargo.lock` file 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. Very demure, very mindful.
- **`--offline`** — prevents 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.offline` config value <https://doc.rust-lang.org/cargo/reference/config.html>.
- **`--frozen`** — equivalent to specifying both `--locked` and `--offline`. Two moods, one flag.
## 💖 Common Options 💖
- **`+toolchain`** — if Cargo has been installed with rustup, and the first argument to cargo begins with `+`, it will be interpreted as a rustup toolchain name (such as `+stable` or `+nightly`). See the rustup documentation <https://rust-lang.github.io/rustup/overrides.html> for more information about how toolchain overrides work.
- **`--config`** *KEY=VALUE* or *PATH* — overrides 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 <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides> for more information.
- **`-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`), as well as the directories searched for discovering `.cargo/config.toml`, for example. This option must appear before the command name, for example `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 <https://github.com/rust-lang/cargo/issues/10098>). Nightly girlies, this one’s for you.
- **`-h`**, **`--help`** — prints help information. The ultimate “bestie, explain”.
- **`-Z`** *flag* — unstable (nightly-only) flags to Cargo. Run `cargo -Z help` for details.
---
# 🌈 ENVIRONMENT 🌈
See the reference <https://doc.rust-lang.org/cargo/reference/environment-variables.html> for details on environment variables that Cargo reads.
---
# 💀 EXIT STATUS 💀
- `0`: Cargo succeeded. We love a happy ending.
- `101`: Cargo failed to complete. It’s giving “it’s not me, it’s the build”.
---
# ✨ EXAMPLES ✨
1. 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 CARGO-METADATA(1) page, bestie — source/version/date as your man page footer says, so check that exact stamp if you need it. You ate this, fr fr. 💅✨
📦 where this page comes from
- alpine 3.24: cargo-doc 1.96.1-r0 · Apache-2.0 OR MIT
- alpine 3.24: chromium-cargo-doc 1.97.0-r0 · Apache-2.0 OR MIT
- centos-stream 10: cargo 1.99.1-1.el10 · (Apache-2.0 OR MIT) AND (Artistic-2.0 AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0 AND Unicode-3.0)
- centos-stream 9: cargo 1.99.1-1.el9 · (Apache-2.0 OR MIT) AND (Artistic-2.0 AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0 AND Unicode-3.0)
- debian bookworm: cargo-web 1.96.0+dfsg1-1~deb12u2 · MIT OR Apache-2.0
- debian trixie: cargo-web 1.96.0+dfsg1-1~deb13u1+b1 · MIT OR Apache-2.0
- fedora 43: cargo 1.98.1-1.fc43
- fedora 43: cargo 1.99.0-1.fc43
- fedora 43: cargo 1.99.1-2.fc43 · (Apache-2.0 OR MIT) AND (Artistic-2.0 AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0 AND Unicode-3.0)
- fedora 44: cargo 1.94.1-1.fc44 · (Apache-2.0 OR MIT) AND (Artistic-2.0 AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0 AND Unicode-3.0)
- fedora 44: cargo 1.98.1-1.fc44
- fedora 44: cargo 1.99.0-1.fc44
- fedora 44: cargo 1.99.1-2.fc44 · (Apache-2.0 OR MIT) AND (Artistic-2.0 AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0 AND Unicode-3.0)
- nixos 26.05: cargo 1.95.0
- opensuse-leap 16.0: cargo1.94 1.94.1-160000.1.1 · Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.94 1.94.1-160000.1.1 · Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.94 1.94.1-160000.1.1 · Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.94 1.94.1-160000.1.1 · Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.95 1.95.0-160000.1.1 · Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.95 1.95.0-160000.1.1 · Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.95 1.95.0-160000.1.1 · Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.95 1.95.0-160000.1.1 · Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.96 1.96.1-160000.1.1 · Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.96 1.96.1-160000.1.1 · Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.96 1.96.1-160000.1.1 · Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.96 1.96.1-160000.1.1 · Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.97 1.97.0-160000.1.1 · Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.97 1.97.0-160000.1.1 · Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.97 1.97.0-160000.1.1 · Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.97 1.97.0-160000.1.1 · Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.98 1.98.0-160000.1.1 · Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.98 1.98.0-160000.1.1 · Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.98 1.98.0-160000.1.1 · Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.98 1.98.0-160000.1.1 · Apache-2.0 OR MIT
- 💖 girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms