CARGO-PUBLISH(1)

πŸ“¦ version 1.83.0, in ubuntu jammy, ubuntu noble

okay so you're reading the CARGO-PUBLISH(1) page from the General Commands Manual, and bestie, this one is a whole journey. Buckle up. πŸŽ€


✨ NAME ✨

cargo-publish β€” uploads a package to the registry. that's the whole vibe. πŸ“¦


πŸ¦‹ SYNOPSIS πŸ¦‹

cargo publish [options]

πŸ’– DESCRIPTION πŸ’–

okay so here's the tea. this command creates a distributable, compressed .crate file with the source code of the package sitting in your current directory, and then it uploads that thing to a registry. the default registry is https://crates.io. slay.

here's the step-by-step, no skips:

  1. it does a few checks, including:
    • it checks the package.publish key in the manifest, because that key is the one holding the restrictions on which registries you're even 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. heads up: the server will do additional checks on the crate, so it's not just you out here verifying things.
  4. the client will poll, waiting for the package to appear in the index, and it may timeout. if that happens, you'll need to check for completion manually. and listen β€” this timeout does not affect the upload. the upload already happened, bestie, it's fine. πŸ’…

this command requires you to be authenticated, either with the --token option or by using cargo-login(1).

for more details about packaging and publishing, see the reference at https://doc.rust-lang.org/cargo/reference/publishing.html.


πŸ”₯ OPTIONS πŸ”₯

🌸 Publish Options 🌸

  • --dry-run β€” does all the checks but doesn't upload anything. a little dress rehearsal, a little test run, no commitment. πŸ™ˆ
  • --token token β€” the API token to use when authenticating. this overrides the token stored in the credentials file (which is the file that cargo-login(1) creates for you).
    • Cargo config environment variables (see https://doc.rust-lang.org/cargo/reference/config.html) can be used to override the tokens stored in the credentials file. the token for crates.io can be specified with the CARGO_REGISTRY_TOKEN environment variable. tokens for other registries can 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. skipping the vibe check, risky but okay. 😭
  • --allow-dirty β€” allows working directories with uncommitted VCS changes to be packaged. yes bestie, you can publish with uncommitted chaos lying around. 🫢
  • --index index β€” the URL of the registry index to use.
  • --registry registry β€” the name of the registry to publish to. registry names are defined in Cargo config files (see https://doc.rust-lang.org/cargo/reference/config.html). if it's not specified, and there's a package.publish field in Cargo.toml (see https://doc.rust-lang.org/cargo/reference/manifest.html#the-publish-field) with a single registry, then it'll publish to that registry. otherwise it uses the default registry, which is defined by the registry.default config key (see https://doc.rust-lang.org/cargo/reference/config.html#registrydefault), and that defaults to crates-io.

πŸŽ€ Package Selection πŸŽ€

by default, the package in the current working directory is the chosen one. the -p flag lets you pick a different package inside a workspace. πŸ‘‘

  • -p spec, --package spec β€” the package to publish. see cargo-pkgid(1) for the SPEC format.

πŸ’œ 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.
  • --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 (see 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 are enabled. when no feature options are given, the default feature is activated for every selected package.

see the features documentation at 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 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. all of them. the whole menu. 😌
  • --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 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 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 (see https://doc.rust-lang.org/cargo/reference/config.html).

  • --frozen β€” equivalent to specifying both --locked and --offline. two for one, iconic.
  • --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 the 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 (see https://doc.rust-lang.org/book/appendix-07-nightly-rust.html) and requires the -Z unstable-options flag to enable (see #14421 at 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 (see 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 β€” 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. main character energy: it refuses to give up. πŸ‘‘

🌈 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 (see 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 (see https://doc.rust-lang.org/cargo/reference/config.html).
  • --color when β€” 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 (see 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 at https://rust-lang.github.io/rustup/overrides.html for more information 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 at https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides for more information.
  • -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 (see https://doc.rust-lang.org/book/appendix-07-nightly-rust.html) and requires the -Z unstable-options flag to enable (see #10098 at https://github.com/rust-lang/cargo/issues/10098). 🧚
  • -h, --help β€” prints help information. the classic. πŸ’…
  • -Z flag β€” unstable (nightly-only) flags to Cargo. run cargo -Z help for details.

🌸 ENVIRONMENT 🌸

see the reference at https://doc.rust-lang.org/cargo/reference/environment-variables.html for details on environment variables that Cargo reads.


πŸ‘‘ EXIT STATUS πŸ‘‘

  • 0: Cargo succeeded. πŸŽ‰
  • 101: Cargo failed to complete. 😭

✨ EXAMPLES ✨

Okay bestie, real talk, this part is short and sweet because the command does the heavy lifting for you. Here's the whole vibe:

  1. Publish the current package:
cargo publish

That's it. That's the post. You're in the package directory, you run it, the world gets your code. Main character behaviour fr fr. πŸ’–

No cap though, peep the earlier sections before you send it β€” publishing is one of those things you can't just take back like a risky text. πŸ™ˆ

πŸ‘€ SEE ALSO πŸ‘€

Because no queen works alone, here's the little squad that hangs out with this page:

  • cargo(1) β€” the big one, the mothership, the whole reason we're here πŸ’…
  • cargo-package(1) β€” for when you wanna bundle it up before you yeet it out there πŸŽ€
  • cargo-login(1) β€” so the registry actually knows it's you, iykyk πŸ”‘

and that's the whole page, babe. it's part of the cargo manual, footer reads CARGO-PUBLISH(1) β€” cargo's own docs, dated and versioned right there with it. go publish something iconic. you got this. πŸ‘‘πŸ’œπŸ¦‹

πŸ“¦ where this page comes from