Cargo.toml crate dependency version problem


#1

I’m using the redis-0.5.2 package which only works with url-x.y.z, x.y.z < 1.0.0. When compiling my library both url-0.5.9 and url-1.0.0. are downloaded and linking fails when redis is tried to be linked with url-1.0.0. Other packages however may depend on url-1.0.0. Two questions:

  1. Is there a way to force redis being linked (statically…?) with url-0.5.9, whilst other packages use url-1.0.0? If not:…
  2. Is there a way to stop downloading url-1.0.0 under all circumstances?

Thanks.


#2

I’m working on pushing out a new release of Redis working with url 1.0.0


#3

Thanks for your effort!

Do you have an idea how to continue my development based on the existing redis version in the meantime?


#4

You can depend on the git version:

redis = { git = "https://github.com/mitsuhiko/redis-rs", branch = "updated-url" }

This will compile with url 1.0.0

Or clone the master branch, change the dependencies and use a path dependency to redis-rs


#5

Works, thanks jer!


#6

cc @llogiq awesome rust community


#7

:sunny:


#8

Just for explanation, the root problem is not you using a newer url version, but the released redis-rs using an url = "*" dependency, which means that it was fine with any version, including breaking new versions. If it did declare (e.g.) url = "0.5.0", Cargo would have downloaded both 0.5.x and 1.0.0 and everything should have worked fine: because url isn’t linking to any non-Rust libraries, it’ll just be compiled into the output in two different versions.

IIRC, these kinds of dependencies are now disallowed for newly published crates.


#9

@birkenfeld Thanks. I tried that avenue: I corrected redis’ url = “*” as you suggested and redis per se compiled fine indeed. However, my own developed library, depending on redis, caused me problems: both url versions were downloaded into my crate dependencies (…probably as you suggest…) where the linker then was trying to link redis with the newer (yet incompatible) version… With jer’s suggestion I can go ahead now.


#10

That should not happen. Did your own library depend on the correct redis version (the one you modified to have the correct dependency)?


#11

With my current (by-me-slightly-modified) Cargo.toml in redis-0.5.2:

[dependencies]
sha1 = "*"
#url = "0.5.9"
url = "< 1.0.0"
rustc-serialize = "*"

it still wanted to link with url-1.0.0; swapping comments made no difference… Note: redis per se compiled fine, the problem started with my dependency on it…


#12

And that’s exactly what I wanted to know: how did you depend on it?


#13

My library’s Cargo.toml:

[dependencies]
url = "*"
redis = "0.5.2"

caused problems. With:

[dependencies]
url = "*"
redis = { git = "https://github.com/mitsuhiko/redis-rs", branch = "updated-url" }

it now works.


#14

Okay. It would also work with

redis = { git = "https://github.com/mitsuhiko/redis-rs" }

as the dependency is fixed in master to url = "0.5.4". That would trigger the case I was referring to, where redis uses the 0.5.9 version, and your crate can still use 1.0.0.


#15

Thanks!


#16

I finally published a new version with fixed dependency versions. Still the old url, but this should built without problems now.