I have a library crate and want to publish it on crates.io.
I created my project with cargo new my_lib --lib
.
My project structure looks like this:
my_lib/
├─ src/
│ ├─ lib.rs
├─ examples/
│ ├─ example.rs
├─ benches/
│ ├─ benchmark.rs
├─ .gitignore
├─ Cargo.toml
├─ README.md
├─ config.json
My Cargo.toml
looks like this:
[package]
name = "my_lib"
version = "0.1.0"
edition = "2018"
description = "Does cool stuff."
license = "MIT"
readme = "README.md"
repository = "https://git.example.com/my_lib"
homepage = "https://git.example.com/my_lib"
include = ["./config.json"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rand = "0.8.4"
regex = "1"
serde_json = "1.0.64"
When I run cargo publish --dry-run
, I get:
error: failed to verify package tarball
Caused by:
failed to parse manifest at `/home/me/my_lib/target/package/my_lib-0.1.0/Cargo.toml`
Caused by:
no targets specified in the manifest
either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present
It tells me to create a src/lib.rs
file, but it's there!
If I try to specify the lib.rs
file like this:
...
[lib]
path = "src/lib.rs"
...
I get a new error:
error: couldn't read src/lib.rs: No such file or directory (os error 2)
error: aborting due to previous error
error: could not compile `my_lib`
Why won't it let me push my library crate?