8000 How do you statically link libraries? · Issue #51 · emk/rust-musl-builder · GitHub
[go: up one dir, main page]

Skip to content
How do you statically link libraries? #51
@Gisleburt

Description

@Gisleburt

I'm using a multi build docker file to try to create a docker image with nothing but the binary in it. Unfortunately I'm left with a large number of dynamic links.

Dockerfile:

#########
# Build #
#########
FROM ekidd/rust-musl-builder AS builder

RUN sudo apt-get update \
 && sudo apt-get install -y \
    libmysqlclient-dev

WORKDIR /build

RUN sudo chown rust:rust .

COPY src src
COPY Cargo.toml .
COPY Cargo.lock .
COPY<
5E93
/span> diesel.toml .

RUN cargo build --release

##############
# Executable #
##############
FROM scratch

WORKDIR /app

COPY --from=builder /build/target/x86_64-unknown-linux-musl/release/webserver webserver

EXPOSE 8080

CMD ["/app/webserver"]

However, if I test the binary after building:

$ ldd target/x86_64-unknown-linux-musl/release/webserver
        linux-vdso.so.1 =>  (0x00007fff33df6000)
        libmysqlclient.so.20 => /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20 (0x00007f41a7252000)
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f41a7038000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f41a6e34000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f41a6c17000)
        libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f41a6895000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f41a658c000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f41a6376000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f41a5fac000)
        /lib/ld64.so.1 => /lib64/ld-linux-x86-64.so.2 (0x00007f41a7861000)

I feel like others must have gone through this but I can't find any sort of guide written down anywhere (my google foo is bad though so 🤷🏻‍♂️).

I feel esspecially silly as I think I was able to do this about nine months ago (with very basic apps at least). 😊

Is there a process I can go through to manage static linking? Perhaps a step by step guide?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0