-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
72 lines (66 loc) · 3.85 KB
/
Copy pathDockerfile
File metadata and controls
72 lines (66 loc) · 3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# syntax=docker/dockerfile:1@sha256:ecfaec9ed6d810b56388c508f4121597bfbba70d41a6dfeee4d8cad5f295fc32
#
# True cross-compilation, no QEMU: this stage always runs on the native
# builder architecture (--platform=$BUILDPLATFORM) and uses zig cc [1] to
# cross-compile static musl binaries for every requested TARGETPLATFORM.
# Faster and far more reliable than emulating apt/configure/make per-arch.
# [1] https://andrewkelley.me/post/zig-cc-powerful-drop-in-substitute-gcc-clang.html
FROM --platform=$BUILDPLATFORM debian:trixie-slim@sha256:d7e12182ce18b85b93007c1dedf31f2d29e01ccf3182cc4017c709b6259bc132 AS build
RUN apt-get update && apt-get install -y --no-install-recommends \
curl xz-utils ca-certificates make binutils autotools-dev \
&& rm -rf /var/lib/apt/lists/*
ARG ZIG_VERSION=0.16.0
ARG BUILDARCH
RUN set -eux; \
case "${BUILDARCH}" in \
amd64) zigarch=x86_64 ;; \
arm64) zigarch=aarch64 ;; \
*) echo "unsupported builder arch ${BUILDARCH}" >&2; exit 1 ;; \
esac; \
curl -fL "https://ziglang.org/download/${ZIG_VERSION}/zig-${zigarch}-linux-${ZIG_VERSION}.tar.xz" | tar -xJ -C /opt \
&& mv "/opt/zig-${zigarch}-linux-${ZIG_VERSION}" /opt/zig
ENV PATH="/opt/zig:${PATH}"
# Map Docker's target platform to a zig/musl target triple. arm/v6 and arm/v7
# share one triple: the v6 baseline zig emits runs fine on v7 hardware too.
ARG TARGETARCH
ARG TARGETVARIANT
RUN set -eux; \
case "${TARGETARCH}${TARGETVARIANT}" in \
amd64) triple=x86_64-linux-musl ;; \
arm64) triple=aarch64-linux-musl ;; \
armv6) triple=arm-linux-musleabihf ;; \
armv7) triple=arm-linux-musleabihf ;; \
ppc64le) triple=powerpc64le-linux-musl ;; \
s390x) triple=s390x-linux-musl ;; \
*) echo "unsupported platform ${TARGETARCH}${TARGETVARIANT}" >&2; exit 1 ;; \
esac; \
echo "$triple" > /triple; \
printf '#!/bin/sh\nexec zig cc -target %s "$@"\n' "$triple" > /usr/local/bin/musl-cc; \
printf '#!/bin/sh\nexec zig ar "$@"\n' > /usr/local/bin/musl-ar; \
printf '#!/bin/sh\nexec zig ranlib "$@"\n' > /usr/local/bin/musl-ranlib; \
chmod +x /usr/local/bin/musl-cc /usr/local/bin/musl-ar /usr/local/bin/musl-ranlib
ENV CC=/usr/local/bin/musl-cc AR=/usr/local/bin/musl-ar RANLIB=/usr/local/bin/musl-ranlib
# gnu89: this 2001-era C needs implicit-int/implicit-function-declaration/
# incompatible-pointer-types downgraded from modern clang's default errors.
# -O2 -fwrapv: zig cc's default -O0 traps signed-overflow (a real latent bug
# in aalib's aamktabl.c this code has always relied on silently wrapping).
ENV CFLAGS="-static -std=gnu89 -O2 -fwrapv -Wno-date-time -Wno-implicit-int -Wno-implicit-function-declaration -Wno-int-conversion -Wno-incompatible-function-pointer-types -Wno-return-type"
RUN curl -fL 'https://sourceforge.net/projects/aa-project/files/aa-lib/1.4rc5/aalib-1.4rc5.tar.gz/download' -o aalib.tar.gz \
&& tar -xzf aalib.tar.gz && rm aalib.tar.gz
WORKDIR /aalib-1.4.0
RUN cp /usr/share/misc/config.guess /usr/share/misc/config.sub . \
&& ./configure --host="$(cat /triple)" --disable-shared --enable-static \
&& make && make install
WORKDIR /
RUN curl -fL 'https://sourceforge.net/projects/aa-project/files/bb/1.3rc1/bb-1.3rc1.tar.gz/download' -o bb.tar.gz \
&& tar -xzf bb.tar.gz && rm bb.tar.gz
WORKDIR /bb-1.3.0
# regparm is an x86-only GCC attribute; bb's checked-in config.h applies it
# unconditionally under __GNUC__, which zig's clang hard-errors on elsewhere.
RUN sed -i 's/#define REGISTERS(n) __attribute__ ((regparm(n)))/#if defined(__i386__) || defined(__x86_64__)\n#define REGISTERS(n) __attribute__ ((regparm(n)))\n#else\n#define REGISTERS(n)\n#endif/' config.h \
&& cp /usr/share/misc/config.guess /usr/share/misc/config.sub . \
&& ./configure --host="$(cat /triple)" \
&& make LDFLAGS="-static"
FROM scratch
COPY --from=build /bb-1.3.0/bb /bb
CMD ["/bb", "-extended", "-loop"]