-
Notifications
You must be signed in to change notification settings - Fork 67
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
Fix static linking error for LLVM-17 #167
Conversation
Hey! I met the similar Issue. And I want to know if you resolve it and how? Thanks! |
It really depends on what your build environment is. This patch was one of a series of patches through the rust-bindgen project to fix static compilation on alpine Linux specifically. You could try the environment variable |
Actually I still have this problem.
I couldn't compile rust-bindgen with the only feature static. Is there anything else I should notice? |
Ah, yes that's caused by Is there any particular reason you need to statically link the compiler like this? Remember the method of linking is only used at compile time and doesn't determine whether the bindgen itself is linked statically / dynamically. |
I'm not familiar with apline. I'm trying to compile my program in the docker rust: alpine. It seems that I cann't load dynamical library. Maybe I should try to cross comopile it on a gnu env. |
Try compiling with That disables static musl linking which should fix the issue. |
I have tried that on alpine. And I have no idea why It doesn't work. I will try again tomorrow. Thanks very much |
Should I use feature |
it's related to rust-lang/cargo#4423 . Fix it by https://doc.rust-lang.org/cargo/reference/unstable.html#host-config . Thanks |
I'm not entirely sure how you're cross-compiling, but if you have the ability to use a container engine such as I do a lot of "cross-compiling" for FROM alpine:edge AS build
ENV RUSTFLAGS="-C target-feature=-crt-static"
ENV PATH=${PATH}:/root/.cargo/bin
WORKDIR /src
# install any dependencies here
RUN apk add alpine-sdk curl llvm-dev clang-dev
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal
COPY . .
RUN cargo build --release
FROM alpine:edge
# install any dependencies here, libgcc is needed since we disabled crt-static
RUN apk add libgcc
COPY --from=build /src/target/release/BINARY /usr/local/bin/BINARY
ENTRYPOINT [ "/usr/local/bin/BINARY" ] In this scenario, you should enable the |
Foreword: this is my first public pr in quite a while, apologies if something is not quite right.
When specifying the static build feature, this crate attempts to link to the library
-lLLVM-17
. However, LLVM does not provide a single static library since it would be too large (500MB!). Therefore, to successfully link against static LLVM, one must append all of the individual libraries, of which there are many.This PR uses the
llvm-config
tool's--link-static
flag, which causes it to output each individual static archive. Additionally, the LLVM library uses symbols fromzstd
, which this PR also appends to the linker.