Target-specific dependency (feature?) resolution failure

Hello everyone!

I have the following setup:

  • My own binary crate Bin.

  • This Bin crate depends on two crates: my own Lib library crate and third-party Foo crate

  • Lib crate, in turn, depends on third-party Bar crate.

  • Foo and Bar are very simple crates that wrap around native libraries libfoo and libbar.

  • Both of them are able to wrap either a system-provided library with the help of system-libfoo and system-libbar features, or to compile-in their own versions with builtin-libfoo and builtin-libbar features. Of course those features are mutually exclusive.

Now to the tricky part. I want my program to rely on system-provided libraries on Unix, but on Windows I want to embed libs into my program. I already did my homework and found that unfortunately target-specific features aren't supported by the Cargo, and the possible workaround is target-scecific dependencies with it's own set of features each.

The only problem is, it works kinda 50/50.

I have the following in the Cargo.toml for Bin crate:

lib = { path = "../lib" }

foo = { version = "0.1", default-features = false, features = ["builtin-libfoo"] }

foo = { version = "0.1", default-features = false, features = ["system-libfoo"] }

And similarly, for the Lib crate:

bar = { version = "0.2", default-features = false, features = ["builtin-libbar"] }

bar = { version = "0.2", default-features = false, features = ["system-libbar"] }

Now, if I try to independently build Lib crate for both targets everything works as expected.

If I try to build Bin crate excluding Lib crate dependency, everything also works as expected for both targets.

But if I enable Lib dependency in Bin create and try to build it, build fails - Bar crate complains that I've enabled two incompatible features.

What did I miss? Why everything's working when I build Lib crate standalone but not as a dependency? And how to workaround this?

Not sure, but here's a guess: Are you using resolver 1 or 2?

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.