Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error related to bindgen when building on alpine #477

Closed
Percivalll opened this issue Jul 26, 2020 · 12 comments
Closed

Error related to bindgen when building on alpine #477

Percivalll opened this issue Jul 26, 2020 · 12 comments

Comments

@Percivalll
Copy link

Percivalll commented Jul 26, 2020

Describe the bug
thread 'main' panicked at 'Unable to find libclang: "the libclang shared library at /usr/lib/libclang.so.10 could not be opened: Dynamic loading not supported"', /root/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.51.1/src/lib.rs:1731:13
To Reproduce
Steps to reproduce the behavior:
cargo build --target x86_64-unknown-linux-musl
Expected behavior
Build successed.

System information

  • CPU architecture:x86_64
  • Distribution and kernel version: Linux alpine latest

Additional context
All content:

TARGET = Some("x86_64-unknown-linux-musl")
OPT_LEVEL = Some("0")
HOST = Some("x86_64-unknown-linux-musl")
CXX_x86_64-unknown-linux-musl = None
CXX_x86_64_unknown_linux_musl = None
HOST_CXX = None
CXX = None
CXXFLAGS_x86_64-unknown-linux-musl = None
CXXFLAGS_x86_64_unknown_linux_musl = None
HOST_CXXFLAGS = None
CXXFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("true")
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
running: "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "grpc/include" "-Wall" "-Wextra" "-std=c++11" "-DGRPC_SYS_SECURE" "-Werror" "-o" "/home/xxxxx/rust_sdk/target/x86_64-unknown-linux-musl/debug/build/grpcio-sys-a4affaee80d0ec98/out/grpc_wrap.o" "-c" "grpc_wrap.cc"
exit code: 0
AR_x86_64-unknown-linux-musl = None
AR_x86_64_unknown_linux_musl = None
HOST_AR = None
AR = None
running: "ar" "crs" "/home/xxxxx/rust_sdk/target/x86_64-unknown-linux-musl/debug/build/grpcio-sys-a4affaee80d0ec98/out/libgrpc_wrap.a" "/home/xxxxx/rust_sdk/target/x86_64-unknown-linux-musl/debug/build/grpcio-sys-a4affaee80d0ec98/out/grpc_wrap.o"
exit code: 0
cargo:rustc-link-lib=static=grpc_wrap
cargo:rustc-link-search=native=/home/xxxxx/rust_sdk/target/x86_64-unknown-linux-musl/debug/build/grpcio-sys-a4affaee80d0ec98/out
CXXSTDLIB_x86_64-unknown-linux-musl = None
CXXSTDLIB_x86_64_unknown_linux_musl = None
HOST_CXXSTDLIB = None
CXXSTDLIB = None
cargo:rustc-link-lib=stdc++
running grpc_wrap.cc --rust-target 1.33 --default-enum-style= rust --constified-enum-module grpc_status_code --blacklist-type (__)?pthread.* --blacklist-type gpr_mu --blacklist-type gpr_cv --blacklist-type gpr_once --blacklist-function \bgpr_mu_.* --blacklist-function \bgpr_cv_.* --blacklist-function \bgpr_once_.* --impl-debug --no-derive-default --generate functions,types,vars,methods,constructors,destructors --whitelist-function \bgrpc_.* --whitelist-function \bgpr_.* --whitelist-function \bgrpcwrap_.* --whitelist-type \bgrpc_.* --whitelist-type \bgpr_.* --whitelist-type \bgrpcwrap_.* --whitelist-type \bcensus_context.* --whitelist-type \bverify_peer_options.* --whitelist-var \bGRPC_.* -- -DGRPC_SYS_SECURE -xc++ -I./grpc/include -std=c++11 ./grpc/include/grpc/compression.h ./grpc/include/grpc/grpc.h ./grpc/include/grpc/grpc_cronet.h ./grpc/include/grpc/grpc_posix.h ./grpc/include/grpc/grpc_security.h ./grpc/include/grpc/impl/codegen/byte_buffer.h ./grpc/include/grpc/impl/codegen/log.h ./grpc/include/grpc/impl/codegen/port_platform.h ./grpc/include/grpc/slice.h ./grpc/include/grpc/slice_buffer.h ./grpc/include/grpc/support/alloc.h ./grpc/include/grpc/support/cpu.h ./grpc/include/grpc/support/log_windows.h ./grpc/include/grpc/support/string_util.h ./grpc/include/grpc/support/sync.h ./grpc/include/grpc/support/thd_id.h ./grpc/include/grpc/support/time.h

--- stderr
CMake Warning at cmake/protobuf.cmake:51 (message):
  gRPC_PROTOBUF_PROVIDER is "module" but PROTOBUF_ROOT_DIR is wrong
Call Stack (most recent call first):
  CMakeLists.txt:207 (include)


CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_ASM_COMPILER
    CMAKE_ASM_FLAGS


/root/.cargo/registry/src/github.com-1ecc6299db9ec823/grpcio-sys-0.6.0/grpc/src/core/tsi/ssl_transport_security.cc: In function 'tsi_result tsi_create_ssl_client_handshaker_factory_with_options(const tsi_ssl_client_handshaker_options*, tsi_ssl_client_handshaker_factory**)':
/root/.cargo/registry/src/github.com-1ecc6299db9ec823/grpcio-sys-0.6.0/grpc/src/core/tsi/ssl_transport_security.cc:1797:44: warning: 'const SSL_METHOD* TLSv1_2_method()' is deprecated [-Wdeprecated-declarations]
 1797 |   ssl_context = SSL_CTX_new(TLSv1_2_method());
      |                                            ^
In file included from /usr/include/openssl/e_os2.h:13,
                 from /usr/include/openssl/x509.h:14,
                 from /root/.cargo/registry/src/github.com-1ecc6299db9ec823/grpcio-sys-0.6.0/grpc/src/core/tsi/ssl_transport_security.h:28,
                 from /root/.cargo/registry/src/github.com-1ecc6299db9ec823/grpcio-sys-0.6.0/grpc/src/core/tsi/ssl_transport_security.cc:21:
/usr/include/openssl/ssl.h:1889:1: note: declared here
 1889 | DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_2_method(void)) /* TLSv1.2 */
      | ^~~~~~~~~~~~~~~~~~
/root/.cargo/registry/src/github.com-1ecc6299db9ec823/grpcio-sys-0.6.0/grpc/src/core/tsi/ssl_transport_security.cc:1797:44: warning: 'const SSL_METHOD* TLSv1_2_method()' is deprecated [-Wdeprecated-declarations]
 1797 |   ssl_context = SSL_CTX_new(TLSv1_2_method());
      |                                            ^
In file included from /usr/include/openssl/e_os2.h:13,
                 from /usr/include/openssl/x509.h:14,
                 from /root/.cargo/registry/src/github.com-1ecc6299db9ec823/grpcio-sys-0.6.0/grpc/src/core/tsi/ssl_transport_security.h:28,
                 from /root/.cargo/registry/src/github.com-1ecc6299db9ec823/grpcio-sys-0.6.0/grpc/src/core/tsi/ssl_transport_security.cc:21:
/usr/include/openssl/ssl.h:1889:1: note: declared here
 1889 | DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_2_method(void)) /* TLSv1.2 */
      | ^~~~~~~~~~~~~~~~~~
/root/.cargo/registry/src/github.com-1ecc6299db9ec823/grpcio-sys-0.6.0/grpc/src/core/tsi/ssl_transport_security.cc: In function 'tsi_result tsi_create_ssl_server_handshaker_factory_with_options(const tsi_ssl_server_handshaker_options*, tsi_ssl_server_handshaker_factory**)':
/root/.cargo/registry/src/github.com-1ecc6299db9ec823/grpcio-sys-0.6.0/grpc/src/core/tsi/ssl_transport_security.cc:1961:58: warning: 'const SSL_METHOD* TLSv1_2_method()' is deprecated [-Wdeprecated-declarations]
 1961 |       impl->ssl_contexts[i] = SSL_CTX_new(TLSv1_2_method());
      |                                                          ^
In file included from /usr/include/openssl/e_os2.h:13,
                 from /usr/include/openssl/x509.h:14,
                 from /root/.cargo/registry/src/github.com-1ecc6299db9ec823/grpcio-sys-0.6.0/grpc/src/core/tsi/ssl_transport_security.h:28,
                 from /root/.cargo/registry/src/github.com-1ecc6299db9ec823/grpcio-sys-0.6.0/grpc/src/core/tsi/ssl_transport_security.cc:21:
/usr/include/openssl/ssl.h:1889:1: note: declared here
 1889 | DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_2_method(void)) /* TLSv1.2 */
      | ^~~~~~~~~~~~~~~~~~
/root/.cargo/registry/src/github.com-1ecc6299db9ec823/grpcio-sys-0.6.0/grpc/src/core/tsi/ssl_transport_security.cc:1961:58: warning: 'const SSL_METHOD* TLSv1_2_method()' is deprecated [-Wdeprecated-declarations]
 1961 |       impl->ssl_contexts[i] = SSL_CTX_new(TLSv1_2_method());
      |                                                          ^
In file included from /usr/include/openssl/e_os2.h:13,
                 from /usr/include/openssl/x509.h:14,
                 from /root/.cargo/registry/src/github.com-1ecc6299db9ec823/grpcio-sys-0.6.0/grpc/src/core/tsi/ssl_transport_security.h:28,
                 from /root/.cargo/registry/src/github.com-1ecc6299db9ec823/grpcio-sys-0.6.0/grpc/src/core/tsi/ssl_transport_security.cc:21:
/usr/include/openssl/ssl.h:1889:1: note: declared here
 1889 | DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_2_method(void)) /* TLSv1.2 */
      | ^~~~~~~~~~~~~~~~~~
thread 'main' panicked at 'Unable to find libclang: "the `libclang` shared library at /usr/lib/libclang.so.10 could not be opened: Dynamic loading not supported"', /root/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.51.1/src/lib.rs:1731:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
@BusyJay
Copy link
Member

BusyJay commented Jul 27, 2020

Have you install clang?

@Percivalll
Copy link
Author

Yes,I have installed clang and its libs which at /usr/lib/libclang.so.10.
I think the problem is that musl cross-compilation target is statically compiled, but the libclang dynamic library is called here.

@BusyJay
Copy link
Member

BusyJay commented Jul 27, 2020

I think you are probably correct. Do you have any idea how to fix it?

@Percivalll
Copy link
Author

In https://github.com/KyleMayes/clang-sys#dependencies:

By default, this crate will attempt to link to libclang dynamically. In this case, this crate depends on the libclang shared library (libclang.so on Linux, libclang.dylib on macOS, libclang.dll on Windows). If you want to link to libclang statically instead, enable the static Cargo feature. In this case, this crate depends on the LLVM and Clang static libraries. If you don't want to link to libclang at compiletime but instead want to load it at runtime, enable the runtime Cargo feature.
These libraries can be either be installed as a part of Clang or downloaded here.
Note: The downloads for LLVM and Clang 3.8 and later do not include the libclang.a static library. This means you cannot link to any of these versions of libclang statically unless you build it from source.

It may be helpful.

@Percivalll
Copy link
Author

In grpc-rs/grpc-sys/Cargo.toml:

# Because of rust-lang/cargo#5237, bindgen should not be upgraded util a minor or major release.
bindgen = { version = "0.51.0", default-features = false }

My guess is that this prevents the static feature?Both about version(it is too low) and default-features(it is closed).

@BusyJay
Copy link
Member

BusyJay commented Jul 27, 2020

I'm afraid the feature can't be enabled until it works both static and dynamic way. The library is for general purpose, it should not require all users to compile a static library.

@Percivalll
Copy link
Author

I understand what you said, but maybe adding a feature to support static compilation is a good idea.

@Percivalll
Copy link
Author

I have made a docker image to build static bin under debian 9,if anyone needs it,I'll share it.

@BusyJay
Copy link
Member

BusyJay commented Aug 3, 2020

Have you verified whether static features work? I'm OK with the feature but we may not release it until 0.7.0 as upgrading bindgen can break things. See rust-lang/cargo#5237

@Percivalll
Copy link
Author

Yes,I tried to manually turn on the static feature of bindgen, and it worked normally, no longer forced to search for libclang.so.
But the interesting thing is that even if I don't open this feature manually, I can still compile successfully under debian statically.
I think this is not because of the pre-generated code, because the target I compiled is x86_64-unknown-linux-musl, not x86_64-unknwon-linux-gnu.

@camdenorrb
Copy link

@ZhangLei-cn Plz share :3

@TeemuKoivisto
Copy link

TeemuKoivisto commented Dec 16, 2022

Well this was bit of a nightmare bug to figure out, but eventually my persistence prevailed. So I'm using rust:1-slim-buster Docker image and it seemed impossible to get this bindgen to work on alpine image (something about runtime and static features can't be combined',)

The main problem I faced was that inside the buster image running apt-get -y install clang would install an older version of clang (v7) which included some bug with snappy library link. Tried many ways to install a newer version of clang which was ridiculously hard. Only thing that finally worked was:

RUN apt-get update && apt-get -y install lsb-release wget software-properties-common gnupg g++
RUN bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"

This of course makes the build even longer than it is with Rust but what can you do. Now it at least builds, hurray. And only 25 minutes in Github CI... Christ 😅 But maybe this helps somebody out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants