CARGO-PACKAGE(1)
π 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:
- 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.
- 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.
- 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.
- 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.
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 π--indexindex β the URL of the registry index you wanna use.--registryregistry β name of the registry you're packaging for; peepcargo publish --helpfor 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.
-pspecβ¦,--packagespecβ¦ β package only the packages you name. the SPEC format lives incargo-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--workspaceflag, 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 π¦
--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-listfor 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-dirdirectory β the directory for all generated artifacts and intermediate files. Can also be set with theCARGO_TARGET_DIRenvironment variable, or thebuild.target-dirconfig value <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults totargetin 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>.
-Ffeatures,--featuresfeatures β a space or comma separated list of features to activate. Features of workspace members can be enabled with thepackage-name/feature-namesyntax. 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-pathpath β path to theCargo.tomlfile. By default Cargo goes hunting forCargo.tomlin the current directory, or any parent directory.--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 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--lockedand--offline. two for one, ate π--lockfile-pathPATH β changes the lockfile path from the default (<workspace_root>/Cargo.lock) to PATH. PATH must end withCargo.lock(e.g.--lockfile-path /tmp/temporary-lockfile/Cargo.lock). Note that providing--lockfile-pathwill 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 π
-jN,--jobsN β number of parallel jobs to run. May also be set with thebuild.jobsconfig 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 stringdefaultis provided, it sets the value back to defaults. Should not be0. 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 theterm.verboseconfig 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 theterm.quietconfig value <https://doc.rust-lang.org/cargo/reference/config.html>. silence, but make it fashion π€«--colorwhen β 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 tocargostarts with+, it gets interpreted as a rustup toolchain name (like+stableor+nightly). See the rustup documentation <https://rust-lang.github.io/rustup/overrides.html> for more info on how toolchain overrides work.--configKEY=VALUE or PATH β overrides a Cargo configuration value. The argument should be in TOML syntax ofKEY=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.-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), and the directories it searches for discovering.cargo/config.toml, for example. This option must appear before the command name, likecargo -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 π₯Ί-Zflag β unstable (nightly-only) flags for Cargo. Runcargo -Z helpfor 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 π
- Create a compressed
.cratefile of the current package:
cargo package
one command. one lil .crate file. that's it. obsessed π
π SEE ALSO π
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
- ubuntu jammy: cargo-1.83 1.83.0+dfsg0ubuntu2~bpo2-0ubuntu2.22.04.1 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.83 1.83.0+dfsg0ubuntu1~bpo2-0ubuntu0.24.04.1 Β· Apache-2.0 WITH LLVM exception
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms