CARGO-PUBLISH(1)

πŸ“¦ version 1.92.0, in ubuntu resolute

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

  1. Performs a few checks, including:
    • Checks the package.publish key in the manifest for restrictions on which registries you're allowed to publish to. πŸ‘€
  2. Create a .crate file by following the steps in cargo-package(1). πŸŽ€
  3. Upload 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'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. πŸ™ˆ
  • --index index β€” the URL of the registry index you wanna use.
  • --registry registry β€” 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 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 publishes to that registry. Otherwise it falls back to the default registry, which is defined by the registry.default <https://doc.rust-lang.org/cargo/reference/config.html#registrydefault> config key β€” and that defaults to crates-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. Peep cargo-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 --workspace flag. 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 πŸ¦‹

  • --target triple β€” 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-dir directory β€” the 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 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.

  • -F features, --features features β€” a space- or comma-separated list of features to activate. Features of workspace members can be enabled with package-name/feature-name syntax. 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-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 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 --locked and --offline at the same time. Two-for-one. πŸ’…
  • --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 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 ⭐

  • -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 the provided value. If a string default is provided, it sets the value back to defaults. Should not be 0. 🚫
  • --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 the term.verbose config value <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 <https://doc.rust-lang.org/cargo/reference/config.html>. 🀫
  • --color when β€” 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 +stable or +nightly). See the rustup documentation <https://rust-lang.github.io/rustup/overrides.html> for more info 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 <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides> for more info.
  • -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 <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.
  • -Z flag β€” unstable (nightly-only) flags to Cargo. Run cargo -Z help for 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 🌸

  1. 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