CARGO-PKGID(1)
β¨ CARGO-PKGID β¨
okay bestie, welcome to cargo-pkgid(1) π this one lives in the General Commands Manual and it's genuinely one of the most underrated little cargo commands. let's get into it π
π NAME π
cargo-pkgid β print a fully qualified package specification β¨
π¦ SYNOPSIS π¦
cargo pkgid [options] [spec]
that's it. that's the whole vibe. π
πΈ DESCRIPTION πΈ
so like, give it a spec argument and it prints out the fully qualified package ID specifier for a package or dependency in the current workspace π«Ά and heads up β if that spec is ambiguous about which package it means in the dependency graph, this command will throw an error. no cap. π and if you don't give it a spec at all? it just prints the specifier for the local package. easy.
β οΈ real talk: this command requires that a lockfile is available and that dependencies have already been fetched. no lockfile, no vibes.
a package specifier is made of a name, a version, and a source URL π and here's the cute part: you're allowed to use partial specifiers to succinctly match a specific package β as long as it matches only one package. only. one. π this same specifier format is also used elsewhere in Cargo, like cargo-metadata(1) and the JSON messages Cargo emits, docs at https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages.
the format of a spec can be one of these bad boys:
nameβbitflagsname@versionβbitflags@1.0.4urlβhttps://github.com/rust-lang/cargourl#versionβhttps://github.com/rust-lang/cargo#0.33.0url#nameβhttps://github.com/rust-lang/crates.io-index#bitflagsurl#name@versionβhttps://github.com/rust-lang/cargo#crates-io@0.21.0
the full specification grammar lives in chapter Package ID Specifications at 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. slay, you get to pick. π
π 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 theterm.verboseconfig value athttps://doc.rust-lang.org/cargo/reference/config.html.-q,--quietβ do not print cargo log messages π€« may also be specified with theterm.quietconfig value athttps://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 at 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 π--frozen,--lockedβ either of these flags requires that theCargo.lockfile is up-to-date. if the lock file is missing, or it needs to be updated, Cargo will exit with an error π the--frozenflag also prevents Cargo from attempting to access the network to determine if it is out-of-date.
these may be used in environments where you want to assert that the Cargo.lock file is up-to-date (such as a CI build) or want to avoid network access π‘οΈ
--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 bestie: 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 at https://doc.rust-lang.org/cargo/reference/config.html.
π 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 athttps://rust-lang.github.io/rustup/overrides.htmlfor 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 athttps://doc.rust-lang.org/cargo/reference/config.html#command-line-overridesfor 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 athttps://doc.rust-lang.org/book/appendix-07-nightly-rust.htmland requires the-Z unstable-optionsflag to enable (see #10098 athttps://github.com/rust-lang/cargo/issues/10098). unstable girlies only π
-h,--helpβ prints help information. the classic. π«Ά-Zflag β unstable (nightly-only) flags to Cargo. runcargo -Z helpfor details. π
π ENVIRONMENT π
see the reference at https://doc.rust-lang.org/cargo/reference/environment-variables.html for details on environment variables that Cargo reads π§
β 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.0offoo:
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!! π this was CARGO-PKGID(1), hanging out in the General Commands Manual section, and honestly? iconic. go forth and print those fully qualified package specs. periodt. πβ¨
π¦ where this page comes from
- ubuntu jammy: cargo-1.78 1.78.0+dfsg1ubuntu1~bpo0-0ubuntu0.22.04.1 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.78 1.78.0+dfsg1ubuntu1-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