-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.manylinux
139 lines (95 loc) · 3.15 KB
/
Dockerfile.manylinux
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
# syntax=docker/dockerfile:1.4
ARG WHEEL_ARCH
ARG PYTHON_VERSION
FROM scratch as ccache
# these must be injected by bake
FROM scratch as cmake
FROM scratch as swig
FROM scratch as ortools-src
FROM --platform=linux/amd64 python:${PYTHON_VERSION}-slim-buster as ortools-builder-base
RUN <<EOT
#!/bin/bash -ex
apt-get update
apt-get install --no-install-recommends -y \
ca-certificates ccache
update-ca-certificates
EOT
WORKDIR /src
# setup ccache
ENV PATH="/usr/lib/ccache:$PATH" CCACHE_DIR="/ccache"
# install cmake
COPY --link --from=cmake / /
# install swig
COPY --link --from=swig / /
WORKDIR /src/or-tools
COPY --link --from=ortools-src / .
RUN apt-get install --no-install-recommends -y \
git ninja-build clang lld make
COPY ./cmake-glpk-v9.3.patch .
COPY ./bdist-wheel-cross.patch .
# cross-compiler helper
FROM --platform=linux/amd64 tonistiigi/xx AS xx
# build or-tools
FROM ortools-builder-base as ortools-builder
# setup cross-compiler scripts
COPY --from=xx / /
ARG TARGETPLATFORM
ARG WHEEL_ARCH
RUN xx-apt-get install --no-install-recommends -y libstdc++-8-dev libc6-dev llvm
RUN <<EOT
#!/bin/bash -ex
export PATH="/root/.local/bin:$PATH"
git apply ./cmake-glpk-v9.3.patch
git apply ./bdist-wheel-cross.patch
xx-clang --setup-target-triple
# for some reason you have to do this twice for -DPYTHON_MODULE_EXTENSION to
# take effect :(
for i in {1..2}; do
cmake -S . -B build -G "Ninja" -DCMAKE_BUILD_TYPE=Release \
-DBUILD_DEPS=ON -DUSE_GLPK=ON -DBUILD_GLPK=ON -DBUILD_FLATZINC=OFF \
-DBUILD_PYTHON=ON -DBUILD_SAMPLES=OFF -DBUILD_EXAMPLES=OFF \
-DFETCH_PYTHON_DEPS=ON \
-DBUILD_TESTING=OFF \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_ASM_COMPILER=clang \
-DPKG_CONFIG_EXECUTABLE="$(xx-clang --print-prog-name=pkg-config)" \
-DCMAKE_C_COMPILER_TARGET="$(xx-clang --print-target-triple)" \
-DCMAKE_CXX_COMPILER_TARGET="$(xx-clang++ --print-target-triple)" \
-DCMAKE_ASM_COMPILER_TARGET="$(xx-clang --print-target-triple)" \
-DCMAKE_STRIP=/usr/bin/$(xx-info)-strip \
-DPYTHON_BDIST_WHEEL_EXTRA_ARGS="--plat-name=linux-${WHEEL_ARCH}" \
-DPYTHON_MODULE_EXTENSION="$(python-config --extension-suffix | sed s/x86_64/${WHEEL_ARCH}/)"
done
EOT
RUN \
--mount=type=cache,target=/ccache,from=ccache \
--mount=type=cache,target=/lock,id=lock-$TARGETPLATFORM,sharing=locked <<EOT
#!/bin/bash -ex
xx-clang --setup-target-triple
export PATH="/root/.local/bin:$PATH"
cmake --build build --parallel 8
cp -r --dereference /ccache /ccache-export
EOT
# package up a manylinux wheel
FROM python:${PYTHON_VERSION}-slim-buster as tester
ARG TARGETPLATFORM
ARG WHEEL_ARCH
RUN apt-get update && apt-get install --no-install-recommends -y patchelf
WORKDIR /dist
COPY --from=ortools-builder /src/or-tools/build/python/dist .
RUN <<EOT
#!/bin/bash -ex
pip install auditwheel
mkdir -p /wheelhouse
auditwheel show *.whl
plat="manylinux_2_27_${WHEEL_ARCH}"
auditwheel repair --plat "$plat" *.whl -w /wheelhouse
EOT
RUN pip install /wheelhouse/*.whl
COPY ./test_ortools.py .
RUN python test_ortools.py
FROM scratch as output
WORKDIR /wheelhouse
COPY --from=tester /wheelhouse/*.whl .
COPY --from=ortools-builder /ccache-export /ccache