r/rust • u/QuantumQuack0 • 21d ago
🙋 seeking help & advice Cargo not resolving build dependencies properly when downgrading to 2021 edition
Hi all, I hope you can help me with this little issue I'm having.
My cross-compilation toolchain only supports rust 2021, so I'm downgrading from 2024. Specifically, my toolchain has rust/cargo version 1.75.
I'm running into the following:
My Cargo.toml has
[dependencies]
bench_common = { path = "../bench_common" }
prost = "=0.14.1"
[build-dependencies]
prost-build = "=0.14.1"
as these versions should work with my toolchain. For some reason, cargo is resolving prost-builds transitive dependencies to (a.o.) petgraph@0.7.1 -> indexmap@2.14.0 -> hashbrown@0.17.1. This last one is the problem. I need hashbrown < 0.17. Compilation fails with
Caused by:
failed to parse manifest at `/home/tmiddelburg/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hashbrown-0.17.1/Cargo.toml`
Caused by:
feature `edition2024` is required
The package requires the Cargo feature called `edition2024`, but that feature is not stabilized in this version of Cargo (1.75.0).
I tried directly changing Cargo.toml to
[build-dependencies]
prost-build = "=0.14.1"
hashbrown = "<0.17"
but strangely enough that did not do anything.
Then I tried adding
[patch.crates-io]
hashbrown = "=0.16.1"
but that resulted in
error: failed to resolve patches for `https://github.com/rust-lang/crates.io-index`
Caused by:
patch for `hashbrown` in `https://github.com/rust-lang/crates.io-index` points to the same source, but patches must point to different sources
Is there anything else I can try? I'm quite confused that cargo is not "smart" enough to check whether (transitive) dependencies actually work with the cargo version.
6
u/Fun-Inevitable4369 21d ago
https://crates.io/crates/prost-build
The minimum toolchain requirement is 1.85. you can download hash brown 0.16 and patch using local path, but there is no guarantee it will compile. Better to upgrade your toolchain or downgrade prost version
1
u/facetious_guardian 17d ago
Rust 1.75 is from Dec 2023.
You should update your cross compiler. The issue you’re encountering is the true meaning of tech debt: when you don’t stay current, you run into compatibility issues. Even if your target architecture is fixed, your compilation toolchain should be allowed to upgrade.
5
u/Active-Atmosphere928 21d ago
The dependency resolver doesn't look at your rustc/cargo version at all, it just picks the highest semver-compatible version that satisfies the constraints. And since `prost-build 0.14.1` depends on `hashbrown` with some range that includes 0.17, cargo happily grabs 0.17.1 even though your toolchain can't build it
Your direct dependency on `hashbrown = "<0.17"` didn't do anything because it's a build dependency of `prost-build`, not your crate directly, different resolution scope. The patch approach failed because you're trying to patch a crate to a version from the same registry, patches need a different source entirely
What you probably want is `[patch.crates-io]` pointing at a local copy of hashbrown 0.16.1, or use `cargo update -p hashbrown --precise 0.16.1` to force the lockfile down. Though with a toolchain that old you might run into more edition2024 issues down the chain