Answer#
Publishing to crates.io cannot be undone: a version can be yanked (hidden from new projects) but never replaced or deleted. Two commands let you see exactly what would happen first, and neither uploads anything.
How to do it#
- Fill in the metadata in
Cargo.toml. crates.io needsdescriptionandlicense(orlicense-file);repository,documentationandreadmeare optional but expected.
[package]
name = "tinycalc"
version = "0.1.0"
edition = "2024"
description = "A tiny calculator library"
license = "MIT"- List the files that will be in the package. Check that nothing private (keys, test data) is in it.
> cargo package --list
warning: manifest has no documentation, homepage or repository
|
= note: see https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info
Cargo.lock
Cargo.toml
Cargo.toml.orig
README.md
src\lib.rs- Run the dry run. It builds the package the way it would be uploaded, compiles it in a clean folder, and stops at the upload step.
> cargo publish --dry-run
Updating crates.io index
warning: manifest has no documentation, homepage or repository
|
= note: see https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info
Packaging tinycalc v0.1.0 (C:\dev\pkg)
Packaged 5 files, 1.1KiB (790B compressed)
Verifying tinycalc v0.1.0 (C:\dev\pkg)
Compiling tinycalc v0.1.0 (C:\dev\pkg\target\package\tinycalc-0.1.0)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.49s
Uploading tinycalc v0.1.0 (C:\dev\pkg)
warning: aborting upload due to dry run- When both are clean, log in once with
cargo login(the token comes from your crates.io account) and runcargo publish.
Common mistakes#
- Reading the dry-run warning about "no documentation, homepage or repository" as an error. It is advice; adding
repository = "..."removes it. - Publishing with uncommitted changes. Cargo refuses unless you pass
--allow-dirty, which the examples above used only because the demo folder is not a real repository. - Choosing a crate name without checking it is free. The name is yours only once the first publish succeeds.
Related questions#
Can I take back a published version?#
cargo yank --version 0.1.0 stops new projects from choosing it. Existing projects that already locked it keep working.