Sharing my experiencing of resolving dependencies

Now, I have demostrating the way I resolve an issue when compiling Rust code.

As Rust is a young language every aspect of it is in evalution so things will broke if the code you downloaded from the Internet is not new enough.

Today I wanted to try a bittorrent client written in Rust, and I found this one (there are something else that is more up-todate, but requires a POSIX system and I am in Windows).

First compile: FAIL

When you use the usual way (and following the project README), doing cargo build after git clone, you will get many error messages. As the exact error you may experienced will be depending on the actual compile order of the crates, I only pick up one as an example.

warning: build failed, waiting for other jobs to finish...
error[E0277]: the trait bound `Self: std::marker::Sized` is not satisfied
  --> C:\Users\Joe\.cargo\registry\src\\num-0.1.25\src\
22 | / pub trait Num: PartialEq + Zero + One
23 | |     + Add<Output = Self> + Sub<Output = Self>
24 | |     + Mul<Output = Self> + Div<Output = Self> + Rem<Output = Self>
25 | | {
...  |
30 | |     fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>;
31 | | }
   | |_^ `Self` does not have a constant size known at compile-time

My first response is jump into the code and added the Self: Sized trait bound.

But there are too many such errors. This wouldn’t work quickly enough. So I looked at the crate name num.

This is a very familiar crate and there are a lot of crates depending on it. This can’t be broken in reality.

The only explaination, is that the verson is too old and so it is no longer compiling by the new compiler.

Reseting dependencies

So, I looked at the Cargo.toml file, and figured out that the dependencies parts are

bencode = "0.1"
getopts = "0.2"
hyper = "0.5"
rand = "0.3"
rust-crypto = "0.2"
url = "0.2"

If the problem is the version specified here is too old, I can reset this to use the latest version. So I changed every version to "*". And to make the upgrade happen you need to delete the Cargo.lock file.

This time, all crates are built except the main crate itself. This is kind of expected: the new versions of crates are not necessory compatible with the main. Luckly there are only 5 such errors.

But instead of fixing those errors by investigating the differences of the APIs between versions, I tried to do something else. Can I specify a “just working” versions for each of those directely referenced crates?

By looking at the error messages I pointed out there are two crates that is not compatible: hyper and url.

Fixing versions

Now I change the Cargo.toml file as like:

bencode = "*"
getopts = "*"
hyper = "0.5"
rand = "*"
rust-crypto = "*"
url = "0.2"

Remove the Cargo.toml file again, building it gives me one error before building the main crate:

error: failed to run custom build command for `openssl-sys v0.6.7`

My previous experience told me that the openssl crate requires the library to be installed in my computer. It seems like I have to download this manually.

But wait. Last time we didn’t see any error until we reach the main crate. This means openssl crate was never needed until we lower the versions.

By looking at Cargo.toml I figured out that openssl was required by hyper 0.5, and the latest version is 0.12. So at some version in between, the dependency to openssl was removed.

Finally worked

So I tried a few times to build with different versions of hyper, and finished at hyper 0.10. This time I have got only 2 warnings. Mission accomplished!

Further beyound

I have not run the crate yet. Maybe there will be another advanture for me to make it working.

But this will be another story to tell…