Rust how to define benchmark only dependencies in Cargo?

Viewed 172
2 Answers

Benchmark dependencies don't get their own section in cargo.toml. You need to put them in the [dev-dependencies] along with test dependencies.

As pointed out by @Dogbert in the comments, there is a related issue: https://github.com/rust-lang/cargo/issues/1596

There is also this useful suggestion to move the benchmarks/quickcheck into a separate repository and use the public interface.

@bluss bluss commented on 2 May 2020 For such cases like benchmarks, for now I'd recommend using an additional non-published crate that you keep in the same repository, that depends on your library and contains the benchmarks. It will need to use the public APIs, of course, but that's ok in most cases. As an example of this, ndarray has a subdirectory for blas-tests that runs tests that depend on BLAS.

Related