-
Notifications
You must be signed in to change notification settings - Fork 3
/
Dockerfile
335 lines (289 loc) · 13.3 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
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
FROM alpine:3.7
WORKDIR /build
RUN apk --no-cache update && apk --no-cache upgrade && apk add --no-cache git
RUN git config --global user.name "Mingw" && \
git config --global user.email root@localhost
RUN git clone -b release_60 https://github.com/llvm-mirror/llvm.git && \
cd llvm/tools && \
git clone -b release_60 https://github.com/llvm-mirror/clang.git && \
git clone -b release_60 https://github.com/llvm-mirror/lld.git
RUN apk add --no-cache clang clang-dev linux-headers cmake \
build-base ninja make python2 python2-dev tar
ENV TOOLCHAIN_PREFIX=/build/prefix
ENV CMAKE_BUILD_TYPE=MinSizeRel
COPY ./scripts/build-llvm.sh build-llvm.sh
RUN ./build-llvm.sh $TOOLCHAIN_PREFIX $CMAKE_BUILD_TYPE
ENV ORIG_PATH=$PATH
ENV PATH=$TOOLCHAIN_PREFIX/bin:$ORIG_PATH
RUN git clone git://git.code.sf.net/p/mingw-w64/mingw-w64
ENV TOOLCHAIN_ARCHS="i686 x86_64 armv7"
# configure of the mingw-w64 crt needs bash :/
RUN apk --no-cache update && apk --no-cache upgrade && apk add --no-cache bash
# Install the wrapper scripts
COPY wrappers/clang-target-wrapper $TOOLCHAIN_PREFIX/bin
RUN cd $TOOLCHAIN_PREFIX/bin && \
for arch in $TOOLCHAIN_ARCHS; do \
for exec in clang clang++; do \
ln -s clang-target-wrapper $arch-w64-mingw32-$exec; \
done; \
done
COPY ./scripts/build-mingw-w64.sh build-mingw-w64.sh
RUN ./build-mingw-w64.sh $TOOLCHAIN_PREFIX $TOOLCHAIN_ARCHS
#TODO: rework compiler-rt libunwind and native mingw-w64 toolchain into scripts
RUN git clone -b release_60 https://github.com/llvm-mirror/compiler-rt.git
#TODO: Support i686 for mingw-w64
# Martell is working on a patch to force i686 like android does
RUN cd $TOOLCHAIN_PREFIX && ln -s i686-w64-mingw32 i386-w64-mingw32
# Manually build compiler-rt as a standalone project
RUN cd compiler-rt && \
for arch in $TOOLCHAIN_ARCHS; do \
buildarchname=$arch && \
libarchname=$arch && \
case $arch in \
armv7) \
libarchname=arm \
;; \
i686) \
buildarchname=i386 \
libarchname=i386 \
;; \
esac && \
mkdir build-$arch && cd build-$arch && cmake -G"Ninja" \
-DCMAKE_C_COMPILER=$arch-w64-mingw32-clang \
-DCMAKE_SYSTEM_NAME=Windows \
-DCMAKE_AR=$TOOLCHAIN_PREFIX/bin/llvm-ar \
-DCMAKE_RANLIB=$TOOLCHAIN_PREFIX/bin/llvm-ranlib \
-DCMAKE_C_COMPILER_WORKS=1 \
-DCMAKE_C_COMPILER_TARGET=$buildarchname-windows-gnu \
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=TRUE \
../lib/builtins && \
ninja && \
mkdir -p $TOOLCHAIN_PREFIX/lib/clang/6.0.0/lib/windows && \
cp lib/windows/libclang_rt.builtins-$buildarchname.a $TOOLCHAIN_PREFIX/lib/clang/6.0.0/lib/windows/libclang_rt.builtins-$libarchname.a && \
cd .. && rm -rf build-$arch || exit 1; \
done
COPY tests/test.c tests/test-tors.c /build/test/
RUN cd test && \
for arch in $TOOLCHAIN_ARCHS; do \
$arch-w64-mingw32-clang test.c -o test-c-$arch.exe || exit 1; \
done
RUN cd test && \
for arch in $TOOLCHAIN_ARCHS; do \
$arch-w64-mingw32-clang test-tors.c -o test-tors-$arch.exe || exit 1; \
done
RUN git clone -b release_60 https://github.com/llvm-mirror/libcxx.git && \
git clone -b release_60 https://github.com/llvm-mirror/libcxxabi.git && \
git clone -b release_60 https://github.com/llvm-mirror/libunwind.git
RUN cd libunwind && \
for arch in $TOOLCHAIN_ARCHS; do \
mkdir build-$arch && cd build-$arch && cmake -G"Ninja" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=$TOOLCHAIN_PREFIX/$arch-w64-mingw32 \
-DCMAKE_C_COMPILER=$arch-w64-mingw32-clang \
-DCMAKE_CXX_COMPILER=$arch-w64-mingw32-clang++ \
-DCMAKE_CROSSCOMPILING=TRUE \
-DCMAKE_SYSTEM_NAME=Windows \
-DCMAKE_C_COMPILER_WORKS=TRUE \
-DCMAKE_CXX_COMPILER_WORKS=TRUE \
-DCMAKE_AR=$TOOLCHAIN_PREFIX/bin/llvm-ar \
-DCMAKE_RANLIB=$TOOLCHAIN_PREFIX/bin/llvm-ranlib \
-DLLVM_NO_OLD_LIBSTDCXX=TRUE \
-DCXX_SUPPORTS_CXX11=TRUE \
-DLIBUNWIND_USE_COMPILER_RT=TRUE \
-DLIBUNWIND_ENABLE_THREADS=TRUE \
-DLIBUNWIND_ENABLE_SHARED=FALSE \
-DLIBUNWIND_ENABLE_CROSS_UNWINDING=FALSE \
-DCMAKE_CXX_FLAGS="-I/build/libcxx/include" \
.. && \
ninja && ninja install && \
cd .. && rm -rf build-$arch || exit 1; \
done
RUN cd libcxxabi && \
for arch in $TOOLCHAIN_ARCHS; do \
mkdir build-$arch && cd build-$arch && cmake -G"Ninja" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=$TOOLCHAIN_PREFIX/$arch-w64-mingw32 \
-DCMAKE_C_COMPILER=$arch-w64-mingw32-clang \
-DCMAKE_CXX_COMPILER=$arch-w64-mingw32-clang++ \
-DCMAKE_CROSSCOMPILING=TRUE \
-DCMAKE_SYSTEM_NAME=Windows \
-DCMAKE_C_COMPILER_WORKS=TRUE \
-DCMAKE_CXX_COMPILER_WORKS=TRUE \
-DCMAKE_AR=$TOOLCHAIN_PREFIX/bin/llvm-ar \
-DCMAKE_RANLIB=$TOOLCHAIN_PREFIX/bin/llvm-ranlib \
-DLIBCXXABI_USE_COMPILER_RT=ON \
-DLIBCXXABI_ENABLE_EXCEPTIONS=ON \
-DLIBCXXABI_ENABLE_THREADS=ON \
-DLIBCXXABI_INCLUDE_TESTS=OFF \
-DLIBCXXABI_TARGET_TRIPLE=$arch-w64-mingw32 \
-DLIBCXXABI_ENABLE_SHARED=OFF \
-DLIBCXXABI_LIBCXX_INCLUDES=../../libcxx/include \
-DLLVM_NO_OLD_LIBSTDCXX=TRUE \
-DCXX_SUPPORTS_CXX11=TRUE \
-DCMAKE_CXX_FLAGS="-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS" \
.. && \
ninja && \
cd .. || exit 1; \
done
COPY patches/libcxx/0001-libcxx-Move-Windows-threading-support-into-a-.cpp-fi.patch /build/
RUN cd libcxx && git am ../0001-libcxx-Move-Windows-threading-support-into-a-.cpp-fi.patch
RUN cd libcxx && \
for arch in $TOOLCHAIN_ARCHS; do \
mkdir build-$arch && cd build-$arch && cmake -G"Ninja" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=$TOOLCHAIN_PREFIX/$arch-w64-mingw32 \
-DCMAKE_C_COMPILER=$arch-w64-mingw32-clang \
-DCMAKE_CXX_COMPILER=$arch-w64-mingw32-clang++ \
-DCMAKE_CROSSCOMPILING=TRUE \
-DCMAKE_SYSTEM_NAME=Windows \
-DCMAKE_C_COMPILER_WORKS=TRUE \
-DCMAKE_CXX_COMPILER_WORKS=TRUE \
-DCMAKE_AR=$TOOLCHAIN_PREFIX/bin/llvm-ar \
-DCMAKE_RANLIB=$TOOLCHAIN_PREFIX/bin/llvm-ranlib \
-DLIBCXX_USE_COMPILER_RT=ON \
-DLIBCXX_INSTALL_HEADERS=ON \
-DLIBCXX_ENABLE_EXCEPTIONS=ON \
-DLIBCXX_ENABLE_THREADS=ON \
-DLIBCXX_ENABLE_MONOTONIC_CLOCK=ON \
-DLIBCXX_ENABLE_SHARED=OFF \
-DLIBCXX_SUPPORTS_STD_EQ_CXX11_FLAG=TRUE \
-DLIBCXX_HAVE_CXX_ATOMICS_WITHOUT_LIB=TRUE \
-DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=OFF \
-DLIBCXX_ENABLE_FILESYSTEM=OFF \
-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=TRUE \
-DLIBCXX_CXX_ABI=libcxxabi \
-DLIBCXX_CXX_ABI_INCLUDE_PATHS=../../libcxxabi/include \
-DLIBCXX_CXX_ABI_LIBRARY_PATH=../../libcxxabi/build-$arch/lib \
-DCMAKE_CXX_FLAGS="-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS" \
.. && \
ninja && ninja install && \
../utils/merge_archives.py \
--ar llvm-ar \
-o $TOOLCHAIN_PREFIX/$arch-w64-mingw32/lib/libc++.a \
$TOOLCHAIN_PREFIX/$arch-w64-mingw32/lib/libc++.a \
$TOOLCHAIN_PREFIX/$arch-w64-mingw32/lib/libunwind.a && \
cd .. && rm -rf build-$arch || exit 1; \
done
# TODO: actually install c++ headers into c++
RUN cd $TOOLCHAIN_PREFIX/include && ln -s ../$(echo $TOOLCHAIN_ARCHS | awk '{print $1}')-w64-mingw32/include/c++ .
COPY tests/test.cpp tests/test-exception.cpp /build/test/
RUN cd test && \
for arch in $TOOLCHAIN_ARCHS; do \
$arch-w64-mingw32-clang++ test.cpp -o test-cpp-$arch.exe -fno-exceptions -lpsapi || exit 1; \
done
RUN cd test && \
for arch in $TOOLCHAIN_ARCHS; do \
$arch-w64-mingw32-clang++ test-exception.cpp -o test-exception-$arch.exe -lpsapi || exit 1; \
done
ENV CROSS_TOOLCHAIN_PREFIX=/build/cross
# ENV PATH=$CROSS_TOOLCHAIN_PREFIX-$arch/bin:$ORIG_PATH
ENV AR=llvm-ar
ENV RANLIB=llvm-ranlib
ENV AS=llvm-as
ENV NM=llvm-nm
RUN apk --no-cache update && apk --no-cache upgrade && apk add --no-cache wine
COPY patches/llvm/0001-cmake-Don-t-build-Native-llvm-config-when-cross-comp.patch /build/
RUN cd llvm && git am ../0001-cmake-Don-t-build-Native-llvm-config-when-cross-comp.patch
#COPY patches/llvm/0001-fixup-tblgen.patch /build/
#RUN cd llvm && git am ../0001-fixup-tblgen.patch
COPY patches/llvm/0002-CMAKE-apply-O3-for-mingw-clang.patch /build/
RUN cd llvm && git am ../0002-CMAKE-apply-O3-for-mingw-clang.patch
COPY patches/llvm/0003-CMAKE-disable-mbig-obj-for-mingw-clang-asm.patch /build/
RUN cd llvm && git am ../0003-CMAKE-disable-mbig-obj-for-mingw-clang-asm.patch
#COPY patches/lld/0001-LLD-Protect-COFF.h-from-winnt-defines.patch /build/
#RUN cd llvm/tools/lld && git am ../../../0001-LLD-Protect-COFF.h-from-winnt-defines.patch
# Only cross building to x86_64 for now, change this to add i386/i686 if you wish.
ENV HOST_TOOLCHAIN_ARCHS="x86_64"
# Build LLVM, Clang and LLD for mingw-w64
RUN cd llvm && \
for arch in $HOST_TOOLCHAIN_ARCHS; do \
mkdir build-cross-$arch && cd build-cross-$arch && cmake -G"Ninja" \
-DCMAKE_C_COMPILER=$TOOLCHAIN_PREFIX/bin/$arch-w64-mingw32-clang \
-DCMAKE_CXX_COMPILER=$TOOLCHAIN_PREFIX/bin/$arch-w64-mingw32-clang++ \
-DCMAKE_INSTALL_PREFIX=$CROSS_TOOLCHAIN_PREFIX-$arch \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CROSSCOMPILING=TRUE \
-DCMAKE_SYSTEM_NAME=Windows \
-DCMAKE_AR=$TOOLCHAIN_PREFIX/bin/llvm-ar \
-DCMAKE_RANLIB=$TOOLCHAIN_PREFIX/bin/llvm-ranlib \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_TARGETS_TO_BUILD="ARM;X86" \
-DCLANG_DEFAULT_CXX_STDLIB=libc++ \
-DCLANG_DEFAULT_LINKER=lld \
-DCLANG_DEFAULT_RTLIB=compiler-rt \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_CXX_FLAGS="-D_GNU_SOURCE -Wl,-lpsapi" \
-DLLVM_CONFIG_PATH=$TOOLCHAIN_PREFIX/bin/llvm-config \
-DLLVM_TABLEGEN=$TOOLCHAIN_PREFIX/bin/llvm-tblgen \
-DCLANG_TABLEGEN=$TOOLCHAIN_PREFIX/bin/clang-tblgen \
-DCMAKE_SYSTEM_PROGRAM_PATH=$TOOLCHAIN_PREFIX/bin \
-DCMAKE_FIND_ROOT_PATH=$TOOLCHAIN_PREFIX \
-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
../ && ninja && ninja install && \
cd .. && rm -rf build-cross-$arch || exit 1; \
done
# Transfer mingw-w64-headers
RUN cd mingw-w64/mingw-w64-headers && \
for host in $HOST_TOOLCHAIN_ARCHS; do \
for arch in $TOOLCHAIN_ARCHS; do \
cd build-$arch && \
DESTDIR=$CROSS_TOOLCHAIN_PREFIX-$host/$arch-w64-mingw32 \
make install && cd .. || exit 1; \
done; \
done
# Install the $TUPLE-clang binaries
COPY wrappers/clang-target-wrapper $CROSS_TOOLCHAIN_PREFIX-i686/bin
RUN for host in $HOST_TOOLCHAIN_ARCHS; do \
cd $CROSS_TOOLCHAIN_PREFIX-$host/bin && \
for arch in $TOOLCHAIN_ARCHS; do \
for exec in clang clang++; do \
ln -s clang-target-wrapper $arch-w64-mingw32-$exec; \
done; \
done; \
done
# Transfer mingw-w64-crt, libcxx and libcxxabi
RUN cd mingw-w64/mingw-w64-crt && \
for host in $HOST_TOOLCHAIN_ARCHS; do \
for arch in $TOOLCHAIN_ARCHS; do \
cd build-$arch && \
DESTDIR=$CROSS_TOOLCHAIN_PREFIX-$host/$arch-w64-mingw32 \
make install && cd .. || exit 1; \
done; \
done
# Transfer compiler-rt
RUN cd compiler-rt && \
for host in $HOST_TOOLCHAIN_ARCHS; do \
for arch in $TOOLCHAIN_ARCHS; do \
buildarchname=$arch && \
libarchname=$arch && \
case $arch in \
armv7) \
libarchname=arm \
;; \
i686) \
buildarchname=i386 \
libarchname=i386 \
;; \
esac && \
mkdir -p $CROSS_TOOLCHAIN_PREFIX-$host/lib/clang/6.0.0/lib/windows && \
cp $TOOLCHAIN_PREFIX/lib/clang/6.0.0/lib/windows/libclang_rt.builtins-$libarchname.a $CROSS_TOOLCHAIN_PREFIX-$host/lib/clang/6.0.0/lib/windows/libclang_rt.builtins-$libarchname.a && \
cd .. && rm -rf build-$arch || exit 1; \
done; \
done
RUN apk add --no-cache wine freetype
RUN WINEARCH=win64 winecfg
COPY tests/test.c tests/test-tors.c /build/test/
# wine currently fails when calling clang
# https://bugs.winehq.org/show_bug.cgi?id=44061
# fixme:crypt:CRYPT_LoadProvider Failed to load dll L"C:\\windows\\system32\\rsaenh.dll"
# LLVM ERROR: Could not acquire a cryptographic context: Unknown error (0x8009001D)
RUN cd test && \
for arch in $TOOLCHAIN_ARCHS; do \
wine64 $CROSS_TOOLCHAIN_PREFIX-x86_64/bin/clang -target x86_64-windows-gnu test.c -o test-c-$arch.exe || exit 1; \
done
RUN cd test && \
for arch in $TOOLCHAIN_ARCHS; do \
wine64 $CROSS_TOOLCHAIN_PREFIX-x86_64/bin/clang -target x86_64-windows-gnu test-tors.c -o test-tors-$arch.exe || exit 1; \
done