Skip to content

Unable to use libp2p 0.49.0 plus libp2p-swarm-derive while publishing a library #3176

Description

@joao-paulo-parity

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions