yairchu
yairchu

Reputation: 24764

Why does cargo use a specific dependency version?

When trying to follow the instructions of the pathfinder library, i.e:

cd demo/native
cargo run --release

I get errors due to the compilation of the dependency winit version 0.19.3:

error[E0308]: mismatched types
   --> /Users/yairchu/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.19.3/src/platform/macos/view.rs:209:9
    |
205 | extern fn has_marked_text(this: &Object, _sel: Sel) -> BOOL {
    |                                                        ---- expected `bool` because of return type
...
209 |         (marked_text.length() > 0) as i8
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `i8`

If I try changing the version used to the latest (which works fine for me) by changing Cargo.toml:

--- a/demo/native/Cargo.toml
+++ b/demo/native/Cargo.toml
@@ -43,7 +43,7 @@ rev = "f3df871ac8c3926fe9106d86a3e51e20aa50d3cc"

 [dependencies.winit]
-version = "<0.19.4" # 0.19.4 causes build errors https://github.com/rust-windowing/winit/pull/1105
+version = "0.27.2"

I still get the same errors!

Interestingly, I notice this in cargo's output:

   Compiling winit v0.19.3
   Compiling winit v0.27.2

It appears to now be building both the version I specified and the old version.

I'm lost. Also using --verbose didn't help elucidate why cargo chooses to build this specific dependency.

Thanks! Rust noob

Upvotes: 0

Views: 1098

Answers (1)

yairchu
yairchu

Reputation: 24764

How can I find out why cargo chooses to build this library?

cargo tree elaborates on whose dependency is each sub-dependency.

Is it using two versions of the same library in one executable?

It is.

You can depend on different versions of the the same crate. This can be useful if you want to use one version of the dependency, but one of your own dependencies uses another version.

(thanks @Masklinn for the answers in the comments!)

Upvotes: 0

Related Questions