CARGO-PACKAGE(1)

πŸ“¦ version 1.78.0, in ubuntu jammy, ubuntu noble

✨ 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:

  1. Load and check the current workspace, running some basic checks along the way.
    • path dependencies? not allowed unless they have a version key. Cargo will straight-up ignore the path key for dependencies in published packages. oh and dev-dependencies? they don't have this restriction, they're free spirits πŸ•ŠοΈ
  2. Create the compressed .crate file.
    • the original Cargo.toml file gets rewritten and normalized.
    • [patch], [replace], and [workspace] sections get removed from the manifest. bye πŸ‘‹
    • Cargo.lock is automatically included if the package contains an executable binary or example target. and 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 (not included with --allow-dirty).
  3. Extract the .crate file 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-verify flag has your back.
  4. 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 the description or the license).
  • --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. check cargo-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 --workspace flag. 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 🌟

  • --target triple β€” package for the given architecture. the default is the host architecture. the general format of the triple is <arch><sub>-<vendor>-<sys>-<abi>. run rustc --print target-list for 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-dir directory β€” directory for all generated artifacts and intermediate files. may also be specified with the CARGO_TARGET_DIR environment variable, or the build.target-dir config value at 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.

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

  • -F features, --features features β€” 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 specified features.
  • --all-features β€” activate all available features of all selected packages.
  • --no-default-features β€” do not activate the default feature of the selected packages.

🫢 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.
  • --frozen, --locked β€” either of these flags requires that the Cargo.lock file is up-to-date. if the lock file is missing, or it needs to be updated, Cargo will exit with an error. the --frozen flag 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 ⭐

  • -j N, --jobs N β€” number of parallel jobs to run. may also be specified with the build.jobs config value at 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. (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 the term.verbose config value at https://doc.rust-lang.org/cargo/reference/config.html.
  • -q, --quiet β€” do not print cargo log messages. may also be specified with the term.quiet config value at https://doc.rust-lang.org/cargo/reference/config.html.
  • --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 at 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 at 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 at 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.
this option is only available on the nightly channel at https://doc.rust-lang.org/book/appendix-07-nightly-rust.html and requires the -Z unstable-options flag to enable (see #10098 at https://github.com/rust-lang/cargo/issues/10098).
  • -h, --help β€” prints help information.
  • -Z flag β€” unstable (nightly-only) flags to Cargo. run cargo -Z help for 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:

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 πŸŽ€

  1. Create a compressed .crate file 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