This repository has been archived by the owner on Jun 29, 2023. It is now read-only.
forked from docker/golang-cross
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
100 lines (88 loc) · 3.5 KB
/
Dockerfile
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
ARG GO_VERSION=1.19
# OS-X SDK parameters
# Go 1.19 supports macOS 10.13 and higher
# https://github.com/golang/go/issues/23011#issuecomment-962269386
ARG OSX_SDK=MacOSX11.3.sdk
ARG OSX_VERSION_MIN=10.13
ARG OSX_CROSS_COMMIT=61925a29c404fc547ce9d51eb2ee4a09bd6533da
# Libtool parameters
ARG LIBTOOL_VERSION=2.4.6_4
# Getting a compiled version of libtool is a total PITA.
# But we can get one from Homebrew!
#
# Here's how you do it:
# Homebrew stores compiled packages as OCI artifacts.
#
# Get the manifest with:
# curl https://ghcr.io/v2/homebrew/core/libtool/manifests/2.4.6_4 -H'Authorization: Bearer QQ==' -H'Accept: application/vnd.oci.image.index.v1+json'
#
# Then pick the bottle digest you want (from the list of options)
ARG LIBTOOL_BOTTLE_DIGEST="35c8d3e024a2507d7d3244bcebdb0ccc61c25ae292e6df6025f78c7342a9799d"
FROM golang:${GO_VERSION}-bullseye AS base
ARG APT_MIRROR
RUN sed -ri "s/(httpredir|deb).debian.org/${APT_MIRROR:-deb.debian.org}/g" /etc/apt/sources.list \
&& sed -ri "s/(security).debian.org/${APT_MIRROR:-security.debian.org}/g" /etc/apt/sources.list
ENV OSX_CROSS_PATH=/osxcross
ENV MUSL_CROSS_PATH=/musl
FROM base AS osx-sdk
ARG OSX_SDK
COPY tarballs/${OSX_SDK}.tar.xz "${OSX_CROSS_PATH}/tarballs/${OSX_SDK}.tar.xz"
FROM base AS cross-base
ARG DEBIAN_FRONTEND=noninteractive
# Dependencies for https://github.com/tpoechtrager/osxcross:
# TODO split these into "build-time" and "runtime" dependencies so that build-time deps do not end up in the final image
RUN apt-get update -qq && apt-get install -y -q --no-install-recommends \
bzip2 \
clang \
file \
llvm \
patch \
xz-utils \
cmake \
git \
python \
libssl-dev \
lzma-dev \
libxml2-dev \
&& rm -rf /var/lib/apt/lists/*
FROM cross-base AS osx-cross
ARG OSX_CROSS_COMMIT
WORKDIR "${OSX_CROSS_PATH}"
RUN git clone https://github.com/tpoechtrager/osxcross.git . \
&& git checkout -q "${OSX_CROSS_COMMIT}" \
&& rm -rf ./.git
COPY --from=osx-sdk "${OSX_CROSS_PATH}/." "${OSX_CROSS_PATH}/"
ARG OSX_VERSION_MIN
RUN UNATTENDED=yes OSX_VERSION_MIN=${OSX_VERSION_MIN} ./build.sh
FROM base AS libtool
ARG LIBTOOL_VERSION
ARG LIBTOOL_BOTTLE_DIGEST
ARG OSX_SDK
RUN mkdir -p "${OSX_CROSS_PATH}/target/SDK/${OSX_SDK}/usr/"
RUN curl -sSL -H'Authorization: Bearer QQ==' "https://ghcr.io/v2/homebrew/core/libtool/blobs/sha256:${LIBTOOL_BOTTLE_DIGEST}" \
| tar -xzf - \
-C "${OSX_CROSS_PATH}/target/SDK/${OSX_SDK}/usr/" \
--strip-components=2 \
"libtool/${LIBTOOL_VERSION}/include/" \
"libtool/${LIBTOOL_VERSION}/lib/"
FROM cross-base AS musl-cross
WORKDIR "${MUSL_CROSS_PATH}"
# https://more.musl.cc/GCC-MAJOR-VERSION/HOST-ARCH-linux-musl/CROSS-ARCH-linux-musl-cross.tgz
RUN curl -sf https://more.musl.cc/11/x86_64-linux-musl/aarch64-linux-musl-cross.tgz | tar zxf -
RUN curl -sf https://more.musl.cc/11/x86_64-linux-musl/x86_64-linux-musl-cross.tgz | tar zxf -
FROM cross-base AS final
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update -qq && apt-get install -y -q --no-install-recommends \
libltdl-dev \
g++-aarch64-linux-gnu \
gcc-aarch64-linux-gnu \
g++-arm-linux-gnueabi \
gcc-arm-linux-gnueabi \
g++-mingw-w64 \
gcc-mingw-w64 \
parallel \
&& rm -rf /var/lib/apt/lists/*
COPY --from=osx-cross "${OSX_CROSS_PATH}/." "${OSX_CROSS_PATH}/"
COPY --from=libtool "${OSX_CROSS_PATH}/." "${OSX_CROSS_PATH}/"
COPY --from=musl-cross "${MUSL_CROSS_PATH}/." "${MUSL_CROSS_PATH}/"
ENV PATH=${OSX_CROSS_PATH}/target/bin:$PATH:${MUSL_CROSS_PATH}/aarch64-linux-musl-cross/bin:${MUSL_CROSS_PATH}/x86_64-linux-musl-cross/bin