CARGO-PACKAGE(1)

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

πŸ’– NAME πŸ’–

From the General Commands Manual, bestie: cargo-package(1) β€” and the actual NAME line is: cargo-package β€” Assemble the local package into a distributable tarball. πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

cargo package [options]

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so here's the tea, bestie: this command creates a distributable, compressed .crate file with the source code of the package in the current directory. The resulting file will be stored in the target/package directory. It's giving "ship it" energy. This performs the following steps:

  1. Load and check the current workspace, performing some basic checks.
    • Path dependencies are not allowed unless they have a version key. Cargo will ignore the path key for dependencies in published packages. dev-dependencies do not have this restriction.
  2. Create the compressed .crate file.
    • The original Cargo.toml file is rewritten and normalized.
    • [patch], [replace], and [workspace] sections are removed from the manifest.
    • Cargo.lock is automatically included if the package contains an executable binary or example target. cargo-install(1) will use the packaged lock file if the --locked flag is used.
    • A .cargo_vcs_info.json file is included that contains information about the current VCS checkout hash if available, as well as a flag if the worktree is dirty.
  3. Extract the .crate file and build it to verify it can build.
    • This will rebuild your package from scratch to ensure that it can be built from a pristine state. The --no-verify flag can be used to skip this step.
  4. Check that build scripts did not modify any source files.

The list of files included can be controlled with the include and exclude fields in the manifest.

See the reference <https://doc.rust-lang.org/cargo/reference/publishing.html> for more details about packaging and publishing.

✨ .cargo_vcs_info.json format ✨

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

Note that 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.

✨ OPTIONS ✨

ok bestie buckle up, this is the long part but it's literally all just "what flag do I type" so we're fine πŸ’…


πŸŽ€ Package Options πŸŽ€

  • -l, --list β€” just shows you the files that would go in a package, no actual packaging happening. window shopping, but for files ✨
  • --no-verify β€” skips verifying the contents by building them. no vibe check on the goods, we're trusting it πŸ™ˆ
  • --no-metadata β€” ignores the warnings about missing human-usable metadata, like the description or the license. living dangerously, no cap
  • --allow-dirty β€” lets you package a working directory that's got uncommitted VCS changes sitting in it. yes bestie, the mess is allowed πŸ’€
  • --index index β€” the URL of the registry index you wanna use.
  • --registry registry β€” name of the registry you're packaging for; peep cargo publish --help for more deets on how registry names get configured. Important: the packages will not be published to this registry β€” but if we're packaging multiple inter-dependent crates, the lock-files get generated assuming the dependencies will be published to this registry. so it's like, cosplay 🫢

🌸 Package Selection 🌸

ok so by default, when you give it no package selection options at all, which packages get picked depends on the manifest file it's looking at (which is based on the current working directory, unless you passed --manifest-path). If that 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. periodt.

The default members of a workspace can be set explicitly with the workspace.default-members key in the root manifest. And if that's not set? A virtual workspace will include all workspace members (that's the same as passing --workspace), while a non-virtual workspace will include only the root crate itself. slay.

  • -p spec…, --package spec… β€” package only the packages you name. the SPEC format lives in cargo-pkgid(1). You can pass this flag multiple times, and it supports common Unix glob patterns like *, ? and []. BUT β€” so your shell doesn't go and expand those globs before Cargo gets to handle them, you gotta wrap each pattern in single quotes or double quotes. otherwise your shell is doing crimes and Cargo is like ??? 😭
  • --workspace β€” package every single member in the workspace. the whole friend group πŸ‘‘
  • --exclude *SPEC*… β€” excludes the packages you name. This one must be used together with the --workspace flag, no solo runs. Can be passed multiple times, supports common Unix glob patterns like *, ? and [], and same deal as before: single or double quote each pattern so your shell doesn't pre-expand them. πŸ’…

πŸ¦‹ Compilation Options πŸ¦‹

  • --target triple β€” package for the given architecture. 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. You can pass this flag multiple times.

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

Heads up: specifying this flag makes Cargo run in a different mode where the target artifacts land in a separate directory. More deets in the build cache docs <https://doc.rust-lang.org/cargo/reference/build-cache.html>. πŸ—‚οΈ

  • --target-dir directory β€” the directory for all generated artifacts and intermediate files. Can also be set 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 🧚

These feature flags let you control which features are enabled, bestie. When you give no feature options at all, the default feature gets activated for every selected package. that's the baseline vibe ✨

More details over in the features docs <https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options>.

  • -F features, --features features β€” a space or comma separated list of features to activate. Features of workspace members can be enabled with the package-name/feature-name syntax. Pass this flag multiple times and it enables all the features you specified. stacking them like bracelets πŸŽ€
  • --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. minimalism era 🧘

πŸ’œ Manifest Options πŸ’œ

  • --manifest-path path β€” path to the Cargo.toml file. By default Cargo goes hunting for Cargo.toml in the current directory, or any parent directory.
  • --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 these scenarios shows up:
    • The lock file is missing.
    • Cargo attempted to change the lock file because of a different dependency resolution.

Use this in environments where you want deterministic builds, like in CI pipelines. no surprises allowed 🚫

  • --offline β€” stops Cargo from accessing the network for any reason. Without this flag, Cargo just stops with an error if it needs the network and the network isn't there. With this flag, Cargo will attempt to proceed without the network if it can.

Beware: this can give you a different dependency resolution than online mode. Cargo restricts itself to crates that are already downloaded locally, even if there might be a newer version indicated in the local copy of the index. See cargo-fetch(1) to download dependencies before going offline, bestie β€” plan ahead πŸ’…

May also be set with the net.offline config value <https://doc.rust-lang.org/cargo/reference/config.html>.

  • --frozen β€” literally equivalent to specifying both --locked and --offline. two for one, ate πŸ’…
  • --lockfile-path PATH β€” changes the lockfile path 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 any existing lockfile at the default path, and instead will either use the lockfile from PATH, or write a new lockfile into the PATH you gave if it doesn't exist. This flag lets you run most commands in read-only directories, writing the lockfile into the PATH you provided. iconic for locked-down setups πŸ”
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>). so if you're on stable, bestie, this one's not for you yet 😭

🌈 Miscellaneous Options 🌈

  • -j N, --jobs N β€” number of parallel jobs to run. May also be set with the build.jobs config value <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults to the number of logical CPUs. If it's negative, it sets the maximum number of parallel jobs to the number of logical CPUs plus the value you gave. If a string default is provided, it sets the value back to defaults. Should not be 0. zero is a trap, do not πŸ™…
  • --keep-going β€” build as many crates in the dependency graph as possible, instead of aborting the build the moment the first one fails to build. keep the party going even when one guest is late πŸ’ƒ

For example: if the current package depends on dependencies fails and works, and one of them 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. Pass it twice for "very verbose" output, which includes extra stuff like dependency warnings and build script output. May also be set with the term.verbose config value <https://doc.rust-lang.org/cargo/reference/config.html>. yap mode: on πŸ—£οΈ
  • -q, --quiet β€” do not print cargo log messages. May also be set with the term.quiet config value <https://doc.rust-lang.org/cargo/reference/config.html>. silence, but make it fashion 🀫
  • --color when β€” controls 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 set with the term.color config value <https://doc.rust-lang.org/cargo/reference/config.html>. we love a colorful terminal 🌈


🫢 Common Options 🫢

  • +toolchain β€” if Cargo was installed with rustup, and the first argument to cargo starts with +, it gets interpreted as a rustup toolchain name (like +stable or +nightly). See the rustup documentation <https://rust-lang.github.io/rustup/overrides.html> for more info on 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 given as a path to an extra configuration file. This flag can be specified multiple times. See the command-line overrides section <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides> for more.
  • -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), and the directories it searches for discovering .cargo/config.toml, for example. This option must appear before the command name, like cargo -C path/to/my-project build. order matters, bestie πŸ“
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. your bestie when you're lost πŸ₯Ί
  • -Z flag β€” unstable (nightly-only) flags for Cargo. Run cargo -Z help for details. exclusive club only πŸ’…

🌍 ENVIRONMENT 🌍

See the reference <https://doc.rust-lang.org/cargo/reference/environment-variables.html> for the deets on which environment variables Cargo reads. it reads them. it's nosy. we love it. πŸ‘€


πŸ’€ EXIT STATUS πŸ’€

  • 0: Cargo succeeded. slay πŸŽ‰
  • 101: Cargo failed to complete. it's giving tragedy 😭

πŸ“ EXAMPLES πŸ“

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

one command. one lil .crate file. that's it. obsessed πŸ’–


πŸ‘‘ SEE ALSO πŸ‘‘

cargo(1), cargo-publish(1)


and that's the whole page, bestie 🫢 this was the CARGO-PACKAGE(1) page from the Cargo manual β€” its footer carries the source/version and the date it was generated, so if you ever need to cite it or check which Cargo era this text is from, that lil line at the bottom is where the receipts live πŸ“œβœ¨ go forth and package responsibly πŸ’…

πŸ“¦ where this page comes from