I'm encountering some strange behavior with Cargo when trying to use different features for a dependency depending on the target. This is what I'm attempting:
[target.'cfg(target_arch = "wasm32")'.dependencies.gfx-backend-gl]
path = "../src/backend/gfx-backend-gl"
optional = true
[target.'cfg(windows)'.dependencies.gfx-backend-gl]
path = "../src/backend/gfx-backend-gl"
features = ["wgl"]
optional = true
[target.'cfg(unix)'.dependencies.gfx-backend-gl]
path = "../src/backend/gfx-backend-gl"
features = ["surfman"]
optional = true
The goal is to include gfx-backend-gl
with a different feature enabled depending on the target. The strange behavior is that when I compile for wasm32
with this setup, it includes the gfx-backend-gl
dependency, but with the wgl
and surfman
features as well, which doesn't make a lot of sense because those features aren't included in the dependency for the matching target.
It would work fine if each dependency was on a different crate, but because they are the same it seems to want to merge the features. Is this a bug?
Hmm, I haven't tried it yet, but maybe if I name each dependency different and use the rename feature to point them all to the same crate?