cargo: Cannot declare different version of dependencies in mutually exclusive targets
Maintainer’s update
- This is fixed for registry dependencies but not git dependencies
That’s a mouthful, but here’s an example:
[target.'cfg(not(target_os = "linux"))'.dependencies]
nix = "0.5.0"
[target.'cfg(target_os = "linux")'.dependencies]
nix = "0.4.3"
Unfortunately, right now this isn’t allowed as it’s considered a duplicate declaration per #2491.
The use case for this is that FreeBSD requires a newer version of nix to work. However, Linuxes with glibc 2.5 require an older version of nix.
My very ugly workaround is to fork nix and rename it. Then I can use cfg to import the correct crate in the source.
About this issue
- Original URL
- State: open
- Created 10 years ago
- Reactions: 5
- Comments: 16 (9 by maintainers)
Commits related to this issue
- Add failing test for #3195 — committed to wagenet/cargo by wagenet 10 years ago
I have an issue that is very similar to this. Essentially, when you run
cargo checkorcargo build, cargo will compile dependencies for all the targets provided. For example, I have a case like this:There are, of course, other dependencies that change between the
wasm32and non-wasm32targets, but what I find is thatcargo checkbuildstokioforwasm32.This is happening given that distinct portions of code are gated with:
Now, I can resolve this by compiling targets separately:
But this leaves a lot to be desired. It’s not really very easy to then have
rust-analyzerusecargo checkas we need to adjust its settings to only focus on a single target at a time. We also cannot build both targets with a single command.What would be great is, like with features as well, we can have
cargo checkandcargo buildonly compile the features and dependencies necessary for the specific target in mind.