CARGO-PUBLISH(1)
β¨ NAME β¨
okay so cargo-publish is the General Commands Manual page that does exactly what it says on the tin, bestie: it lets you upload a package to the registry π no cap, that's the whole NAME section. π«Ά
π SYNOPSIS π
cargo publish [options]
π« DESCRIPTION π«
so this command is the main character of publishing, fr fr. It creates a distributable, compressed .crate file containing the source code of the package in the current directory, and then it uploads that file to a registry. The default registry is https://crates.io π. Here's the whole glow-up routine it performs, step by step:
- Performs a few checks, including:
- Checks the
package.publishkey in the manifest for restrictions on which registries you're allowed to publish to. π
- Checks the
- Create a
.cratefile by following the steps incargo-package(1). π - Upload 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'll need to check for completion manually. This timeout does not affect the upload. β³
also, this command requires you to be authenticated using cargo-login(1) or environment variables of the registry.token (https://doc.rust-lang.org/cargo/reference/config.html#registrytoken) and registries.<name>.token (https://doc.rust-lang.org/cargo/reference/config.html#registriesnametoken) config fields. π
and if you want the full tea, see the reference https://doc.rust-lang.org/cargo/reference/publishing.html for more details about packaging and publishing. π
β¨ OPTIONS β¨
π Publish Options π
--dry-runβ runs every single check like a full rehearsal, but doesn't actually upload anything. It's the dress rehearsal, bestie. π--no-verifyβ skips the "let's build the contents to make sure they're not cursed" step. No building, no verifying.--allow-dirtyβ lets Cargo package up a working directory that still has uncommitted VCS changes. Messy girl behavior, but okay. π--indexindex β the URL of the registry index you wanna use.--registryregistry β the name of the registry to publish to. Registry names live in Cargo config files <https://doc.rust-lang.org/cargo/reference/config.html>. If you don't specify one, and there's apackage.publish<https://doc.rust-lang.org/cargo/reference/manifest.html#the-publish-field> field inCargo.tomlwith a single registry, then it publishes to that registry. Otherwise it falls back to the default registry, which is defined by theregistry.default<https://doc.rust-lang.org/cargo/reference/config.html#registrydefault> config key β and that defaults tocrates-io. π
πΈ Package Selection πΈ
Okay so here's the tea: by default, when you don't give any package selection options, which packages get selected depends on the manifest file that's selected (which is based on the current working directory if you didn't pass --manifest-path). If the manifest is the root of a workspace, then the workspace's default members get selected. Otherwise, only the package defined by that manifest gets selected. π«Ά
The default members of a workspace can be set explicitly with the workspace.default-members key in the root manifest. If that's not set, then a virtual workspace includes all workspace members (same energy as passing --workspace), and a non-virtual workspace includes only the root crate itself.
-p*spec*β¦,--package*spec*β¦ β publish only the packages you name. Peepcargo-pkgid(1)for the SPEC format. You can pass this flag multiple times, and it supports common Unix glob patterns like*,?and[]. BUT β and this is important β to stop your shell from expanding glob patterns before Cargo even gets to handle them, you must wrap each pattern in single quotes or double quotes. π₯--workspaceβ publish every member in the workspace. All of them. Periodt.--allβ deprecated alias for--workspace. It's giving legacy. π--exclude*SPEC*β¦ β excludes the packages you name. Has to be used together with the--workspaceflag. Can be specified multiple times and supports common Unix glob patterns like*,?and[]. And again β 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 β publish for the specified target architecture. This flag can 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 gets internally substituted by the host's target. This is particularly useful if you're cross-compiling some crates and don't wanna specify your host's machine as a target (say, an xtask in a shared project that many different hosts might work on). π- A path to a custom target specification. See Custom Target Lookup Path <https://doc.rust-lang.org/rustc/targets/custom.html#custom-target-lookup-path> for more info.
This may also be specified with the build.target config value <https://doc.rust-lang.org/cargo/reference/config.html>.
Heads up: specifying this flag makes Cargo run in a different mode where the target artifacts get placed in a separate directory. See the build cache <https://doc.rust-lang.org/cargo/reference/build-cache.html> documentation for more deets.
--target-dirdirectory β the 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 let you control which features get enabled. When you don't give any feature options, 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 β a space- or comma-separated list of features to activate. Features of workspace members can be enabled withpackage-name/feature-namesyntax. This flag may be specified multiple times, and that enables all the features you specified.--all-featuresβ activates all available features of all selected packages. Go big or go home. β¨--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 these scenarios pops up:- 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, like in CI pipelines. π€
--offlineβ stops 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 isn't 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 <https://doc.rust-lang.org/cargo/reference/config.html>.
--frozenβ equivalent to specifying both--lockedand--offlineat the same time. Two-for-one. π--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 an 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 the 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 β
-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 the provided value. If a stringdefaultis provided, it sets the value back to defaults. Should not be0. π«--keep-goingβ builds 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 π
-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 <https://doc.rust-lang.org/cargo/reference/config.html>.-q,--quietβ do not print cargo log messages. May also be specified with theterm.quietconfig value <https://doc.rust-lang.org/cargo/reference/config.html>. π€«--colorwhen β controls 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>. π
π«Ά 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+stableor+nightly). See the rustup documentation <https://rust-lang.github.io/rustup/overrides.html> for more info 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 <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides> for more info.-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>). π
-h,--helpβ prints help information.-Zflag β unstable (nightly-only) flags to Cargo. Runcargo -Z helpfor details.
π ENVIRONMENT π
See the reference <https://doc.rust-lang.org/cargo/reference/environment-variables.html> for details on environment variables that Cargo reads. π
β¨ EXIT STATUS β¨
okay bestie, the exit codes are literally so simple, here's the vibe check π
0β Cargo succeeded. ate and left no crumbs π101β Cargo failed to complete. not the moment π
πΈ EXAMPLES πΈ
- Publish the current package:
cargo publish
like... that's it. that's the whole thing. go off π
π¦ SEE ALSO π¦
and that's a wrap on the whole page, bestie π this was CARGO-PUBLISH(1), from the Cargo source + version, dated like the rest of the docs. slay, go publish something iconic πβ¨
π¦ where this page comes from
- ubuntu resolute: cargo-1.92 1.92.0+dfsg-0ubuntu2 Β· 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