[I apologize for the length of this post; the problem is somewhat involved, and I don't know if I've even described it accurately.]
I'm new to Rust, and working with an existing crate (it's part of a Python package): GitHub - Qiskit/qiskit-terra: Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and algorithms.
rustc 1.61.0 (fe5b13d68 2022-05-18)
cargo 1.61.0 (a028ae4 2022-04-29)
This crate uses a number of existing crates
it ships with a Cargo.lock file, probably generated in the past.
when building with that Cargo.lock file (
cargo build), the package "hashbrown" is built with version
but if I blow away that Cargo.lock file,
cargo cleanand then
cargo build, it builds both versions
v0.11.2. And the build fails with errors related to
Just to be clear: the way the error reproduces is:
cargo clean, remove
cargo build fails with compile errors related to various types and traits (after building those two versions of
- So I can pin the version of hashbrown in the Cargo.toml file to the one I want:
[dependencies.hashbrown] version = ">= 0.11.2, < 0.12" features = ["rayon"]
- Another reason two versions are getting built, is that
indexmap(which in the original Cargo.lock file was
1.8.2) gets pulled in at
1.9.0, and indexmap:1.9.0 depends on hashbrown :0.12. But I can fix that, by pinning
indexmap = ">= 1.8.2, < 1.9.0"
- Doing that,
cargo clean, remove
Cargo.lock, then do
cargo buildstill fails, but this time
indexmapis at version
1.8.2as it was in the original
Cargo.lockfile. Instead, the problem is now package
pyo3, which has stanza
[[package]] name = "pyo3" version = "0.16.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e6302e85060011447471887705bb7838f14aba43fcb06957d823739a496b3dc" dependencies = [ "cfg-if", "hashbrown 0.12.1", "indoc", "libc", "num-complex", "parking_lot", "pyo3-build-config", "pyo3-ffi", "pyo3-macros", "unindent", ]
But the package itself (at version 0.16.5) has dependency:
[dependencies.hashbrown] version = ">= 0.9, < 0.13" optional = true
[verified by digging out the crate from cargo's cache and unpacking it, just to be sure]
So to my question: why is cargo building two versions of this crate "hashbrown" ?
As I said, I checked in Cargo.lock for all crates that depend on hashbrown, and for all of them that got installed with a newer version (and that pulled in the newer version of hashbrown, I pinned the dependency to an older version (e.g.
pyo3 doesn't depend on a newer version of hashbrown, and in fact in the original Cargo.lock says so:
[[package]] name = "pyo3" version = "0.16.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e6302e85060011447471887705bb7838f14aba43fcb06957d823739a496b3dc" dependencies = [ "cfg-if", "hashbrown", "indoc", "libc", "num-complex", "parking_lot", "pyo3-build-config", "pyo3-ffi", "pyo3-macros", "unindent", ]
I have no idea what's going on, but basically it seems I cannot delete that Cargo.lock without breaking the build. And that seems completely wrong.