CARGO-PACKAGE(1)

πŸ“¦ version 1.82.0, in ubuntu jammy, ubuntu noble

✨ cargo-package ✨

okay bestie, welcome to the cargo-package manual page β€” part of the cargo suite of General Commands, and honestly? it's giving ✨packaging✨ energy. let's get into it πŸ’…


🌸 NAME 🌸

cargo-package β€” Assemble the local package into a distributable tarball πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

cargo package [options]

πŸ’– DESCRIPTION πŸ’–

so basically, this command creates a distributable, compressed .crate file stuffed with the source code of the package that lives in your current directory. where does it go? into the target/package directory, obviously. πŸ‘‘

and like, it's not just yeeting your files into a zip and calling it a day. it does the whole ritual. here's the rundown:

  1. Loads and checks your current workspace, doing some basic vibe checks along the way.
    • Path dependencies are not allowed unless they have a version key. no cap. Cargo will straight up ignore the path key for dependencies in published packages. (but dev-dependencies? they don't have this restriction, lucky them πŸ“)
  2. Creates the compressed .crate file.
    • The original Cargo.toml file is rewritten and normalized. glow-up ✨
    • The [patch], [replace], and [workspace] sections get removed from the manifest. gone. bye. πŸ™ˆ
    • Cargo.lock is automatically included if the package contains an executable binary or example target. and listen β€” cargo-install(1) will use the packaged lock file if the --locked flag is used. iykyk.
    • A .cargo_vcs_info.json file is included, holding info about the current VCS checkout hash if available, plus a flag telling you if the worktree is dirty. messy worktree? it knows. πŸ’€
  3. Extracts the .crate file and builds it to verify it can actually build.
    • this literally rebuilds your package from scratch to make sure it can be built from a pristine state. main character energy, honestly. and if you don't wanna? the --no-verify flag skips this whole step. 🧚
  4. Checks that build scripts did not modify any source files. rude of them if they did.

the list of files that get included can be controlled with the include and exclude fields in the manifest. your files, your rules πŸ’…

for more details about packaging and publishing, see the reference at https://doc.rust-lang.org/cargo/reference/publishing.html β€” go read it, bestie 🫢


🌈 .cargo_vcs_info.json format 🌈

it will generate a .cargo_vcs_info.json in the following format:

{
 "git": {
   "sha1": "aac20b6e7e543e6dd4118b246c77225e3a3a1302",
   "dirty": true
 },
 "path_in_vcs": ""
}
  • dirty indicates that the Git worktree was dirty when the package was built. 😭
  • path_in_vcs will be set to a repo-relative path for packages in subdirectories of the version control repository.

the compatibility of this file is maintained under the same policy as the JSON output of cargo-metadata(1). so like, respect the policy, periodt.

⚠️ heads up though: this file provides a best-effort snapshot of the VCS information. however, the provenance of the package is not verified. there is no guarantee that the source code in the tarball matches the VCS information. so don't come for me if it doesn't line up πŸ™ˆ

✨ OPTIONS ✨


πŸŽ€ Package Options πŸŽ€

  • -l, --list β€” just prints the files that would go into a package, no actual package-making happening. window shopping bestie πŸ’…
  • --no-verify β€” skips verifying the contents by building them. no vibe check, just send it.
  • --no-metadata β€” ignores warnings about a lack of human-usable metadata (stuff like the description or the license). like, cargo will stop nagging you about it.
  • --allow-dirty β€” lets you package working directories that have uncommitted VCS changes. messy girlies, this one's for you 🫢
  • --index index β€” the URL of the registry index to use.
  • --registry registry β€” name of the registry to package for; peep cargo publish --help for more deets about how registry names get configured. The packages will not be published to this registry, but if we're packaging multiple inter-dependent crates, lock-files will be generated under the assumption that dependencies will be published to this registry.

🌸 Package Selection 🌸

By default, when you don't hand it any package selection options, the packages selected depend on the selected manifest file (which is based on the current working directory if --manifest-path isn't given). If the manifest is the root of a workspace then the workspace's default members get selected β€” otherwise only the package defined by the manifest gets selected. fr fr.

The default members of a workspace can be set explicitly with the workspace.default-members key in the root manifest. If that's not set, a virtual workspace will include all workspace members (equivalent to passing --workspace), and a non-virtual workspace will include only the root crate itself. iykyk.

  • -p *spec*…, --package *spec*… β€” package only the specified packages. Check cargo-pkgid(1) for the SPEC format. This flag may be specified multiple times and supports common Unix glob patterns like *, ? and []. However, to avoid your shell accidentally expanding glob patterns before Cargo even gets to handle them, you must use single quotes or double quotes around each pattern. no cap, your shell is out here doing too much.
  • --workspace β€” package every member in the workspace. all of them. the whole friend group πŸ’–
  • --exclude *SPEC*… β€” exclude the specified packages. Must be used in conjunction with the --workspace flag. This flag may be specified multiple times and supports common Unix glob patterns like *, ? and []. But again β€” to avoid your shell accidentally expanding glob patterns before Cargo handles them, you must use single quotes or double quotes around each pattern.

πŸ¦‹ Compilation Options πŸ¦‹

  • --target triple β€” package for the given architecture. The default is the host architecture. The general format of the triple is <arch><sub>-<vendor>-<sys>-<abi>. Run rustc --print target-list for a list of supported targets. This flag may be specified multiple times.

This may also be specified with the build.target config value <https://doc.rust-lang.org/cargo/reference/config.html>.

Note that specifying this flag makes Cargo run in a different mode where the target artifacts are placed in a separate directory. See the build cache <https://doc.rust-lang.org/cargo/guide/build-cache.html> documentation for more details.

  • --target-dir directory β€” directory for all generated artifacts and intermediate files. May also be specified with the CARGO_TARGET_DIR environment variable, or the build.target-dir config value <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults to target in the root of the workspace.

πŸ’œ 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. slay.

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.
  • --all-features β€” activate all available features of all selected packages. go big or go home ✨
  • --no-default-features β€” do not activate the default feature of the selected packages.

πŸŽ€ 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. it's giving "where's my manifest" scavenger hunt.
  • --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. (ci girlies, this is your moment πŸ”₯)

  • --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 for one special, we love a bundle.
  • --lockfile-path PATH β€” changes the path of the lockfile from the default (<workspace_root>/Cargo.lock) to PATH. PATH must end with Cargo.lock (e.g. --lockfile-path /tmp/temporary-lockfile/Cargo.lock). Note that providing --lockfile-path will ignore 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>). unstable queen behavior, we respect it πŸ‘‘

🌈 Miscellaneous Options 🌈

  • -j N, --jobs N β€” number of parallel jobs to run. May also be specified with the build.jobs config value <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults to the number of logical CPUs. If negative, it sets the maximum number of parallel jobs to the number of logical CPUs plus the provided value. If a string default is provided, it sets the value back to defaults. Should not be 0. (literally don't. zero jobs is not a vibe.)
  • --keep-going β€” build as many crates in the dependency graph as possible, rather than aborting the build on the first one that fails to build.

For example if the current package depends on dependencies fails and works, one of which fails to build, cargo package -j1 may or may not build the one that succeeds (depending on which one of the two builds Cargo picked to run first), whereas cargo package -j1 --keep-going would definitely run both builds, even if the one run first fails.


⭐ 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>.


🧚 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. order matters bestie, don't fight it.
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. when in doubt, ask for help 🫢
  • -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. πŸŽ‰
  • 101: Cargo failed to complete. 😭

πŸ“ EXAMPLES πŸ“

  1. Create a compressed .crate file of the current package:
cargo package

πŸ‘‘ SEE ALSO πŸ‘‘

cargo(1), cargo-publish(1)


and that's the whole page, bestie, we ate and left no crumbs πŸ’…βœ¨ this was CARGO-PACKAGE(1), dated February 2025, from the Cargo source package β€” it's part of the Rust toolchain, so copyright and license live with Rust there. go forth and package something iconic πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from