CARGO-PUBLISH(1)
๐ 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:
- It runs a few checks, including:
- It checks the
package.publishkey in the manifest for restrictions on which registries you're allowed to publish to. ๐
- It checks the
- It creates a
.cratefile by following the steps incargo-package(1). ๐ - It uploads the crate to the registry. The server will perform additional checks on the crate. โ๏ธ
- 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. ๐ซ๐ค--tokentoken โ API token to use when authenticating. This overrides the token stored in the credentials file (which is created bycargo-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 theCARGO_REGISTRY_TOKENenvironment variable. Tokens for other registries may be specified with environment variables of the formCARGO_REGISTRIES_NAME_TOKENwhereNAMEis 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. ๐งผ--indexindex โ The URL of the registry index to use. ๐--registryregistry โ 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 apackage.publish<https://doc.rust-lang.org/cargo/reference/manifest.html#the-publish-field>field inCargo.tomlwith a single registry, then it will publish to that registry. Otherwise it will use the default registry, which is defined by theregistry.default<https://doc.rust-lang.org/cargo/reference/config.html#registrydefault>config key which defaults tocrates-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-workspaceflag to enable. See<https://github.com/rust-lang/cargo/issues/10948>for more information. โ ๏ธ
-p*spec*โฆ,--package*spec*โฆ โ Publish only the specified packages. Seecargo-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-workspaceflag 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-workspaceflag 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--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. ๐ซ 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-workspaceflag to enable. See<https://github.com/rust-lang/cargo/issues/10948>for more information. โ ๏ธ
โ๏ธ Compilation Options โ๏ธ
--targettriple โ Publish 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 thebuild.targetconfig 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-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 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. ๐
-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 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. ๐--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. ๐๏ธ
--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 thecargo-fetch(1)command to download dependencies before going offline. โ ๏ธ May also be specified with thenet.offlineconfig value<https://doc.rust-lang.org/cargo/reference/config.html>. ๐ง--frozenโ Equivalent to specifying both--lockedand--offline. ๐ง--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-optionsflag to enable (see #14421<https://github.com/rust-lang/cargo/issues/14421>). โ ๏ธ
๐ฒ 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 provided value. If a stringdefaultis provided, it sets the value back to defaults. Should not be0. ๐งต--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 dependenciesfailsandworks, one of which fails to build,cargo publish -j1may or may not build the one that succeeds (depending on which one of the two builds Cargo picked to run first), whereascargo publish -j1 --keep-goingwould 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 theterm.verboseconfig 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 theterm.quietconfig value <https://doc.rust-lang.org/cargo/reference/config.html>. ๐คซ--colorwhen โ 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 theterm.colorconfig 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 tocargostarts with+, it's interpreted as a rustup toolchain name (like+stableor+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โจ. ๐ฆ--configKEY=VALUE or PATH โ overrides a Cargo configuration value. The argument should be in TOML syntax ofKEY=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. ๐ง-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 searched for discovering.cargo/config.toml, for example. This option must appear before the command name, likecargo -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. ๐-Zflag โ unstable (nightly-only) flags to Cargo. Runcargo -Z helpfor 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 ๐
- 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
- ubuntu jammy: cargo-1.89 1.89.0+dfsg~24.04-0ubuntu0.22.04.2 ยท Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.89 1.89.0+dfsg~24.04-0ubuntu0.24.04.2 ยท 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