8

I'm trying to use actix-web and reqwest crates in the same project, but they depend on different versions of tokio.

Apparently, Cargo can't select a version of tokio which would satisfy all direct dependencies, but I'm not even using those dependencies in the same context:

  • actix-web is for server REST API implementation
  • reqwest is for system tests only

Cargo.toml:

[package]
name = "test-cargo"
version = "0.1.0"
edition = "2018"

[dependencies]
actix-rt = "1.0.0"
actix-web = "2.0.0-alpha.6"

[dev-dependencies]
reqwest = "0.10.0-alpha.2"

Output of cargo build:

Updating crates.io index
error: failed to select a version for `tokio`.
    ... required by package `reqwest v0.10.0-alpha.2`
    ... which is depended on by `test-cargo v0.1.0 (/workspaces/test-cargo)`
versions that meet the requirements `= 0.2.0-alpha.6` are: 0.2.0-alpha.6

all possible versions conflict with previously selected packages.

  previously selected package `tokio v0.2.4`
    ... which is depended on by `actix-rt v1.0.0`
    ... which is depended on by `actix-web v2.0.0-alpha.6`
    ... which is depended on by `test-cargo v0.1.0 (/workspaces/test-cargo)`

failed to select a version for `tokio` which could resolve this conflict

I've thought of some workarounds, but they are all unacceptable:

  • downgrade one of the direct dependencies so that tokio versions would match — then my dependencies are not the versions I want.
  • replace reqwest with a similar crate which doesn't depend on tokio — then my dependencies are not the crates I want.
  • move tests with reqwest to a separate package
artin
  • 1,764
  • 1
  • 17
  • 23
  • In general, Cargo handles this fine (see [Why is a trait not implemented for a type that clearly has it implemented?](https://stackoverflow.com/q/44437123/155423)). The problem is that the resolver has some issues with the prerelease version of crates. – Shepmaster Dec 18 '19 at 20:52
  • For your *specific* issue and crates, you can depend on the `reqwest` crate's master branch instead of a released version, or downgrade to `reqwest` 0.9, which will pull in `tokio` 0.1 (and you'll have `tokio` 0.2 for your main app). – Shepmaster Dec 18 '19 at 20:53
  • @Shepmaster I've tried to use stable version of `reqwest` and yeah it works. Do we have issue in cargo repository for that?.. – artin Dec 18 '19 at 21:09
  • So, cargo can match `tokio` versions `0.2.4` - `0.1.7`, but not `0.2.4` - `=0.2.0-alpha.6`. Probably because of `=`?. – artin Dec 18 '19 at 21:30
  • 2
    @Shepmaster Are you sure cargo cannot match `tokio` versions because one of them is prerelease `-alpha.6`? Because I still can add `0.2.0-alpha.6`, but not `=0.2.0-alpha.6`, so I believe issue in that strict version sign `=`. Let's update title to more general: "How to have multiple *incompatible* versions of the same indirect dependency?" – artin Dec 19 '19 at 08:16

0 Answers0