CARGO-PACKAGE(1)
β¨ 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:
- Loads and checks your current workspace, doing some basic vibe checks along the way.
- Path dependencies are not allowed unless they have a
versionkey. no cap. Cargo will straight up ignore thepathkey for dependencies in published packages. (butdev-dependencies? they don't have this restriction, lucky them π)
- Path dependencies are not allowed unless they have a
- Creates the compressed
.cratefile.- The original
Cargo.tomlfile is rewritten and normalized. glow-up β¨ - The
[patch],[replace], and[workspace]sections get removed from the manifest. gone. bye. π Cargo.lockis 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--lockedflag is used. iykyk.- A
.cargo_vcs_info.jsonfile 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. π
- The original
- Extracts the
.cratefile 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-verifyflag skips this whole step. π§
- 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
- 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": ""
}
dirtyindicates that the Git worktree was dirty when the package was built. πpath_in_vcswill 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 π«Ά--indexindex β the URL of the registry index to use.--registryregistry β name of the registry to package for; peepcargo publish --helpfor 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. Checkcargo-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--workspaceflag. 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 π¦
--targettriple β package for the given architecture. The 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. 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-dirdirectory β 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 totargetin 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.
-Ffeatures,--featuresfeatures β 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 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-pathpath β path to theCargo.tomlfile. By default, Cargo searches for theCargo.tomlfile 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 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. (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--lockedand--offline. two for one special, we love a bundle.--lockfile-pathPATH β changes the path of the lockfile 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 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 π
-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 stringdefaultis provided, it sets the value back to defaults. Should not be0. (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 theterm.verboseconfig value <https://doc.rust-lang.org/cargo/reference/config.html>.-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>.--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, 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 π«Ά-Zflag β unstable (nightly-only) flags to Cargo. Runcargo -Z helpfor 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 π
- Create a compressed
.cratefile of the current package:
cargo package
π SEE ALSO π
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
- ubuntu jammy: cargo-1.82 1.82.0+dfsg0ubuntu0~jammy-0ubuntu0.22.04.1 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.82 1.82.0+dfsg0ubuntu0-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