-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Dockerfile.j2
275 lines (252 loc) · 13.5 KB
/
Dockerfile.j2
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
{% if manylinux -%}
FROM {{ manylinux }} AS manylinux
{% elif musllinux -%}
FROM {{ musllinux }} as musllinux
{% endif %}
{%- if base %}
FROM {{ base }}
ENV TARGET_READELF={{ target }}-readelf
{%- else %}
FROM {{ toolchain_os }} AS toolchain
{% endif %}
{%- if ct_ng_version %}
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && \
apt-get install --no-install-recommends -y \
automake \
bison \
bzip2 \
ca-certificates \
cmake \
curl \
file \
flex \
g++ \
gawk \
gdb \
git \
gperf \
help2man \
libncurses-dev \
libssl-dev \
libtool-bin \
make \
ninja-build \
patch \
pkg-config \
python3 \
sudo \
texinfo \
unzip \
wget \
xz-utils \
libssl-dev \
libffi-dev
# Install crosstool-ng
RUN curl -Lf https://github.com/crosstool-ng/crosstool-ng/archive/{{ ct_ng_version }}.tar.gz | tar xzf - && \
cd crosstool-ng-{{ ct_ng_version }} && \
./bootstrap && \
./configure --prefix=/usr/local && \
make -j4 && \
make install && \
cd .. && rm -rf crosstool-ng-*
COPY .config /tmp/toolchain.config
# Build cross compiler
RUN mkdir build && \
cd build && \
cp /tmp/toolchain.config .config && \
export CT_ALLOW_BUILD_AS_ROOT_SURE=1 && \
ct-ng build.2 || { tail -n 500 build.log; exit $ERRCODE; } && \
cd .. && \
rm -rf build
FROM ubuntu:22.04
# Copy cross toolchain
COPY --from=toolchain /usr/{{ target }} /usr/{{ target }}
ENV DEBIAN_FRONTEND noninteractive
ENV PATH=$PATH:/usr/{{ target }}/bin
ENV CC_{{ target | replace('ibm', 'unknown') | replace('-', '_') }}={{ target }}-gcc \
AR_{{ target | replace('ibm', 'unknown') | replace('-', '_') }}={{ target }}-ar \
CXX_{{ target | replace('ibm', 'unknown') | replace('-', '_') }}={{ target }}-g++
ENV TARGET_CC={{ target }}-gcc \
TARGET_AR={{ target }}-ar \
TARGET_RANLIB={{ target }}-ranlib \
TARGET_CXX={{ target }}-g++ \
TARGET_READELF={{ target }}-readelf \
TARGET_SYSROOT=/usr/{{ target }}/{{ target }}/sysroot/ \
TARGET_C_INCLUDE_PATH=/usr/{{ target }}/{{ target }}/sysroot/usr/include/
ENV CARGO_BUILD_TARGET={{ target | replace('ibm', 'unknown') }}
ENV CARGO_TARGET_{{ target | replace('ibm', 'unknown') | replace('-', '_') | upper }}_LINKER={{ target }}-gcc
RUN echo "set(CMAKE_SYSTEM_NAME Linux)\nset(CMAKE_SYSTEM_PROCESSOR {{ cmake_arch | default(arch) }})\nset(CMAKE_SYSROOT /usr/{{ target }}/{{ target }}/sysroot/)\nset(CMAKE_C_COMPILER {{ target }}-gcc)\nset(CMAKE_CXX_COMPILER {{ target }}-g++)" > /usr/{{ target }}/cmake-toolchain.cmake
ENV TARGET_CMAKE_TOOLCHAIN_FILE_PATH=/usr/{{ target }}/cmake-toolchain.cmake
{% endif %}
RUN echo 'Acquire::Retries "3";' > /etc/apt/apt.conf.d/80-retries && \
apt-get update && \
apt-get install --no-install-recommends -y \
curl \
git \
g++ \
make \
sudo \
wget \
software-properties-common \
gpg-agent \
cmake \
llvm-dev \
libclang-dev \
clang
{% if not musllinux -%}
ENV {{ target | replace('ibm', 'unknown') | replace('-', '_') | upper }}_OPENSSL_DIR=/usr/{{ target }}/
{% endif -%}
RUN add-apt-repository -y ppa:deadsnakes/ppa && \
apt-get update && \
apt-get install -y \
python3.7 python3.7-venv python3.7-dev \
python3.8 python3.8-venv python3.8-dev \
python3.9 python3.9-venv python3.9-dev \
python3.11 python3.11-venv python3.11-dev \
python3.12 python3.12-venv python3.12-dev \
python3.13 python3.13-venv python3.13-dev \
python3 python3-venv python3-dev python-is-python3
RUN if [ "$(uname -m)" = "x86_64" ]; then export PYPY_ARCH="linux64"; else export PYPY_ARCH="aarch64"; fi && \
mkdir -p /usr/local/pypy/pypy3.7 && \
curl -sqL https://downloads.python.org/pypy/pypy3.7-v7.3.9-$PYPY_ARCH.tar.bz2 | tar xjf - -C /usr/local/pypy/pypy3.7 --strip-components=1 && \
ln -s /usr/local/pypy/pypy3.7/bin/pypy /usr/local/bin/pypy3.7 && \
mkdir -p /usr/local/pypy/pypy3.8 && \
curl -sqL https://downloads.python.org/pypy/pypy3.8-v7.3.11-$PYPY_ARCH.tar.bz2 | tar xjf - -C /usr/local/pypy/pypy3.8 --strip-components=1 && \
ln -s /usr/local/pypy/pypy3.8/bin/pypy /usr/local/bin/pypy3.8 && \
mkdir -p /usr/local/pypy/pypy3.9 && \
curl -sqL https://downloads.python.org/pypy/pypy3.9-v7.3.12-$PYPY_ARCH.tar.bz2 | tar xjf - -C /usr/local/pypy/pypy3.9 --strip-components=1 && \
ln -s /usr/local/pypy/pypy3.9/bin/pypy /usr/local/bin/pypy3.9 && \
mkdir -p /usr/local/pypy/pypy3.10 && \
curl -sqL https://downloads.python.org/pypy/pypy3.10-v7.3.12-$PYPY_ARCH.tar.bz2 | tar xjf - -C /usr/local/pypy/pypy3.10 --strip-components=1 && \
ln -s /usr/local/pypy/pypy3.10/bin/pypy /usr/local/bin/pypy3.10
{% if manylinux %}
COPY --from=manylinux /opt/_internal /opt/_internal
COPY --from=manylinux /opt/python /opt/python
{% elif musllinux %}
COPY --from=musllinux /opt/_internal /opt/_internal
COPY --from=musllinux /opt/python /opt/python
{% else %}
{% set python_target = "armv7l-unknown-linux-gnueabihf" if target.startswith("armv7-") else target %}
RUN mkdir -p /opt/python
RUN cd /tmp && \
VERS=3.7.17 && PREFIX=/opt/python/cp37-cp37m && \
curl -LO https://www.python.org/ftp/python/$VERS/Python-$VERS.tgz && \
tar xzf Python-$VERS.tgz && cd Python-$VERS && \
./configure CC=$TARGET_CC AR=$TARGET_AR READELF=$TARGET_READELF --host={{ python_target }} --target={{ python_target }} --prefix=$PREFIX --disable-shared --with-ensurepip=no --build=$(uname -m)-linux-gnu --disable-ipv6 ac_cv_have_long_long_format=yes ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no && \
{% if target.startswith('armv7-') -%}
sed -i 's/_PYTHON_HOST_PLATFORM=linux-arm/_PYTHON_HOST_PLATFORM=linux-armv7l/' Makefile && \
{% endif -%}
make -j4 && make -j4 install && \
rm -rf Python-$VERS.tgz Python-$VERS $PREFIX/share && \
# we don't need libpython*.a, and they're many megabytes
find $PREFIX -name '*.a' -print0 | xargs -0 rm -f && \
# We do not need the Python test suites
find $PREFIX -depth \( -type d -a -name test -o -name tests \) | xargs rm -rf && \
# We do not need precompiled .pyc and .pyo files.
find $PREFIX -type f -a \( -name '*.pyc' -o -name '*.pyo' \) -delete
RUN cd /tmp && \
VERS=3.8.20 && PREFIX=/opt/python/cp38-cp38 && \
curl -LO https://www.python.org/ftp/python/$VERS/Python-$VERS.tgz && \
tar xzf Python-$VERS.tgz && cd Python-$VERS && \
./configure CC=$TARGET_CC AR=$TARGET_AR READELF=$TARGET_READELF --host={{ python_target }} --target={{ python_target }} --prefix=$PREFIX --disable-shared --with-ensurepip=no --build=$(uname -m)-linux-gnu --disable-ipv6 ac_cv_have_long_long_format=yes ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no && \
{% if target.startswith('armv7-') -%}
sed -i 's/_PYTHON_HOST_PLATFORM=linux-arm/_PYTHON_HOST_PLATFORM=linux-armv7l/' Makefile && \
{% endif -%}
make -j4 && make -j4 install && \
rm -rf Python-$VERS.tgz Python-$VERS $PREFIX/share && \
# we don't need libpython*.a, and they're many megabytes
find $PREFIX -name '*.a' -print0 | xargs -0 rm -f && \
# We do not need the Python test suites
find $PREFIX -depth \( -type d -a -name test -o -name tests \) | xargs rm -rf && \
# We do not need precompiled .pyc and .pyo files.
find $PREFIX -type f -a \( -name '*.pyc' -o -name '*.pyo' \) -delete
RUN cd /tmp && \
VERS=3.9.20 && PREFIX=/opt/python/cp39-cp39 && \
curl -LO https://www.python.org/ftp/python/$VERS/Python-$VERS.tgz && \
tar xzf Python-$VERS.tgz && cd Python-$VERS && \
./configure CC=$TARGET_CC AR=$TARGET_AR READELF=$TARGET_READELF --host={{ python_target }} --target={{ python_target }} --prefix=$PREFIX --disable-shared --with-ensurepip=no --build=$(uname -m)-linux-gnu --disable-ipv6 ac_cv_have_long_long_format=yes ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no && \
{% if target.startswith('armv7-') -%}
sed -i 's/_PYTHON_HOST_PLATFORM=linux-arm/_PYTHON_HOST_PLATFORM=linux-armv7l/' Makefile && \
{% endif -%}
make -j4 && make -j4 install && \
rm -rf Python-$VERS.tgz Python-$VERS $PREFIX/share && \
# we don't need libpython*.a, and they're many megabytes
find $PREFIX -name '*.a' -print0 | xargs -0 rm -f && \
# We do not need the Python test suites
find $PREFIX -depth \( -type d -a -name test -o -name tests \) | xargs rm -rf && \
# We do not need precompiled .pyc and .pyo files.
find $PREFIX -type f -a \( -name '*.pyc' -o -name '*.pyo' \) -delete
RUN cd /tmp && \
VERS=3.10.15 && PREFIX=/opt/python/cp310-cp310 && \
curl -LO https://www.python.org/ftp/python/$VERS/Python-$VERS.tgz && \
tar xzf Python-$VERS.tgz && cd Python-$VERS && \
./configure CC=$TARGET_CC AR=$TARGET_AR READELF=$TARGET_READELF --host={{ python_target }} --target={{ python_target }} --prefix=$PREFIX --disable-shared --with-ensurepip=no --build=$(uname -m)-linux-gnu --disable-ipv6 ac_cv_have_long_long_format=yes ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no && \
{% if target.startswith('armv7-') -%}
sed -i 's/_PYTHON_HOST_PLATFORM=linux-arm/_PYTHON_HOST_PLATFORM=linux-armv7l/' Makefile && \
{% endif -%}
make -j4 && make -j4 install && \
rm -rf Python-$VERS.tgz Python-$VERS $PREFIX/share && \
# we don't need libpython*.a, and they're many megabytes
find $PREFIX -name '*.a' -print0 | xargs -0 rm -f && \
# We do not need the Python test suites
find $PREFIX -depth \( -type d -a -name test -o -name tests \) | xargs rm -rf && \
# We do not need precompiled .pyc and .pyo files.
find $PREFIX -type f -a \( -name '*.pyc' -o -name '*.pyo' \) -delete
RUN cd /tmp && \
VERS=3.11.10 && PREFIX=/opt/python/cp311-cp311 && \
curl -LO https://www.python.org/ftp/python/$VERS/Python-$VERS.tgz && \
tar xzf Python-$VERS.tgz && cd Python-$VERS && \
./configure CC=$TARGET_CC AR=$TARGET_AR READELF=$TARGET_READELF --host={{ python_target }} --target={{ python_target }} --prefix=$PREFIX --disable-shared --with-build-python=python3.11 --with-ensurepip=no --build=$(uname -m)-linux-gnu --disable-ipv6 ac_cv_have_long_long_format=yes ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no && \
{% if target.startswith('armv7-') -%}
sed -i 's/_PYTHON_HOST_PLATFORM=linux-arm/_PYTHON_HOST_PLATFORM=linux-armv7l/' Makefile && \
{% endif -%}
make -j4 && make -j4 install && \
rm -rf Python-$VERS.tgz Python-$VERS $PREFIX/share && \
# we don't need libpython*.a, and they're many megabytes
find $PREFIX -name '*.a' -print0 | xargs -0 rm -f && \
# We do not need the Python test suites
find $PREFIX -depth \( -type d -a -name test -o -name tests \) | xargs rm -rf && \
# We do not need precompiled .pyc and .pyo files.
find $PREFIX -type f -a \( -name '*.pyc' -o -name '*.pyo' \) -delete
RUN cd /tmp && \
VERS=3.12.7 && PREFIX=/opt/python/cp312-cp312 && \
curl -LO https://www.python.org/ftp/python/$VERS/Python-$VERS.tgz && \
tar xzf Python-$VERS.tgz && cd Python-$VERS && \
./configure CC=$TARGET_CC AR=$TARGET_AR READELF=$TARGET_READELF --host={{ python_target }} --target={{ python_target }} --prefix=$PREFIX --disable-shared --with-build-python=python3.12 --with-ensurepip=no --build=$(uname -m)-linux-gnu --disable-ipv6 ac_cv_have_long_long_format=yes ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no && \
{% if target.startswith('armv7-') -%}
sed -i 's/_PYTHON_HOST_PLATFORM=linux-arm/_PYTHON_HOST_PLATFORM=linux-armv7l/' Makefile && \
{% endif -%}
make -j4 && make -j4 install && \
rm -rf Python-$VERS.tgz Python-$VERS $PREFIX/share && \
# we don't need libpython*.a, and they're many megabytes
find $PREFIX -name '*.a' -print0 | xargs -0 rm -f && \
# We do not need the Python test suites
find $PREFIX -depth \( -type d -a -name test -o -name tests \) | xargs rm -rf && \
# We do not need precompiled .pyc and .pyo files.
find $PREFIX -type f -a \( -name '*.pyc' -o -name '*.pyo' \) -delete
RUN cd /tmp && \
VERS=3.13.0 && PREFIX=/opt/python/cp313-cp313 && \
curl -LO https://www.python.org/ftp/python/$VERS/Python-$VERS.tgz && \
tar xzf Python-$VERS.tgz && cd Python-$VERS && \
./configure CC=$TARGET_CC AR=$TARGET_AR READELF=$TARGET_READELF --host={{ python_target }} --target={{ python_target }} --prefix=$PREFIX --disable-shared --with-build-python=python3.13 --with-ensurepip=no --build=$(uname -m)-linux-gnu --disable-ipv6 ac_cv_have_long_long_format=yes ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no && \
{% if target.startswith('armv7-') -%}
sed -i 's/_PYTHON_HOST_PLATFORM=linux-arm/_PYTHON_HOST_PLATFORM=linux-armv7l/' Makefile && \
{% endif -%}
make -j4 && make -j4 install && \
rm -rf Python-$VERS.tgz Python-$VERS $PREFIX/share && \
# we don't need libpython*.a, and they're many megabytes
find $PREFIX -name '*.a' -print0 | xargs -0 rm -f && \
# We do not need the Python test suites
find $PREFIX -depth \( -type d -a -name test -o -name tests \) | xargs rm -rf && \
# We do not need precompiled .pyc and .pyo files.
find $PREFIX -type f -a \( -name '*.pyc' -o -name '*.pyo' \) -delete
{%- endif %}
RUN curl -sS https://bootstrap.pypa.io/pip/3.7/get-pip.py | "python3.7" && \
for VER in 3.13 3.12 3.11 3.8 3.9 3.10; do curl -sS https://bootstrap.pypa.io/get-pip.py | "python$VER"; done && \
curl -sS https://bootstrap.pypa.io/pip/3.7/get-pip.py | "pypy3.7" && \
for VER in 3.8 3.9 3.10; do curl -sS https://bootstrap.pypa.io/get-pip.py | "pypy$VER"; done && \
for VER in 3.13 3.12 3.11 3.7 3.8 3.9 3.10; do "python$VER" -m pip install --no-cache-dir cffi; done && \
python3 -m pip --version && \
python3 -m pip install --no-cache-dir auditwheel patchelf build && \
python3 -m pip install --no-cache-dir auditwheel-symbols