CARGO-PUBLISH(1)

๐Ÿ“ฆ version 1.89.0, in ubuntu jammy, ubuntu noble

๐Ÿ’– CARGO-PUBLISH(1) ๐Ÿ’–

General Commands Manual

๐ŸŒธ NAME ๐ŸŒธ

cargo-publish โ€” Upload a package to the registry. It's giving "ship it to crates.io" energy. ๐Ÿ’…๐Ÿ“ฆ

โœจ SYNOPSIS โœจ

cargo publish [options]

๐Ÿ’– DESCRIPTION ๐Ÿ’–

Okay bestie, so this command creates a distributable, compressed .crate file with the source code of the package in the current directory and uploads it to a registry. The default registry is <https://crates.io>. ๐Ÿฆ‹ It does these steps:

  1. It runs a few checks, including:
    • It checks the package.publish key in the manifest for restrictions on which registries you're allowed to publish to. ๐Ÿ”’
  2. It creates a .crate file by following the steps in cargo-package(1). ๐ŸŽ€
  3. It uploads the crate to the registry. The server will perform additional checks on the crate. โ˜๏ธ
  4. The client will poll waiting for the package to appear in the index, and may timeout. In that case, you will need to check for completion manually. This timeout does not affect the upload. โณ

This command requires you to be authenticated with either the --token option or using cargo-login(1). ๐Ÿ”

See the reference <https://doc.rust-lang.org/cargo/reference/publishing.html> for more details about packaging and publishing. ๐Ÿ“š


๐ŸŽ€ OPTIONS ๐ŸŽ€

No skipping, bestie. Every flag is here. ๐Ÿ’–

๐Ÿ›๏ธ Publish Options ๐Ÿ›๏ธ

  • --dry-run โ€” Perform all checks without uploading. ๐Ÿšซ๐Ÿ“ค
  • --token token โ€” API token to use when authenticating. This overrides the token stored in the credentials file (which is created by cargo-login(1)). ๐Ÿ”‘ Cargo config <https://doc.rust-lang.org/cargo/reference/config.html> environment variables can be used to override the tokens stored in the credentials file. The token for crates.io may be specified with the CARGO_REGISTRY_TOKEN environment variable. Tokens for other registries may be specified with environment variables of the form CARGO_REGISTRIES_NAME_TOKEN where NAME is the name of the registry in all capital letters. ๐ŸŒˆ
  • --no-verify โ€” Donโ€™t verify the contents by building them. ๐Ÿ™ˆ
  • --allow-dirty โ€” Allow working directories with uncommitted VCS changes to be packaged. ๐Ÿงผ
  • --index index โ€” The URL of the registry index to use. ๐Ÿ”—
  • --registry registry โ€” Name of the registry to publish to. Registry names are defined in Cargo config files <https://doc.rust-lang.org/cargo/reference/config.html>. If not specified, and there is a package.publish <https://doc.rust-lang.org/cargo/reference/manifest.html#the-publish-field> field in Cargo.toml with a single registry, then it will publish to that registry. Otherwise it will use the default registry, which is defined by the registry.default <https://doc.rust-lang.org/cargo/reference/config.html#registrydefault> config key which defaults to crates-io. ๐Ÿ‘‘

๐Ÿ“ฆ 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 workspaces 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. ๐ŸŒณ

Selecting more than one package is unstable and available only on the nightly channel <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and requires the -Z package-workspace flag to enable. See <https://github.com/rust-lang/cargo/issues/10948> for more information. โš ๏ธ
  • -p *spec*โ€ฆ, --package *spec*โ€ฆ โ€” Publish only the specified packages. See 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. ๐Ÿงฉ Selecting more than one package with this option is unstable and available only on the nightly channel <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and requires the -Z package-workspace flag to enable. See <https://github.com/rust-lang/cargo/issues/10948> for more information. โš ๏ธ
  • --workspace โ€” Publish all members in the workspace. ๐Ÿข This option is unstable and available only on the nightly channel <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and requires the -Z package-workspace flag to enable. See <https://github.com/rust-lang/cargo/issues/10948> for more information. โš ๏ธ
  • --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. ๐Ÿšซ This option is unstable and available only on the nightly channel <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and requires the -Z package-workspace flag to enable. See <https://github.com/rust-lang/cargo/issues/10948> for more information. โš ๏ธ

โš™๏ธ Compilation Options โš™๏ธ

  • --target triple โ€” Publish 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 <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/reference/build-cache.html> documentation 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 <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults to target in the root of the workspace. ๐ŸŽฏ

โœจ Feature Selection โœจ

The feature flags allow you to control which features are enabled. When no feature options are given, the default feature is activated for every selected package. ๐ŸŽ›๏ธ

See the features documentation <https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options> for more details. ๐Ÿ“–

  • -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. ๐Ÿ”
  • --locked โ€” Asserts that the exact same dependencies and versions are used as when the existing Cargo.lock file 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. ๐Ÿ—๏ธ
  • --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 --locked and --offline. ๐ŸงŠ
  • --lockfile-path PATH โ€” Changes the path of the lockfile from the default (<workspace_root>/Cargo.lock) to PATH. PATH must end with Cargo.lock (e.g. --lockfile-path /tmp/temporary-lockfile/Cargo.lock). Note that providing --lockfile-path will 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>). โš ๏ธ

๐ŸŽฒ Miscellaneous Options ๐ŸŽฒ

  • -j N, --jobs N โ€” Number of parallel jobs to run. May also be specified with the build.jobs config 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 provided value. If a string default is provided, it sets the value back to defaults. Should not be 0. ๐Ÿงต
  • --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 publish -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 publish -j1 --keep-going would definitely run both builds, even if the one run first fails. ๐Ÿ’ช

โœจ Display Options โœจ

Okay bestie, these are the vibe-check options for how much Cargo talks to you. ๐Ÿ’ฌ

  • -v, --verbose โ€” bestie, this makes Cargo spill the tea. Use it once for verbose output, and twice for very verbose โ€” that's when you get the extra deets like dependency warnings and build script output. You can also set this with the term.verbose config value <https://doc.rust-lang.org/cargo/reference/config.html>. ๐Ÿ‘‘
  • -q, --quiet โ€” not me wanting peace and quiet. This makes Cargo stop printing log messages. It's giving silent mode. You can also set it with the term.quiet config value <https://doc.rust-lang.org/cargo/reference/config.html>. ๐Ÿคซ
  • --color when โ€” control when colored output happens. Valid values are:
    • auto (default): Automatically detect if color support is available on the terminal. So it just knows. ๐Ÿ”ฎ
    • always: Always display colors. Periodt. ๐ŸŒˆ
    • never: Never display colors. No cap. ๐Ÿšซ You can also set this with the term.color config value <https://doc.rust-lang.org/cargo/reference/config.html>. ๐ŸŽจ

๐ŸŽ€ Common Options ๐ŸŽ€

These are the common options that work across Cargo commands, bestie. They're like the little black dress of CLI flags. ๐Ÿ–ค

  • +toolchain โ€” if you installed Cargo with rustup, and the first argument to cargo starts with +, it's interpreted as a rustup toolchain name (like +stable or +nightly). Check the rustup documentation <https://rust-lang.github.io/rustup/overrides.html> for more info on how toolchain overrides work. It's giving โœจversatilityโœจ. ๐Ÿฆ‹
  • --config KEY=VALUE or PATH โ€” overrides a Cargo configuration value. The argument should be in TOML syntax of KEY=VALUE, or a path to an extra configuration file. You can use this flag multiple times. See the command-line overrides section <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides> for more. This is your config cheat code. ๐Ÿ”ง
  • -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), and the directories searched for discovering .cargo/config.toml, for example. This option must appear before the command name, like cargo -C path/to/my-project build.
โš ๏ธ 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>). So, like, don't try this on stable, bestie. ๐Ÿ’€
  • -h, --help โ€” prints help information. The classic. When in doubt, ask for help. ๐Ÿ†˜
  • -Z flag โ€” unstable (nightly-only) flags to Cargo. Run cargo -Z help for details. This is the backstage pass to the unstable stuff. ๐ŸŽŸ๏ธ

๐ŸŒฟ ENVIRONMENT ๐ŸŒฟ

Cargo reads environment variables, bestie. See the reference <https://doc.rust-lang.org/cargo/reference/environment-variables.html> for all the details on which ones and what they do. It's giving very configurable. ๐ŸŒฑ

๐Ÿšฆ EXIT STATUS ๐Ÿšฆ

  • 0: Cargo succeeded. We love a win. ๐ŸŽ‰
  • 101: Cargo failed to complete. Oof. ๐Ÿ’”

๐ŸŒŸ EXAMPLES ๐ŸŒŸ

  1. Publish the current package:
cargo publish

That's it. That's the whole thing. You're a published author now. ๐Ÿ’…

๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

cargo(1), cargo-package(1), cargo-login(1)


And that's the tea, bestie! This has been CARGO-PUBLISH(1) from the cargo manual. Check the footer for the exact source/version and date โ€” I'm just here to make it cute. Now go publish something iconic! ๐Ÿ’–โœจ

๐Ÿ“ฆ where this page comes from