From 32177648e0290ed385d455e403a685e5033b40e1 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Fri, 17 Sep 2021 04:06:56 +0200 Subject: [PATCH] Native cross compilation --- Dockerfile | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/Dockerfile b/Dockerfile index 93f7beb..f249934 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,38 +1,47 @@ ARG MSMTP_VERSION=1.8.16 +ARG ALPINE_S6_VERSION=3.14-2.2.0.3 +ARG XX_VERSION=1.0.0-rc.2 -FROM --platform=${BUILDPLATFORM:-linux/amd64} crazymax/alpine-s6:3.14-2.2.0.3 AS download -RUN apk --update --no-cache add curl tar unzip xz +FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx +FROM --platform=$BUILDPLATFORM crazymax/alpine-s6:${ALPINE_S6_VERSION} AS builder +RUN apk --update --no-cache add \ + clang \ + curl \ + file \ + make \ + pkgconf \ + tar \ + unzip \ + xz \ + && rm -rf /tmp/* ARG MSMTP_VERSION -WORKDIR /dist/msmtp +WORKDIR /src RUN curl -sSL "https://marlam.de/msmtp/releases/msmtp-$MSMTP_VERSION.tar.xz" | tar xJv --strip 1 -FROM crazymax/alpine-s6:3.14-2.2.0.3 AS builder -RUN apk --update --no-cache add \ - autoconf \ - automake \ - binutils \ - build-base \ +ARG TARGETPLATFORM +ENV XX_CC_PREFER_LINKER=ld +COPY --from=xx / / +RUN xx-apk --no-cache add \ + g++ \ gettext-dev \ gnutls-dev \ + libc-dev \ libidn2-dev \ libgsasl-dev \ - libsecret-dev \ - openssl-dev \ - && rm -rf /tmp/* - -COPY --from=download /dist/msmtp /tmp/msmtp -WORKDIR /tmp/msmtp -RUN ./configure \ + libsecret-dev +RUN set -x \ + && ./configure \ + --host=$(xx-clang --print-target-triple) \ --prefix=/usr \ --sysconfdir=/etc \ --mandir=/usr/share/man \ --localstatedir=/var \ && make -j$(nproc) \ - && make install \ - && msmtp --version + && make install +RUN msmtp --version -FROM crazymax/alpine-s6:3.14-2.2.0.3 +FROM crazymax/alpine-s6:${ALPINE_S6_VERSION} ENV S6_BEHAVIOUR_IF_STAGE2_FAILS="2" \ TZ="UTC" \ @@ -51,7 +60,6 @@ RUN apk --update --no-cache add \ libgsasl \ libsecret \ mailx \ - openssl \ shadow \ tzdata \ && ln -sf /usr/bin/msmtp /usr/sbin/sendmail \