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

[---] Build docker executable with musl libc. #751

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM busybox:glibc
FROM busybox

MAINTAINER "André Stein <[email protected]>"

Expand Down
46 changes: 46 additions & 0 deletions ci/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
FROM alpine:3.10

ENV DUB_BRANCH "v1.20.1"
ENV RDMD_BRANCH "v2.091.0"

RUN apk add --no-cache llvm5-libs g++ binutils-gold clang \
llvm8-libs llvm8-static llvm8-dev \
cmake ninja zlib-dev curl-dev curl-static openssl-dev git make

# build ldc2 ########################################################

ADD https://github.com/ldc-developers/ldc/releases/download/v1.13.0/ldc2-1.13.0-alpine-linux-x86_64.tar.xz /ldc-bin.tar.xz
RUN tar xf ldc-bin.tar.xz

# TODO: use environment variable from travis for LDC version
ADD https://github.com/ldc-developers/ldc/releases/download/v1.21.0/ldc-1.21.0-src.tar.gz /ldc-src.tar.xz
RUN tar xf ldc-src.tar.xz

RUN mkdir /ldc-1.21.0-src/build \
&& cd /ldc-1.21.0-src/build \
&& cmake -G Ninja .. -DCMAKE_BUILD_TYPE=Release \
-DD_COMPILER=/ldc2-1.13.0-alpine-linux-x86_64/bin/ldmd2 \
&& ninja -j2 \
&& ninja install

# build dub ##########################################################

RUN git clone --single-branch --branch ${DUB_BRANCH} https://github.com/dlang/dub \
&& cd dub \
&& ldmd2 -run build.d \
&& cp bin/dub /usr/local/bin/

# build rdmd #########################################################

RUN git clone --single-branch --branch ${RDMD_BRANCH} https://github.com/dlang/tools \
&& cd tools \
&& sed -i "s|^DMD = .*$|DMD = ldmd2|" posix.mak \
&& sed -i "s|^INSTALL_DIR = .*$|INSTALL_DIR = $PWD|" posix.mak \
&& make -f posix.mak install \
&& cp bin/rdmd /usr/local/bin/


COPY docker.build.sh /docker.build.sh
RUN chmod +x /docker.build.sh

ENTRYPOINT [ "/docker.build.sh" ]
5 changes: 5 additions & 0 deletions ci/docker.build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
set -e -u

cd /core/
dub build -c static --compiler=ldc2
4 changes: 3 additions & 1 deletion ci/travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ dub --compiler=${DC} -- --sanitycheck

# Compile to static binary with ldc
if [[ "${DC}" == "ldc2" ]]; then
dub build -c static --compiler=${DC}
docker build -t dlangtour_build ./ci/
docker run --rm -v `pwd`:/core/ -ti dlangtour_build
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the interactive run ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied from the docker run below.


docker build -t dlangtour_test_image ./
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -ti dlangtour_test_image --wait-until-pulled --sanitycheck
fi
4 changes: 3 additions & 1 deletion dub.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ configuration "static" {
targetType "executable"
versions "VibeDefaultMain"
lflags "-lz" "-lssl" "-lcrypto" "-ldl" platform="posix"
dflags "-static" platform="posix"

// gcc on alpine has issues with the ld.gold linker, use bfd instead
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be better to pass this as DFLAGS from alpine as ld.gold does drastically speed-up the build time locally.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately ld.gold has some issues on musl, so either BFD or LLD has to be used.

dflags "-linker=bfd" "-static" platform="posix"
}
configuration "library" {
versions "VibeCustomMain"
Expand Down