CARGO-PACKAGE(1)
β¨ CARGO-PACKAGE(1) β¨
okay so this is cargo-package, from the General Commands Manual section, and bestieβ¦ she's a whole vibe. let's get into it π
πΈ NAME πΈ
cargo-package β assemble the local package into a distributable tarball
π SYNOPSIS π
cargo package [options]
π¦ DESCRIPTION π¦
okay so picture this: this command creates a distributable, compressed .crate file holding the source code of the package sitting in your current directory. and where does that little baby go? straight into the target/package directory. iconic.
and the way it does it is literally a four-step glow-up:
- Load and check the current workspace, running some basic checks along the way.
- path dependencies? not allowed unless they have a
versionkey. Cargo will straight-up ignore thepathkey for dependencies in published packages. oh anddev-dependencies? they don't have this restriction, they're free spirits ποΈ
- path dependencies? not allowed unless they have a
- Create the compressed
.cratefile.- the original
Cargo.tomlfile gets rewritten and normalized. [patch],[replace], and[workspace]sections get removed from the manifest. bye πCargo.lockis automatically included if the package contains an executable binary or example target. andcargo-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 (not included with--allow-dirty).
- the original
- Extract the
.cratefile and build it to verify it can build.- this rebuilds your package from scratch to make sure it can be built from a pristine state. if you wanna skip this whole step, the
--no-verifyflag has your back.
- this rebuilds your package from scratch to make sure it can be built from a pristine state. if you wanna skip this whole step, the
- Check that build scripts did not modify any source files. (yes, they check. they always check. π)
the list of files included can be controlled with the include and exclude fields in the manifest.
want more tea about packaging and publishing? see the reference at https://doc.rust-lang.org/cargo/reference/publishing.html π
π§ .cargo_vcs_info.json format π§
this is gonna generate a .cargo_vcs_info.json in the following format:
{
"git": {
"sha1": "aac20b6e7e543e6dd4118b246c77225e3a3a1302"
},
"path_in_vcs": ""
}
path_in_vcs will be set to a repo-relative path for packages in subdirectories of the version control repository. slay.
π OPTIONS π
π Package Options π
-l,--listβ print files included in a package without making one. window shopping, basically π--no-verifyβ don't verify the contents by building them.--no-metadataβ ignore warnings about a lack of human-usable metadata (such as thedescriptionor thelicense).--allow-dirtyβ allow working directories with uncommitted VCS changes to be packaged. living dangerously, love that for you π
π Package Selection π
by default, when no package selection options are given, the packages selected depend on the selected manifest file (based on the current working directory if --manifest-path is not given). if the manifest is the root of a workspace then the workspace's default members are selected, otherwise only the package defined by the manifest will be selected.
the default members of a workspace can be set explicitly with the workspace.default-members key in the root manifest. if this is 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.
-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 handles them, you must use single quotes or double quotes around each pattern. no cap.--workspaceβ package all members in the workspace. all of them. every single one.--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[]. however, 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 at https://doc.rust-lang.org/cargo/reference/config.html.
heads up bestie: 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 at https://doc.rust-lang.org/cargo/guide/build-cache.html 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 athttps://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.
see the features documentation at https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options for more details. iykyk β¨
-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.--no-default-featuresβ do not activate thedefaultfeature 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.--frozen,--lockedβ either of these flags requires that theCargo.lockfile is up-to-date. if the lock file is missing, or it needs to be updated, Cargo will exit with an error. the--frozenflag also prevents Cargo from attempting to access the network to determine if it is out-of-date.
these may be used in environments where you want to assert that the Cargo.lock file is up-to-date (such as a CI build) or want to avoid network access.
--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 bestie π 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 at https://doc.rust-lang.org/cargo/reference/config.html.
β Miscellaneous Options β
-jN,--jobsN β number of parallel jobs to run. may also be specified with thebuild.jobsconfig value athttps://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 be 0. (like, do not.)--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 athttps://doc.rust-lang.org/cargo/reference/config.html.-q,--quietβ do not print cargo log messages. may also be specified with theterm.quietconfig value athttps://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 at 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 athttps://rust-lang.github.io/rustup/overrides.htmlfor 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 athttps://doc.rust-lang.org/cargo/reference/config.html#command-line-overridesfor 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.
this option is only available on the nightly channel athttps://doc.rust-lang.org/book/appendix-07-nightly-rust.htmland requires the-Z unstable-optionsflag to enable (see #10098 athttps://github.com/rust-lang/cargo/issues/10098).
-h,--helpβ prints help information.-Zflag β unstable (nightly-only) flags to Cargo. runcargo -Z helpfor details.
πΏ ENVIRONMENT πΏ
okay so bestie, Cargo lowkey reads a bunch of environment variables, and we are not listing them all here because that would be a whole other saga. Instead:
- the full deets live in the reference at
https://doc.rust-lang.org/cargo/reference/environment-variables.html
that's the spot. go there. it's giving "required reading" but make it cute. π
β¨ EXIT STATUS β¨
the receipts, bestie β here's what Cargo hands back when it's done:
0β Cargo succeeded. π slay. the vibes are immaculate.101β Cargo failed to complete. π not the outcome we wanted. something went sideways.
no cap, 101 is the one you'll see in your CI logs at 2am. just so you know. π«Ά
π EXAMPLES π
- Create a compressed
.cratefile of the current package:
cargo package
that's it. that's the whole thing. one command, one .crate file, main character energy. π
π SEE ALSO π
go read those too, bestie, they're literally the same universe. iykyk. π
and that's a wrap on CARGO-PACKAGE(1) β this gorgeous little page is from the Cargo source, dated like a fine vintage, and its footer signs off as CARGO-PACKAGE(1) which is honestly iconic of it. mwah. πβ¨
π¦ where this page comes from
- ubuntu jammy: cargo-1.78 1.78.0+dfsg1ubuntu1~bpo0-0ubuntu0.22.04.1 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.78 1.78.0+dfsg1ubuntu1-0ubuntu0.24.04.2 Β· 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