I have a large mono-repo, of which a big chunk is a PyO3 package called ress.
Building it randomly fails when making unrelated changes or switching machines by cargo selecting conflicting versions of ndarray. I use multiple crates which interact with ndarray objects: sprs, numpy, sprs-superlu (I maintain the latter). According to their Cargo.toml files all these crates should work with ndarray 0.16.
When compiling the same commit on my local machine and my deployment server (both with rustc and cargo 1.82.0), I get different results (I ran cargo clean on both before building). On my machine it works, whereas the build fails on the server with a package conflict. A working fix is to copy the Cargo.lock file from my local machine to the server and then run cargo build. I have tried to add a patch to Cargo.toml:
[patch.crates-io]
ndarray = "0.16"
Then cargo build throws:
patch for ndarray
in https://github.com/rust-lang/crates.io-index
points to the same source, but patches must point to different sources
Below I have put the relevant part of both Cargo.lock files which raises multiple questions for me:
- Why can ndarray be in Cargo.lock twice (0.16 and 0.15.6)?
- Why are numpy and sprs-superlu using different versions of ndarray on either machine?
- How can I make sure that ndarray 0.16 is used in the entire project?
Cargo.toml:
...
[dependencies]
ndarray = "0.16"
numpy = { version = "0.22.0"}
sprs = "0.11"
sprs-superlu = "0.1.6"
...
Cargo.lock (local machine):
[[package]]
name = "ndarray"
version = "0.15.6"
...
[[package]]
name = "ndarray"
version = "0.16.1"
...
[[package]]
name = "numpy"
version = "0.22.0"
...
dependencies = [
...
"ndarray 0.16.1",
]
[[package]]
name = "ress"
version = "0.0.264"
...
dependencies = [
...
"ndarray 0.16.1"
]
[[package]]
name = "sprs"
version = "0.11.1"
...
dependencies = [
"ndarray 0.15.6",
...
]
[[package]]
name = "sprs-superlu"
version = "0.1.6"
...
dependencies = [
...
"ndarray 0.16.1",
"sprs",
]
Cargo.lock (deployment server):
[[package]]
name = "ndarray"
version = "0.15.6"
...
[[package]]
name = "ndarray"
version = "0.16.1"
...
[[package]]
name = "numpy"
version = "0.22.0"
...
dependencies = [
"ndarray 0.15.6",
...
]
[[package]]
name = "ress"
version = "0.0.264"
...
dependencies = [
...
"ndarray 0.16.1"
]
[[package]]
name = "sprs"
version = "0.11.1"
...
dependencies = [
"ndarray 0.15.6",
...
]
[[package]]
name = "sprs-superlu"
version = "0.1.6"
...
dependencies = [
...
"ndarray 0.15.6",
"sprs",
]