CARGO-PKGID(1)
β¨ CARGO-PKGID(1) β¨
okay bestie, welcome to the cargo-pkgid page π this one lives in Cargo's General Commands Manual and honestly? it's giving "small command, huge main character energy." Let's get into it.
πΈ NAME πΈ
cargo-pkgid β print a fully qualified package specification. That's it, that's the job, and it slays at it. π
π SYNOPSIS π
cargo pkgid [options] [spec]
π¦ DESCRIPTION π¦
So here's the vibe: you hand it a spec argument, and it prints out the fully qualified package ID specifier for a package or dependency in the current workspace. Iconic. β¨
But heads up β if spec is ambiguous about which package it's referring to in the dependency graph, this command will straight up error out. No guessing games, no vibes-based resolution. π
And if you don't give it a spec at all? Then it just prints the specifier for the local package. Chill. Easy. Done.
Also, lowkey important: this command requires that a lockfile is available and that dependencies have been fetched. No lockfile, no pkgid. Periodt.
A package specifier is made of three things: a name, a version, and a source URL. The cute part is you're allowed to use partial specifiers to succinctly match a specific package β as long as it matches exactly one package. Only one, bestie. That's the rule. π«Ά
This same specifier format is also used by other parts in Cargo, like cargo-metadata(1) and the JSON messages emitted by Cargo (https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages).
The format of a spec can be one of the following:
nameβ e.g.bitflagsname@versionβ e.g.bitflags@1.0.4urlβ e.g.https://github.com/rust-lang/cargourl#versionβ e.g.https://github.com/rust-lang/cargo#0.33.0url#nameβ e.g.https://github.com/rust-lang/crates.io-index#bitflagsurl#name@versionβ e.g.https://github.com/rust-lang/cargo#crates-io@0.21.0
The specification grammar can be found in chapter Package ID Specifications: https://doc.rust-lang.org/cargo/reference/pkgid-spec.html
π OPTIONS π
π Package Selection
-pspec,--packagespec β get the package ID for the given package instead of the current package. Like, "not this one, that one." π―
π Display Options
-v,--verboseβ use verbose output. You can specify it twice for "very verbose" output, which includes extra output such as 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).--colorwhen β 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-pathpath β path to theCargo.tomlfile. By default, Cargo searches for theCargo.tomlfile in the current directory or any parent directory. It's like a little scavenger hunt, ngl. π--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 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. Determinism girlies, this one's for you. π
--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--lockedand--offline. Two flags in a trench coat. π§₯--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 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 https://github.com/rust-lang/cargo/issues/14421).
πΈ Common Options
+toolchain β if Cargo has been installed with rustup, and the first argument tocargobegins with+, it will be interpreted as a rustup toolchain name (such as+stableor+nightly). See the rustup documentation (https://rust-lang.github.io/rustup/overrides.html) for more information about how toolchain overrides work.--configKEY=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 information.-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), as well as the directories searched for discovering.cargo/config.toml, for example. This option must appear before the command name, for examplecargo -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).
-h,--helpβ prints help information. π«Ά-Zflag β unstable (nightly-only) flags to Cargo. Runcargo -Z helpfor details.
π§ ENVIRONMENT π§
See the reference (https://doc.rust-lang.org/cargo/reference/environment-variables.html) for details on environment variables that Cargo reads. Yes, it's a link. Go read it, bestie, I believe in you. π
β EXIT STATUS β
0: Cargo succeeded. π101: Cargo failed to complete. π
π₯ EXAMPLES π₯
- Retrieve package specification for
foopackage:
cargo pkgid foo
- Retrieve package specification for version 1.0.0 of
foo:
cargo pkgid foo@1.0.0
- Retrieve package specification for
foofrom crates.io:
cargo pkgid https://github.com/rust-lang/crates.io-index#foo
- Retrieve package specification for
foofrom a local package:
cargo pkgid file:///path/to/local/package#foo
π¦ SEE ALSO π¦
cargo(1), cargo-generate-lockfile(1), cargo-metadata(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, we ate and left no crumbs π
β¨ this was CARGO-PKGID(1) from Cargo's General Commands Manual β go forth and print fully qualified package specs, you've got this π«Άππ
π¦ 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