Cargo publish with excluded benchmark — fails validation

Continuing the discussion from What to include when publishing a crate?, I've excluded benchmarks and interactive examples from my textwrap crate:

[package]
exclude = [".github/", ".gitignore", "benches/", "examples/", "fuzz/"]

Tests are still included so that projects that test the wider Rust ecosystem has an easy time running them. So far so good.

I'm using Criterion benchmarks and have configured them thus in my Cargo.toml:

[[bench]]
name = "linear"
harness = false

This also works fine until now. However, when I now try to cargo publish --dry-run, I run into trouble:

% cargo publish --dry-run
    Updating crates.io index
   Packaging textwrap v0.13.1 (/home/mg/src/textwrap)
   Verifying textwrap v0.13.1 (/home/mg/src/textwrap)
error: failed to verify package tarball

Caused by:
  failed to parse manifest at `/home/mg/src/textwrap/target/package/textwrap-0.13.1/Cargo.toml`

Caused by:
  can't find `linear` bench, specify bench.path

Has anybody found a nice workaround for this?

If it works identical to tests, then adding a path with the path to the bench file, allows you to publish the crate, even if the file is missing in the final crate.

https://github.com/jonasbb/serde_with/blob/a6228ea443dc8f7ac627eb344d23089121101144/Cargo.toml#L56-L59

2 Likes

Oh, that is great! Thank you, cargo publish --dry-run completed successfully when I specified the path.

:man_facepalming: I just read the last part again — I completely missed the part about specify bench.path. I think I stopped looking for clues when I read that the Cargo.toml couldn't be parsed.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.