Open jethrogb opened 3 years ago
Yeah, this was known when taking #1617, but there didn't seem to be a lot of better solutions to this problem. Better ideas def. welcome.
You need to choose one of the features to override the other. It's not really clear to me what the difference is between “no features”, the “runtime feature”, but I'd suggest:
(default behavior): dynamic linking static: this forces static linking
Also, IIUC, if static feature is enabled by clang-sys, you need to call it in a different way. So then the existence of this feature should be propagated by clang-sys's build script to dependents using the DEP_...
environment variable.
Another option would be that the dependents that want static linking get static linking, and the ones that want dynamic linking get dynamic linking? You'd need two separate crates, or types, or a builder to do this properly.
I need to page this back in, but IIRC the problem is that there are effectively three behaviors, not two:
static
feature)..so
, like a static library)Ah, that makes sense. So yeah you have to make a choice between static and dynamic. But runtime could be used independently, assuming symbols are sufficiently namespaced?
I ran into this issue when trying to use both littlefs2-sys
and nettle-sys
in the same crate.
Cargo.toml
Is there any way to work around this issue? If not, how should littlefs2-sys
and nettle-sys
be changed to avoid it?
Also, if this isn’t fixed in the code, it should at least be documented to make users aware of this issue and how to fix it.
Perhaps a solution based on --cfg
flags would be preferable over mutually exclusive features. This is an example of another library taking this approach: https://github.com/dalek-cryptography/curve25519-dalek/pull/455
If you have two different dependencies that both depend on bindgen, but dependency A uses static linking and dependency B using dynamic linking, this will fail to build.
You can test this easily with the following Cargo.toml:
Cargo features are supposed to be additive, i.e. one crate in your dependency tree should never fail to build because another crate elsewhere in your dependency tree enables some feature.
There's also a related issue where if you do something like this:
This will build, but it will panic at runtime:
See also https://github.com/KyleMayes/clang-sys/issues/128