Cargo build package with conflicting features from the same git repository?

I have a git repository (not which has different features, let’s call them A and B, which are mutually exclusive - the two features expose structs and API of the same names, hence compiling both naively will result in conflicts and fail.

As a developer of a dependant package, I want to use both features.
I can use aliasing. It fails if I use the same git repository url, but it works if in Cargo.toml I use two different git repositories:

my_package_A = {package = "my_package", git = "/first/url", features = ["A"]}
my_package_B = {package = "my_package", git = "/second/url", features = ["B"]}

I want to avoid forking my repository to a different url.
Is there a way to do that?

Cargo doesn’t support mutually-exclusive features. Cargo will actively try to merge all features. In principle, all features are supposed to be additive.

The right solution would be to redesign the crate to allow all features at once (e.g. by namespacing the structs in separate modules, or making them generic).

Changing of Git URL, to pretend it’s a separate package with a separate set of features, seems like a sensible workaround.

1 Like