[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 version:
rustc 1.61.0 (fe5b13d68 2022-05-18)
-
cargo version:
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 versionv0.11.2
-
but if I blow away that Cargo.lock file,
cargo clean
and thencargo build
, it builds both versionsv0.12.1
andv0.11.2
. And the build fails with errors related tohashbrown
.
Just to be clear: the way the error reproduces is: cargo clean
, remove Cargo.lock
, then cargo build
fails with compile errors related to various types and traits (after building those two versions of hashbrown
).
- 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 was1.8.2
) gets pulled in at1.9.0
, and indexmap:1.9.0 depends on hashbrown :0.12. But I can fix that, by pinningindexmap
to1.8.2
:
indexmap = ">= 1.8.2, < 1.9.0"
- Doing that,
cargo clean
, removeCargo.lock
, then docargo build
still fails, but this timeindexmap
is at version1.8.2
as it was in the originalCargo.lock
file. Instead, the problem is now packagepyo3
, 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. indexmap
). But 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.