Reputation: 8390
Rustup's musl toolchain breaks dynamic libraries by design, meaning that bindgen
's runtime feature which loads libclang.so
at runtime cannot be used. Now, I want my crate to compile in both musl and gnu environments, so I'm trying to detect the environment and configure bindgen accordingly. This was my attempt:
[target.'cfg(all(target_os = "linux", target_env = "musl"))'.build-dependencies]
bindgen = { version = "0.60.1", features = ["static"], default-features = false }
[target.'cfg(not(all(target_os = "linux", target_env = "musl")))'.build-dependencies]
bindgen = { version = "0.60.1", features = ["runtime"], default-features = false }
I now tested this on my ArchLinux machine which is a gnu environment but got the following error message:
thread 'main' panicked at '`runtime` and `static` features can't be combined', /home/msrd0/.cargo/registry/src/github.com-1ecc6299db9ec823/clang-sys-1.3.3/build.rs:53:9
stack backtrace:
0: std::panicking::begin_panic
at /rustc/1.63.0/library/std/src/panicking.rs:616:12
1: build_script_build::main
at ./build.rs:53:9
2: core::ops::function::FnOnce::call_once
at /rustc/1.63.0/library/core/src/ops/function.rs:248:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
This is weird since under no circumstances I've enabled both features. I tested with the first two lines commented out and it works as expected, and the last two lines commented out and it fails to compile because there is no crate called bindgen, which is also expected.
Note that I'm using target_env
since I couldn't find something like host_env
in the output of rustc --print cfg
.
How can I enable different features based on the host (or target if host is unavailable) environment?
Upvotes: 1
Views: 30