Feature for static linking build
izderadicka opened this issue · 3 comments
I want to use rust_icu_col
in building fully statically linked binary. I'm building on alpine with RUSTFLAGS="-C target-feature=+crt-static -C link-self-contained=yes"
Problem here is that I'm getting this error when rust_icu_sys is compiled:
thread 'main' panicked at 'Unable to find libclang: "the `libclang` shared library at /usr/lib/libclang.so.11.1 could not be opened: Dynamic loading not supported"', /root/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.53.3/src/lib.rs:1956:31
I do have static version of libclang - e.g libclang.a on system, but build is still preferring dynamic version.
In my other projects I' m using feature static
which will enforce println!("cargo:rustc-link-lib=static=ssl");
(here should be clang) for dependant C libraries.
However I'm not sure how to do it for indirect dependencies - e.g. you depend on C library and I depend on your crate.
I guess same will be for icu C library, but just hit clang first.
Yes, feature flag would be great.
I finally was able to do a static build against rust_icu_col, but it took this:
- build in alpine with taget x86_64-unknown-linux-musl
- need to install static libs for icu a clang
- use rust_icu_col without default features, just with
rename
andicu_version_in_env
- use environment vars:
export RUST_ICU_MAJOR_VERSION_NUMBER=67
export RUSTFLAGS="-C target-feature=+crt-static -C link-self-contained=yes -L native=/usr/lib -l static=clang -l static=icui18n -l static=icuuc -l static=icudata -l static=stdc++"
Some of the complexity is caused by Rust complicated approach to static build, but for rest static
feature in rust_icu will help.
From what I have seen bindgen has static feature too, which might be useful.
Feel free to contribute a patch that handles your use case. It looks like you've already done the legwork, so I hope it shouldn't be too complicated.