CARGO-PACKAGE(1)
๐ 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:
- Load and check the current workspace, performing some basic checks.
- Path dependencies are not allowed unless they have a
versionkey. Cargo will ignore thepathkey for dependencies in published packages.dev-dependenciesdo not have this restriction. That's the rule, periodt.
- Path dependencies are not allowed unless they have a
- Create the compressed
.cratefile.- The original
Cargo.tomlfile is rewritten and normalized. [patch],[replace], and[workspace]sections are removed from the manifest.Cargo.lockis automatically included if the package contains an executable binary or example target.cargo-install(1)will use the packaged lock file if the--lockedflag is used.- A
.cargo_vcs_info.jsonfile 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.
- The original
- Extract the
.cratefile 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-verifyflag can be used to skip this step. So if you're in a rush,--no-verifyis right there, but it skips the vibe check.
- This will rebuild your package from scratch to ensure that it can be built from a pristine state. The
- 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 incargo-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--workspaceflag. 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 ๐
--targettriple โ package for the given architecture. default is the host architecture. the general format of the triple is<arch><sub>-<vendor>-<sys>-<abi>. runrustc --print target-listto 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 totarget` 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.
-Ffeatures,--featuresfeatures โ a space or comma separated list of features to activate. features of workspace members may be enabled withpackage-name/feature-namesyntax. 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-pathpath โ path to theCargo.tomlfile. by default, Cargo searches for theCargo.tomlfile 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 existingCargo.lockfile 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--lockedand--offline. two flags in a trench coat, slay ๐ง
โญ Miscellaneous Options โญ
-jN,--jobsN โ number of parallel jobs to run. may also be specified with thebuild.jobsconfig 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 be0. (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 theterm.verboseconfig 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 theterm.quietconfig value<https://doc.rust-lang.org/cargo/reference/config.html>. silence, but make it chic ๐คซ--colorwhen โ 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 tocargobegins with+, it will be interpreted as a rustup toolchain name (such as+stableor+nightly). see the rustup documentation<https://rust-lang.github.io/rustup/overrides.html>for more information about how toolchain overrides work. ๐--configKEY=VALUE or PATH โ overrides a Cargo configuration value. the argument should be in TOML syntax ofKEY=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.-CPATH โ 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 examplecargo -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-optionsflag to enable (see #10098<https://github.com/rust-lang/cargo/issues/10098>). ๐ง
-h,--helpโ prints help information. when in doubt ๐-Zflag โ unstable (nightly-only) flags to Cargo. runcargo -Z helpfor 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 โญ
- Create a compressed
.cratefile of the current package:
cargo package
๐ SEE ALSO ๐
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
- ubuntu jammy: cargo-1.81 1.81.0+dfsg0ubuntu0-0ubuntu0.22.04.1 ยท Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.81 1.81.0+dfsg0ubuntu1-0ubuntu0.24.04.1 ยท MIT OR Apache-2.0
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms