Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot declare different version of dependencies in mutually exclusive targets #3195

Open
wagenet opened this issue Oct 12, 2016 · 15 comments
Open
Labels
A-target-dependencies Area: [target.'cfg(foo)'.dependencies] S-triage Status: This issue is waiting on initial triage.

Comments

@wagenet
Copy link

wagenet commented Oct 12, 2016

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.

@alexcrichton
Copy link
Member

Yeah unfortunately Cargo doesn't handle this case very well in general (depending on two versions of a library). If this works at all I'd be pretty surprised!

@alexcrichton alexcrichton added the A-diagnostics Area: Error and warning messages generated by Cargo itself. label Oct 17, 2016
@wagenet
Copy link
Author

wagenet commented Oct 18, 2016

It works, but only if the libraries are forked an renamed to avoid actual duplicate names.

@alexcrichton
Copy link
Member

Yeah Cargo should definitely have built-in support for that kind of operation.

@TheNeikos
Copy link
Contributor

Interesting, there is this test:

fn ignore_version_from_other_platform() {

That seems to test exactly that, and it checks for success

@damaex
Copy link

damaex commented Oct 27, 2016

I somewhat have an equal problem with the feature-dependencies for mysql-crate:

[target.'cfg(any(unix, macos))'.dependencies.mysql]
version = "*"
default-features = false
features = ["socket"]

[target.'cfg(windows)'.dependencies.mysql]
version = "*"
default-features = false
features = ["pipe"]

@alexcrichton
Copy link
Member

@TheNeikos oh interesting! @wagenet maybe this was fixed in nightly at some point? Or perhaps you could gist the exact error?

@damaex ah I think that my actually be an unrelated failure (e.g. another bug in Cargo). Enabling separate features for different targets unfortunately isn't supported right now.

@wagenet
Copy link
Author

wagenet commented Nov 7, 2016

@alexcrichton looks like you're right about this being fixed on the latest nightly. Thanks!

@wagenet wagenet closed this as completed Nov 7, 2016
@wagenet
Copy link
Author

wagenet commented Nov 8, 2016

Looks like there are still issues around git dependencies. This doesn't work:

[target.'cfg(not(target_os = "linux"))'.dependencies]
nix     = "0.5.0"
pidfile = { git = "https://github.com/wagenet/pidfile-rust", rev = "a0fe92915e419938d8d33f5cefb6e8f50b89d174" }

[target.'cfg(target_os = "linux")'.dependencies]
nix     = "0.4.3"
pidfile = { git = "https://github.com/carllerche/pidfile-rust", rev = "7516edfc9af2c0480e9f187c87de8cf6323c1ee3" }

It complains about pidfile being a duplicate, but not nix.

@wagenet wagenet reopened this Nov 8, 2016
wagenet added a commit to wagenet/cargo that referenced this issue Nov 8, 2016
@wagenet
Copy link
Author

wagenet commented Nov 8, 2016

Initial work on a PR to fix this here: #3275

@Eh2406
Copy link
Contributor

Eh2406 commented Oct 22, 2018

Note that #6179 (comment) may provide a workaround by using --minimal-cargo-lock to build only for the current platform.

@wagenet
Copy link
Author

wagenet commented Oct 23, 2018

See #6212.

@alexcrichton
Copy link
Member

I don't personally know how we'd solve this today or whether it's easily solvable, but PRs to implement it are of course always welcome!

@RalfJung
Copy link
Member

Looks like a duplicate of #2524.

@ehuss
Copy link
Contributor

ehuss commented Jun 30, 2019

@RalfJung I don't see this as a duplicate. The issue here is that two different targets using git dependencies does not work. #2524 is about using different features.

@RalfJung
Copy link
Member

Sorry for that then, seems I didn't understand what this bug is about.

@epage epage added A-target-dependencies Area: [target.'cfg(foo)'.dependencies] S-triage Status: This issue is waiting on initial triage. and removed A-diagnostics Area: Error and warning messages generated by Cargo itself. labels Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-target-dependencies Area: [target.'cfg(foo)'.dependencies] S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

8 participants