LinuxCommandLibrary

cargo-package

Package a Rust crate for distribution

TLDR

Perform checks and create a .crate file (equivalent of cargo publish --dry-run)

$ cargo package
copy

Display what files would be included in the tarball without actually creating it
$ cargo package [[-l|--list]]
copy

SYNOPSIS

cargo package [path] [--allow-dirty] [--no-verify] [--no-delete] [--no-build] [--jobs N] [--color WHEN] [-v...] [-q] [--frozen] [--locked] [--offline] [-h] [-V]

PARAMETERS

--allow-dirty
    Allow packaging from a dirty git working directory

--no-verify
    Skip running cargo check before packaging

--no-delete
    Don't delete the generated tarball on failure

--no-build
    Don't build dependencies before checking

--jobs, -j N
    Number of parallel jobs (default: number of CPUs)

--color WHEN
    Control colored output: auto, always, never

-v, --verbose ...
    Increase verbosity (repeatable for more)

-q, --quiet
    Suppress all output

--frozen
    Don't update Cargo.lock or use network

--locked
    Require Cargo.lock to be up-to-date

--offline
    Run without network access

path
    Path to Cargo.toml directory to package (default: current)

-h, --help
    Print help information

-V, --version
    Print Cargo version

DESCRIPTION

The cargo package command creates a versioned tarball (.crate file) of the current Rust project or specified path, ready for publishing to a registry like crates.io.

It performs several checks: verifies the package metadata in Cargo.toml, ensures no local paths in dependencies, runs cargo check (unless disabled), and builds dependencies if needed. The tarball excludes files listed in .gitignore, Cargo.lock (by default), and other ignored files, including only relevant source code and assets.

By default, it aborts if the working directory is dirty (uncommitted changes), deletes the tarball on failure, and verifies the package integrity. This ensures only clean, buildable packages are created. The output file is named like <package>-<version>.crate in target/package/. Ideal for CI/CD pipelines before cargo publish.

CAVEATS

Requires a valid Cargo.toml; aborts on dirty tree by default; excludes Cargo.lock unless --locked; network access needed for dependency resolution unless --offline.

OUTPUT LOCATION

Tarball saved to target/package/<name>-<version>.crate

EXAMPLE

cargo package --allow-dirty
Packages despite uncommitted changes.

HISTORY

Introduced with Cargo 0.1.0 in 2014 by Rust team at Mozilla; evolved with Rust editions and workspace support in Cargo 0.18+ (2017). Now at Cargo 1.80+ with improved verification.

SEE ALSO

Copied to clipboard