How to organize crate with circular dependencies

So I have a slog crate, that by itself does not have any direct dependencies. However, for testing, it's convenient to pull in crates that depend on the slog itself.

So the slog/Cart.toml is:

(...)
[dev-dependencies]
slog-term = "2"
slog-async = "2"
(...)

Both slog-term and slog-async depend directly on slog itself.

I use to make it all work with .cargo/config:

paths = [ "." ]

that was overwritting dependency of slog-term and slog-async to use the local version of slog.

However this recently broke for cargo publish.

$ cargo publish
(...)

error: failed to verify package tarball


Caused by:
  package collision in the lockfile: packages slog v2.3.2 (file:///home/dpc/lab/slog/slog) and slog v2.3.2 (file:///home/dpc/lab/slog/slog/target/package/slog-2.3.2) are different, but only one can be written to lockfile unambigiously

So, I'd like to ask for advice here. What are my best options to organizing it. Do I have to move my tests out of the slog repo itself?

1 Like

Assuming these crates are all in the same repository, you can simultaneously depend on a crate via a version and a path. The version is used when slog is pulled from crates.io, and the path dependency is used when building slog directly:

[dev-dependencies]
slog-term = { version = "2", path = "../slog-term" }

See the openssl repo for an example:

https://github.com/sfackler/rust-openssl/blob/master/openssl/Cargo.toml#L26

It is a little odd that you need to include other crates to test your crate. Can't you test it internally? Also where are the tests located on the repo?