Duplicate crate only during `cargo install` for stdg crate

I'm trying to install the stdg crate using the shell command cargo install stdg recommend on the project's github page [1].

The install fails with the following error:

error[E0308]: mismatched types
   --> /home/charetjc/.cargo/registry/src/github.com-1ecc6299db9ec823/stdg-0.2.0/src/main.rs:567:33
    |
567 | / ...                   &text_font
568 | | ...                       .clone()
569 | | ...                       .expect("text font must be given before text is drawn"),
    | |_________________________________________________________________________________^ expected struct `font_kit::loaders::freetype::Font`, found a different struct `font_kit::loaders::freetype::Font`
    |
    = note: expected reference `&font_kit::loaders::freetype::Font` (struct `font_kit::loaders::freetype::Font`)
               found reference `&font_kit::loaders::freetype::Font` (struct `font_kit::loaders::freetype::Font`)
    = note: perhaps two different versions of crate `font_kit` are being used?

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
error: failed to compile `stdg v0.2.0`, intermediate artifacts can be found at `/tmp/cargo-installYmiWtT`

Caused by:
  could not compile `stdg`.
(Click to expand full output of `cargo install stdg`)
 cargo install stdg                                                                                                                                                                                                                                                                                                          
    Updating crates.io index
  Installing stdg v0.2.0
   Compiling pkg-config v0.3.17
   Compiling cc v1.0.54
   Compiling libc v0.2.71
   Compiling autocfg v1.0.0
   Compiling cfg-if v0.1.10
   Compiling byteorder v1.3.4
   Compiling arrayvec v0.4.12
   Compiling semver-parser v0.7.0
   Compiling nodrop v0.1.14
   Compiling lazy_static v1.4.0
   Compiling log v0.4.8
   Compiling adler32 v1.1.0
   Compiling crc32fast v1.2.0
   Compiling maybe-uninit v2.0.0
   Compiling same-file v1.0.6
   Compiling bitflags v1.2.1
   Compiling float-ord v0.2.0
   Compiling arrayvec v0.5.1
   Compiling sw-composite v0.7.10
   Compiling typed-arena v2.0.1
   Compiling semver v0.9.0
   Compiling cmake v0.1.44
   Compiling inflate v0.4.5
   Compiling walkdir v2.3.1
   Compiling num-traits v0.2.12
   Compiling rustc_version v0.2.3
   Compiling servo-fontconfig-sys v4.0.9
   Compiling x11-dl v2.18.5
   Compiling deflate v0.7.20
   Compiling dirs-sys v0.3.5
   Compiling time v0.1.43
   Compiling dirs v1.0.5
   Compiling memmap v0.7.0
   Compiling dirs v2.0.2
   Compiling cast v0.2.3
   Compiling png v0.15.3
   Compiling euclid v0.20.13
   Compiling servo-freetype-sys v4.0.5
   Compiling expat-sys v2.1.6
   Compiling minifb v0.13.0
   Compiling freetype v0.4.1
   Compiling lyon_geom v0.14.1
   Compiling lyon_geom v0.15.3
   Compiling servo-fontconfig v0.4.0
   Compiling lyon_path v0.14.0
   Compiling font-kit v0.5.0
   Compiling font-kit v0.4.0
   Compiling raqote v0.7.14
   Compiling stdg v0.2.0
error[E0308]: mismatched types
   --> /home/charetjc/.cargo/registry/src/github.com-1ecc6299db9ec823/stdg-0.2.0/src/main.rs:567:33
    |
567 | / ...                   &text_font
568 | | ...                       .clone()
569 | | ...                       .expect("text font must be given before text is drawn"),
    | |_________________________________________________________________________________^ expected struct `font_kit::loaders::freetype::Font`, found a different struct `font_kit::loaders::freetype::Font`
    |
    = note: expected reference `&font_kit::loaders::freetype::Font` (struct `font_kit::loaders::freetype::Font`)
               found reference `&font_kit::loaders::freetype::Font` (struct `font_kit::loaders::freetype::Font`)
    = note: perhaps two different versions of crate `font_kit` are being used?

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
error: failed to compile `stdg v0.2.0`, intermediate artifacts can be found at `/tmp/cargo-installYmiWtT`

Caused by:
  could not compile `stdg`.

To learn more, run the command again with --verbose.

The conflict reports two versions of font-kit (v0.4.0, and v0.5.0).

If I clone the repository, then git checkout v0.2.0, and cargo build --release, the build only compiles font-kit:0.4.0 and compiles the project without any errors.

If I then cargo install --path ., the build tries to compile both font-kit:0.4.0 and font-kit:0.5.0.

I checked the Cargo.lock with grep 'font-kit' Cargo.lock, and only font-kit:0.4.0 is listed. I understood the point of Cargo.lock was to ensure a fixed set of crate versions were used when building the package, but this behavior suggests otherwise.

So my question is, does anyone know why cargo install is trying to compile two different versions of font-kit when the project appears to only require one?

Other info:

rustc --version
rustc 1.44.1 (c7087fe00 2020-06-17)

[1]: https://github.com/calebwin/stdg

Looks like I need to use cargo install --locked stdg. I thought I tried --locked before posting, but I missed it, and moved on after failing with --frozen.

It seems that cargo install will pull the latest [compatible?] crate available by default...

Yes, there's an open issue about it not using the lockfile by default

2 Likes

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.