Summary
When trying to publish a library which uses libp2p 0.49.0 and libp2p-swarm-derive, Cargo will pick libp2p-swarm-derive 0.30.2, which is incompatible with libp2p 0.49.0. It should instead pick libp2p-swarm-derive 0.30.1, but it doesn't do that even though the version is set to 0.31.0 in the Cargo.toml of libp2p 0.49.0. EDIT: Not actually true, see #3176 (comment).
The problem's description is expanded in the README of https://github.com/joao-paulo-parity/libp2p-troubleshoot. That repository contains an example project and sample commands that you can run to reproduce this problem.
Expected behaviour
I should be able to publish a library which uses libp2p 0.49.0 and libp2p-swarm-derive
Actual behaviour
I'm unable to achieve the expected behaviour
Possible Solution
The crux of the problem is that cargo picks libp2p-swarm-derive 0.30.2 instead of libp2p-swarm-derive 0.30.1, even though the latter is set in the Cargo.toml of libp2p 0.49.0. Therefore the solutions entail somehow making cargo resolve 0.30.1 for libp2p 0.49.0.
Option 1: Perhaps (i.e. I haven't actually verified this) cargo thinks that it's fine to use libp2p-swarm-derive 0.30.2 because it's a patch bump from 0.30.1, i.e. theoretically semver-compatible with libp2p 0.49.0. Thus if we were to turn the current libp2p-swarm-derive 0.30.2 release into 0.31.0 and yank 0.30.2, that would maybe cause cargo to choose 0.30.1, which would effectively solve the problem.
Option 2: A workaround would be to include an [[example]] within the library to be published. That would cause cargo to not ignore the Cargo.lock and therefore make it correctly pick libp2p-swarm-derive 0.30.1 during publish. This is mentioned in https://doc.rust-lang.org/cargo/reference/manifest.html:
A minimized Cargo.lock is automatically included if the package contains a binary or example target
While that would fix the version resolution during publish, I'm still unsure if it would be effective during consumption of the library. I might test this later and report it back here.
I think Option 1 would be preferrable, but as already mentioned I don't know yet if it would work in practice. I might also try this out later.
Summary
When trying to publish a library which uses
libp2p 0.49.0andlibp2p-swarm-derive, Cargo will picklibp2p-swarm-derive 0.30.2, which is incompatible withlibp2p 0.49.0.It should instead pickEDIT: Not actually true, see #3176 (comment).libp2p-swarm-derive 0.30.1, but it doesn't do that even though the version is set to0.31.0in theCargo.tomloflibp2p 0.49.0.The problem's description is expanded in the README of https://github.com/joao-paulo-parity/libp2p-troubleshoot. That repository contains an example project and sample commands that you can run to reproduce this problem.
Expected behaviour
I should be able to publish a library which uses
libp2p 0.49.0andlibp2p-swarm-deriveActual behaviour
I'm unable to achieve the expected behaviour
Possible Solution
The crux of the problem is that
cargopickslibp2p-swarm-derive 0.30.2instead oflibp2p-swarm-derive 0.30.1, even though the latter is set in theCargo.tomloflibp2p 0.49.0. Therefore the solutions entail somehow makingcargoresolve0.30.1forlibp2p 0.49.0.Option 1: Perhaps (i.e. I haven't actually verified this)
cargothinks that it's fine to uselibp2p-swarm-derive 0.30.2because it's a patch bump from0.30.1, i.e. theoretically semver-compatible withlibp2p 0.49.0. Thus if we were to turn the currentlibp2p-swarm-derive 0.30.2release into0.31.0and yank0.30.2, that would maybe causecargoto choose0.30.1, which would effectively solve the problem.Option 2: A workaround would be to include an
[[example]]within the library to be published. That would causecargoto not ignore theCargo.lockand therefore make it correctly picklibp2p-swarm-derive 0.30.1during publish. This is mentioned in https://doc.rust-lang.org/cargo/reference/manifest.html:While that would fix the version resolution during publish, I'm still unsure if it would be effective during consumption of the library. I might test this later and report it back here.
I think Option 1 would be preferrable, but as already mentioned I don't know yet if it would work in practice. I might also try this out later.