CARGO-PUBLISH(1)

๐Ÿ“ฆ version 1.96.1, in ubuntu stonking

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:

  1. It performs a few checks, including:
    • It checks the package.publish key in the manifest for restrictions on which registries you are 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. The server will perform additional checks on the crate. (yes, more checks, everyone's checking, it's giving airport security โœˆ๏ธ)
  4. 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 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. 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. ๐Ÿ˜ญ
  • --index index โ€” The URL of the registry index to use. URL, bestie. ๐Ÿ”—
  • --registry registry โ€” 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 a package.publish field in Cargo.toml with a single registry โ€” the docs for that field live at https://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 the registry.default config key https://doc.rust-lang.org/cargo/reference/config.html#registrydefault which defaults to crates-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. See cargo-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 --workspace flag. 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 ๐Ÿฆ‹

  • --target triple โ€” 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, an xtask in 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-path for 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-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 https://doc.rust-lang.org/cargo/reference/config.html. Defaults to target in the root of the workspace. Default is target, 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.

  • -F features, --features features โ€” 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. 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-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. It's gonna go look for it. ๐Ÿ”
  • --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 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 --locked and --offline. Two-in-one combo. ๐ŸงŠ

๐ŸŒŸ 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 provided value. If a string default is provided, it sets the value back to defaults. Should not be 0. Don't you dare set it to 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. 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 the term.verbose config value https://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 the term.quiet config value https://doc.rust-lang.org/cargo/reference/config.html. Shhh, no logs. ๐Ÿคซ
  • --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 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 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 information about how toolchain overrides work. Toolchain override realness. ๐Ÿ› ๏ธ
  • --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 information. Config but make it CLI. โœจ
  • -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). Nightly only, bestie. ๐ŸŒ™

  • -h, --help โ€” Prints help information. Help is always there for you. ๐Ÿซถ
  • -Z flag โ€” Unstable (nightly-only) flags to Cargo. Run cargo -Z help for 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 ๐Ÿ“

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