LinuxCommandLibrary

cargo-pkgid

Print the fully qualified package ID

TLDR

Print the fully qualified package specification for the current project

$ cargo pkgid
copy

Print the fully qualified package specification for the specified package
$ cargo pkgid [partial_pkgspec]
copy

SYNOPSIS

cargo pkgid [OPTIONS] [SPEC...]

PARAMETERS

-p, --package SPEC...
    Select packages by name or name:version to output pkgid for

--manifest-path PATH
    Path to Cargo.toml file to use as workspace root

-q, --quiet
    Suppress all output except pkgid

--color WHEN
    Control output coloring: auto (default), always, never

-v, -vv, -vvv, --verbose
    Increase verbosity level (up to 3)

-h, --help
    Print help information

SPEC...
    Positional package specifiers (name, path, etc.)

DESCRIPTION

The cargo pkgid command outputs the unique Package ID (pkgid) for one or more packages specified in the current workspace or via arguments.

A pkgid identifies a package unambiguously within Cargo's dependency graph, formatted as package-name version (path-or-registry#hash). This is essential for tools, scripts, or integrations needing precise package references without ambiguity.

Without arguments, it prints the pkgid of the default package (root or first in workspace). Use positional arguments or -p for specific packages by name, name:version, or workspace-relative paths. It respects workspace inheritance and respects Cargo.toml configurations.

Ideal for automation, CI/CD pipelines, or generating reproducible builds. Output is stable and parseable, making it suitable for piping to other commands. Errors if no matching package found.

CAVEATS

Must run from workspace directory or specify --manifest-path; no matching spec yields error; does not resolve dependencies recursively.

OUTPUT FORMAT

Single line per package: name version (source-path-or-registry#short-hash).
Example: my-pkg 0.1.0 (/path/to/pkg#abc123)

EXAMPLES

cargo pkgid → root package ID
cargo pkgid -p mylib → specific package
cargo pkgid mybin mylib → multiple positional

HISTORY

Introduced in Cargo 1.30.0 (October 2018) to provide stable pkgid output for scripting and tooling integration.

SEE ALSO

cargo metadata(1), cargo tree(1), cargo check(1)

Copied to clipboard