-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDockerfile.base
210 lines (194 loc) · 5.57 KB
/
Dockerfile.base
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
ARG ALPINE_VERSION="3.18"
ARG OSX_SDK="MacOSX15.0.sdk"
ARG OSX_SDK_URL="https://github.com/joseluisq/macosx-sdks/releases/download/15.0/${OSX_SDK}.tar.xz"
ARG OSX_CROSS_COMMIT="29fe6dd35522073c9df5800f8cd1feb4b9a993a8"
ARG CROSSTOOL_REPO_REF="329bb4da71c4eb16a898ce98fd29287cb7259b80"
# Get the macOS SDK
FROM --platform=$BUILDPLATFORM alpine:${ALPINE_VERSION} AS sdk
RUN apk --update --no-cache add ca-certificates curl tar xz
ARG OSX_SDK
ARG OSX_SDK_URL
RUN curl -sSL "$OSX_SDK_URL" -o "/$OSX_SDK.tar.xz"
RUN mkdir /osxsdk && tar -xf "/$OSX_SDK.tar.xz" -C "/osxsdk"
# Get the osxcross source
FROM --platform=$BUILDPLATFORM alpine:${ALPINE_VERSION} AS osxcross-src
RUN apk --update --no-cache add patch
WORKDIR /osxcross
ARG OSX_CROSS_COMMIT
ADD "https://github.com/tpoechtrager/osxcross.git#${OSX_CROSS_COMMIT}" .
# Patch osxcross -- from https://github.com/crazy-max/docker-osxcross
COPY <<EOF lcxx.patch
diff --git a/wrapper/target.cpp b/wrapper/target.cpp
index 82bf65c..a2520e2 100644
--- a/wrapper/target.cpp
+++ b/wrapper/target.cpp
@@ -741,6 +741,9 @@ bool Target::setup() {
(stdlib == StdLib::libstdcxx && usegcclibs)) {
fargs.push_back("-nostdinc++");
fargs.push_back("-Qunused-arguments");
+ if ((SDKOSNum >= OSVersion(11, 1)) && (stdlib == StdLib::libcxx)) {
+ fargs.push_back("-lc++");
+ }
}
if (stdlib == StdLib::libstdcxx && usegcclibs && targetarch.size() < 2 &&
EOF
RUN patch -p1 < lcxx.patch
# Pre-create the base image using existing macos-cross-compiler
FROM ghcr.io/shepherdjerred/macos-cross-compiler:latest AS base-macoscompilers
RUN export DEBIAN_FRONTEND="noninteractive" \
&& apt-get update \
&& apt-get install --no-install-recommends -y \
apt-transport-https \
autoconf \
automake \
bash \
binutils-multiarch-dev \
bison \
build-essential \
ca-certificates \
clang \
cmake \
curl \
flex \
gawk \
git \
gperf \
help2man \
libbz2-dev \
libc6-dev \
libgmp-dev \
liblzma-dev \
libmpc-dev \
libmpfr-dev \
libncurses-dev \
libpsi3-dev \
libssl-dev \
libtool \
libtool-bin \
libxml2-dev \
libz-dev \
libzstd-dev \
lld \
lzma-dev \
make \
meson \
patch \
patchelf \
python3 \
rsync \
sudo \
texinfo \
unzip \
uuid-dev \
wget \
xz-utils \
zlib1g-dev \
zstd \
&& apt-get clean \
&& rm -rf /var/cache/apt/archives /var/lib/apt/lists
# Build binutils for both x86_64 and aarch64
FROM base-macoscompilers AS build-osxcross
ARG OSX_SDK
WORKDIR /workspace
COPY --link --from=osxcross-src /osxcross .
COPY --link --from=sdk /$OSX_SDK.tar.xz ./tarballs/$OSX_SDK.tar.xz
ENV PATH="/osxcross/bin:$PATH"
RUN mkdir build
RUN OSX_VERSION_MIN=10.13 UNATTENDED=1 ENABLE_COMPILER_RT_INSTALL=1 TARGET_DIR=/osxcross TARGET_ARCH=x86_64 ./build_binutils.sh
RUN OSX_VERSION_MIN=10.13 UNATTENDED=1 ENABLE_COMPILER_RT_INSTALL=1 TARGET_DIR=/osxcross TARGET_ARCH=aarch64 ./build_binutils.sh
# Build crosstool-ng
FROM build-osxcross AS build-crosstool-ng
ARG CROSSTOOL_REPO_REF
RUN git clone https://github.com/crosstool-ng/crosstool-ng.git /tmp/crosstool-ng \
&& cd /tmp/crosstool-ng \
&& git checkout --progress --force $CROSSTOOL_REPO_REF \
&& ./bootstrap \
&& ./configure --prefix=/ct-ng \
&& make -j$(nproc) \
&& make install
# Final image
FROM ubuntu:noble AS final
RUN export DEBIAN_FRONTEND="noninteractive" \
&& apt-get update \
&& apt-get install --no-install-recommends -y \
apt-transport-https \
autoconf \
automake \
bash \
binutils-multiarch-dev \
bison \
build-essential \
ca-certificates \
clang \
cmake \
curl \
flex \
gawk \
git \
gperf \
help2man \
libbz2-dev \
libc6-dev \
libgmp-dev \
liblzma-dev \
libmpc-dev \
libmpfr-dev \
libncurses-dev \
libpsi3-dev \
libssl-dev \
libtool \
libtool-bin \
libxml2-dev \
libz-dev \
libzstd-dev \
lld \
lzma-dev \
make \
meson \
patch \
patchelf \
pkg-config \
python3 \
rsync \
sudo \
texinfo \
unzip \
uuid-dev \
wget \
xz-utils \
zlib1g-dev \
zstd \
&& apt-get clean \
&& rm -rf /var/cache/apt/archives /var/lib/apt/lists
# Copy across the base image compilers and SDKs
COPY --from=build-crosstool-ng /ct-ng /ct-ng
COPY --from=build-crosstool-ng /osxcross /osxcross
COPY --from=build-crosstool-ng /gcc /gcc
COPY --from=build-crosstool-ng /cctools /cctools
COPY --from=build-crosstool-ng /sdk /sdk
COPY --from=build-crosstool-ng /usr/local /usr/local
# Remove the ubuntu user and group
USER 0:0
RUN userdel ubuntu || true && groupdel ubuntu || true
# Ensure search paths for libraries are up to date
RUN rm /etc/ld.so.cache && ldconfig
# Runtime shell init script to ensure the user is created with the correct UID/GID for the mountpoint
COPY <<EOF /init.sh
#!/bin/bash
set -eEuo pipefail
qmk_uid=\$(stat --format='%u' \$TC_WORKDIR)
qmk_gid=\$(stat --format='%g' \$TC_WORKDIR)
groupadd --non-unique -g \$qmk_gid qmk
useradd --non-unique -u \$qmk_uid -g \$qmk_gid -N qmk
echo "qmk ALL=(ALL) NOPASSWD:ALL" | tee /etc/sudoers.d/qmk >/dev/null 2>&1
cd \$TC_WORKDIR
export PATH="/qmk/bin:/ct-ng/bin:/cctools/bin:/gcc/bin:/osxcross/binutils/bin:/osxcross/bin:\$PATH" # this must have `/cctools/bin:/gcc/bin` on \$PATH before osxcross equivalent
if [[ -n \$1 ]]; then
sudo -u qmk -g qmk -H --preserve-env=PATH -- bash -lic "exec \$*"
else
sudo -u qmk -g qmk -H --preserve-env=PATH -- bash -li
fi
EOF
RUN chmod +x /init.sh
ENTRYPOINT ["/init.sh"]
CMD ["bash"]