CARGO-PACKAGE(1)

๐Ÿ“ฆ version 1.81.0, in ubuntu jammy, ubuntu noble

๐Ÿ’– NAME ๐Ÿ’–

cargo-package โ€” Assemble the local package into a distributable tarball โœจ

Okay bestie, welcome to the cargo-package manual page. This is the one about making a cute lil distributable tarball from your local package. It's giving "ship it" energy, no cap. ๐ŸŽ€

๐ŸŒˆ SYNOPSIS ๐ŸŒˆ

cargo package [options]

โœจ DESCRIPTION โœจ

This command will create 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. 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. That's the rule, periodt.
  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. Obsessed with the transparency, honestly.
  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. So if you're in a rush, --no-verify is right there, but it skips the vibe check.
  4. Check that build scripts did not modify any source files. fr fr, this is the final safety check.

The list of files included can be controlled with the include and exclude fields in the manifest. Curate your package like a playlist, bestie. ๐ŸŽง

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


๐Ÿฆ‹ .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. So if it says true, your worktree was not clean, bestie.

path_in_vcs will be set to a repo-relative path for packages in subdirectories of the version control repository. Subdirectory package? You get that path. Slay.

The compatibility of this file is maintained under the same policy as the JSON output of cargo-metadata(1). Same energy, same policy. โœจ

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.

So don't treat it like a signed, sealed, certified receipt. It's a vibe check, not a proof. ๐Ÿ’€

โœจ OPTIONS โœจ


๐ŸŽ€ Package Options ๐ŸŽ€

  • -l, --list โ€” bestie this one just prints out the files that would go inside a package, and does not actually make one. window shopping, but for your crate ๐Ÿ’…
  • --no-verify โ€” skips the whole "verify the contents by building them" step. no vibe check, no build check ๐Ÿซถ
  • --no-metadata โ€” tells Cargo to ignore the warnings it would normally throw at you about missing human-usable metadata (that's stuff like the description or the license). literally just letting it slide ๐Ÿ™ˆ
  • --allow-dirty โ€” permits packaging a working directory that has uncommitted VCS changes. yes queen, ship it unwashed ๐Ÿ’€

๐ŸŒธ Package Selection ๐ŸŒธ

okay so by default, when you don't pass any package selection options, which packages get picked depends on the selected manifest file (which is based on the current working directory if --manifest-path isn't given). and if that manifest is the root of a workspace, then the workspace's default members are selected โ€” otherwise, only the package defined by the manifest gets selected. no cap โœจ

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, then a virtual workspace will include all workspace members (which is equivalent to passing --workspace), and a non-virtual workspace will include only the root crate itself. iykyk ๐ŸŒˆ

  • -p *spec*โ€ฆ, --package *spec*โ€ฆ โ€” package only the packages you name. the SPEC format lives over in cargo-pkgid(1). you can pass this flag multiple times and it supports common Unix glob patterns like *, ? and []. BUT โ€” and this is the part everyone gets wrong โ€” to stop your shell from expanding those glob patterns before Cargo even gets its hands on them, you must wrap each pattern in single quotes or double quotes. periodt ๐ŸŽ€
  • --workspace โ€” package every single member in the workspace. the whole squad, no one left out ๐Ÿ’–
  • --exclude *SPEC*โ€ฆ โ€” exclude the packages you name. this one must be used together with the --workspace flag. may be specified multiple times, supports common Unix glob patterns like *, ? and [], and โ€” same deal as before โ€” you must use single quotes or double quotes around each pattern so your shell doesn't go rogue and expand them first. iconic behavior only ๐Ÿฆ‹

๐Ÿ’… 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 to get 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 documentation <https://doc.rust-lang.org/cargo/guide/build-cache.html> for more details. it's giving "different directory, different era" โœจ

  • *--target-dir *directoryโ€” directory for all generated artifacts and intermediate files. may also be specified with theCARGO_TARGET_DIRenvironment variable, or thebuild.target-dirconfig 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. yes bestie, everyone gets the default ๐ŸŒธ

see the features documentation <https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options> for more details.

  • -F features, --features features โ€” a 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 the specified features. stacking them like accessories ๐Ÿ‘‘
  • --all-features โ€” activate every available feature of all selected packages. all of them. go feral ๐Ÿ’…
  • --no-default-features โ€” do not activate the default feature of the selected packages. we're going minimal today ๐ŸŽ€

๐ŸŒˆ 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 will find it, trust ๐Ÿซถ
  • --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. no surprises, no plot twists โœจ

  • --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 isn't available. with this flag, Cargo will attempt to proceed without the network if possible.
beware bestie โ€” this may result in a 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 flags in a trench coat, slay ๐ŸงŠ

โญ 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. (seriously, zero is not the 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. resilience, main character energy ๐Ÿ”ฅ

๐Ÿ’œ 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>. tell me everything, i'm nosy ๐Ÿ‘€
  • -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>. silence, but make it chic ๐Ÿคซ
  • --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 โœจ
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 ๐ŸŽ€
  • -Z flag โ€” unstable (nightly-only) flags to Cargo. run cargo -Z help for details. forbidden knowledge, only for the brave ๐Ÿ”ฎ

๐ŸŒ 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)


okay that's the whole page bestie, and honestly? iconic. this was the CARGO-PACKAGE(1) manual page โ€” give it a lil kiss goodnight ๐Ÿ’–๐ŸŒธโœจ

๐Ÿ“ฆ where this page comes from