CARGO-PUBLISH(1)
cargo-publish ๐โจ
the cargo-publish page, from the General Commands Manual (section 1) โ aka the moment your little crate leaves the nest and goes to live on the internet ๐ฆ
NAME ๐
cargo-publish โ Upload a package to the registry
SYNOPSIS ๐
cargo publish [options]
DESCRIPTION ๐
okay bestie, listen. This command does the big dramatic thing: it builds a distributable, compressed .crate file out of the source code of the package sitting in the current directory, and then it uploads that thing to a registry. The default registry is <https://crates.io>. ๐
Here's the whole glow-up journey, step by step:
- It performs a few checks, including:
- It checks the
package.publishkey in the manifest for restrictions on which registries you are 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. (yes, more checks, everyone's checking, it's giving airport security โ๏ธ)
- 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. Good news tho: this timeout does not affect the upload. ๐ซถ
๐ the vibe check: this command requires you to be authenticated usingcargo-login(1)or environment variables of theregistry.token<https://doc.rust-lang.org/cargo/reference/config.html#registrytoken> andregistries.<name>.token<https://doc.rust-lang.org/cargo/reference/config.html#registriesnametoken> config fields. No auth, no publish, periodt.
See the reference <https://doc.rust-lang.org/cargo/reference/publishing.html> for more details about packaging and publishing. it's literally the lore iykyk ๐โจ
โจ OPTIONS โจ
๐ Publish Options ๐
--dry-runโ Do all the checks but don't upload anything. It's giving rehearsal vibes, bestie. ๐--no-verifyโ Don't verify the contents by building them. No build check, just vibes. ๐--allow-dirtyโ Allow working directories with uncommitted VCS changes to be packaged. Yes, even if your git status is a mess. ๐ญ--indexindex โ The URL of the registry index to use. URL, bestie. ๐--registryregistry โ Name of the registry to publish to. Registry names are defined in Cargo config fileshttps://doc.rust-lang.org/cargo/reference/config.html. If not specified, and there is apackage.publishfield inCargo.tomlwith a single registry โ the docs for that field live athttps://doc.rust-lang.org/cargo/reference/manifest.html#the-publish-fieldโ then it will publish to that registry. Otherwise it will use the default registry, which is defined by theregistry.defaultconfig keyhttps://doc.rust-lang.org/cargo/reference/config.html#registrydefaultwhich defaults tocrates-io. Iconic default behavior. โจ
๐ธ 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.
-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. Quote those globs, bestie! ๐--workspaceโ Publish all members in the workspace. All of them. The whole squad. ๐ซถ--allโ Deprecated alias for--workspace. It still works but it's giving legacy energy. ๐--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. Again: quote your globs! โจ
๐ฆ Compilation Options ๐ฆ
--targettriple โ Publish for the specified target architecture. Flag may be specified multiple times. The default is the host architecture. The general format of the triple is<arch><sub>-<vendor>-<sys>-<abi>.
Possible values:
- Any supported target in
rustc --print target-list. "host-tuple", which will internally be substituted by the hostโs target. This can be particularly useful if youโre cross-compiling some crates, and donโt want to specify your hostโs machine as a target (for instance, anxtaskin a shared project that may be worked on by many hosts).- A path to a custom target specification. See Custom Target Lookup Path
https://doc.rust-lang.org/rustc/targets/custom.html#custom-target-lookup-pathfor more information.
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-dirdirectory โ Directory for all generated artifacts and intermediate files. May also be specified with theCARGO_TARGET_DIRenvironment variable, or thebuild.target-dirconfig valuehttps://doc.rust-lang.org/cargo/reference/config.html. Defaults totargetin the root of the workspace. Default istarget, periodt. โจ
๐ 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. Feature time, slay! ๐--all-featuresโ Activate all available features of all selected packages. ALL the features. ๐--no-default-featuresโ Do not activate the default feature of the selected packages. No defaults, only choices. ๐
๐ 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 gonna go look for it. ๐--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 bestie, this one's for you. โจ
--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. Beware the different resolution, bestie. ๐ญ
--frozenโ Equivalent to specifying both--lockedand--offline. Two-in-one combo. ๐ง
๐ Miscellaneous Options ๐
-jN,--jobsN โ Number of parallel jobs to run. May also be specified with thebuild.jobsconfig valuehttps://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. Don't you dare set it to0. ๐--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. Keep going, keep glowing. โจ
๐ 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 valuehttps://doc.rust-lang.org/cargo/reference/config.html. Spill the tea, Cargo. โ-q,--quietโ Do not print cargo log messages. May also be specified with theterm.quietconfig valuehttps://doc.rust-lang.org/cargo/reference/config.html. Shhh, no logs. ๐คซ--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. Color theory but make it Cargo. ๐จ
๐ 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 documentationhttps://rust-lang.github.io/rustup/overrides.htmlfor more information about how toolchain overrides work. Toolchain override realness. ๐ ๏ธ--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 sectionhttps://doc.rust-lang.org/cargo/reference/config.html#command-line-overridesfor more information. Config but make it CLI. โจ-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 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). Nightly only, bestie. ๐
-h,--helpโ Prints help information. Help is always there for you. ๐ซถ-Zflag โ Unstable (nightly-only) flags to Cargo. Runcargo -Z helpfor details. Nightly vibes only. โก
๐ ENVIRONMENT ๐
See the reference https://doc.rust-lang.org/cargo/reference/environment-variables.html for details on environment variables that Cargo reads. Env vars go brrr. โจ
๐ฆ EXIT STATUS ๐ฆ
0: Cargo succeeded. We love a zero. ๐101: Cargo failed to complete. Not the 101. ๐ญ
๐ EXAMPLES ๐
- Publish the current package:
cargo publish
๐ SEE ALSO ๐
cargo(1), cargo-package(1), cargo-login(1)
that's the whole CARGO-PUBLISH(1) vibe, bestie ๐ โ source/version and date are doing their lil footer thing where they belong โจ. mwah! ๐
๐ฆ where this page comes from
- ubuntu stonking: cargo-1.97 1.97.1+dfsg-0ubuntu1 ยท 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