Dependency conflict

Hey folks, newbee rust question.
I created a blank project, added two dependencies:

tensorflow = "0.16"
rust_tokenizers = "6.2.3"

and I'm getting error:

cargo build
    Updating index
error: failed to select a version for `protobuf`.
    ... required by package `tensorflow v0.16.0`
    ... which is depended on by `test v0.1.0`
versions that meet the requirements `=2.17.0` are: 2.17.0

all possible versions conflict with previously selected packages.

  previously selected package `protobuf v2.22.1`
    ... which is depended on by `rust_tokenizers v6.2.3`
    ... which is depended on by `test v0.1.0`

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

I understand, that two crates depend on different versions of the same third crate, but I'm not sure what to do next, is this kind of issue cargo cannot handle at all? Are there any workarounds?
Would appreciate any help.

Normally cargo will deal with these sorts of version conflicts by trying hard to find a common version, falling back to compiling both crates separately. However in this case, the tensorflow crate requires exactly v2.17.0 of protobuf while rust_tokenizers requires something compatible with v2.22.1 (i.e. something greater or equal to 2.22.1 and less than 3.0).

The ideal solution is to create an issue against the tensorflow crate and ask them to create a new release which relaxes their requirements (i.e. remove this "=") so cargo can choose a compatible version.

Normally you wouldn't run into issues like this because libraries should aim to be flexible in which dependency versions they require.

There are also ways of overriding dependencies, but that's mainly used as a temporary mechanism during development (e.g. you forked the tensorflow crate and want to use your version while waiting for the PR to merge) or as an escape hatch/quick hack if you just want to force things to work.


Thanks, Michael!
So, do I understand correctly, asking tensorflow folks to update their dep definition is the only option I have? Could playing with [patch] help here somehow? I don't think I have enough rust/cargo knowledge yet to figure out how I'd use it to resolve this issue :frowning:

You could get a local copy of the tensorflow crate, change their dependency requirement, and use [patch] to use your version.

But by the stated requirements of these crates, they're incompatible with each other.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.