Shared dependencies and incompatible features



I’m struggling with a dependency problem in my crate, that I’m hoping you guys can help me with:

I’m trying to use bindgen (0.32.1) and config (0.7.0) and both in turn depend (either directly or indirectly) on nom (3.2.1). The problem is that one of the them requires the nom feature “verbose-errors” but that causes a compile error in the other:

Is there anyway to work around this?

In my case, bindgen is a build-dependency while config is a regular dep so a theoretical solution would be to build nom seperately for the different class of dependencies. But is that even possible?



The best solution is probably to make an issue/PR to one of the dependencies and ask them to add a feature flag which will toggle whether the verbose-errors feature is activated for nom. That way users can toggle how nom’s error handling to make sure all crates work together.

I can’t really think of any other way to work around it :disappointed: The root problem is that feature flags are meant to be a purely additive thing, and nom seems to have broken that contract. Enabling a feature should only add functionality, not change behaviour or signatures.


Author of cexpr here (bindgen’s dependency that uses nom). This is a real bummer. What makes the situation even worse is that a crate’s dependents can’t figure out which feature is currently enabled, so it’s not possible to conditionally generate code for one path or the other.

I filed a PR with config to be compatible with either feature configuration:


Thank you @jethrogb! Really appreciate it.

I’m using your PR in my Cargo.toml and now it builds fine! Hopefully it gets merged soon.


How do you use individual PR in Cargo.toml?


You usually add a [patch] section to your Cargo.toml to override a dependency.


In my case I just did:

config = {git = “”, rev = “97b9687”}

But using a patch section is probably a more correct way to do it :slight_smile: