Build the OpenMP runtime in docker based builds
LLVM's OpenMP implementation only supports Windows on x86, and it requires a MASM-compatible assembler to build it. Build UASM for this purpose, for now. (UASM isn't available packaged in debian/ubuntu repos.) In the future, llvm-ml should be able to handle it instead, but it's not currently mature enough. Not including it in the regular build-all.sh for now, as UASM isn't generally available.
This commit is contained in:
1 parent
d5d30fae23
commit
9031eb6791
6 files changed
+222
-2
No files matched your search
+12
-1
@@ -19,8 +19,18 @@ ARG TOOLCHAIN_ARCHS="i686 x86_64 armv7 aarch64"
|
||||
|
||||
ARG DEFAULT_CRT=ucrt
|
||||
|
||||
# Build UASM, for building openmp. In the future, llvm-ml should be able
|
||||
# to handle it, but it doesn't yet.
|
||||
RUN git clone https://github.com/Terraspace/UASM && \
|
||||
cd UASM && \
|
||||
git checkout 16a853bd6de807fe2c42569f8375a029684c0f22 && \
|
||||
make -f gccLinux64.mak -j$(nproc) && \
|
||||
mkdir -p $TOOLCHAIN_PREFIX/bin && \
|
||||
cp GccUnixR/uasm $TOOLCHAIN_PREFIX/bin
|
||||
COPY wrappers/uasm-wrapper.sh $TOOLCHAIN_PREFIX/bin
|
||||
|
||||
# Build everything that uses the llvm monorepo. We need to build the mingw runtime before the compiler-rt/libunwind/libcxxabi/libcxx runtimes.
|
||||
COPY build-llvm.sh strip-llvm.sh install-wrappers.sh build-mingw-w64.sh build-mingw-w64-tools.sh build-compiler-rt.sh build-mingw-w64-libraries.sh build-libcxx.sh ./
|
||||
COPY build-llvm.sh strip-llvm.sh install-wrappers.sh build-mingw-w64.sh build-mingw-w64-tools.sh build-compiler-rt.sh build-mingw-w64-libraries.sh build-libcxx.sh build-openmp.sh ./
|
||||
COPY wrappers/*.sh wrappers/*.c wrappers/*.h ./wrappers/
|
||||
RUN ./build-llvm.sh $TOOLCHAIN_PREFIX && \
|
||||
./strip-llvm.sh $TOOLCHAIN_PREFIX && \
|
||||
@@ -31,6 +41,7 @@ RUN ./build-llvm.sh $TOOLCHAIN_PREFIX && \
|
||||
./build-mingw-w64-libraries.sh $TOOLCHAIN_PREFIX && \
|
||||
./build-libcxx.sh $TOOLCHAIN_PREFIX && \
|
||||
./build-compiler-rt.sh $TOOLCHAIN_PREFIX --build-sanitizers && \
|
||||
./build-openmp.sh $TOOLCHAIN_PREFIX && \
|
||||
rm -rf /build/*
|
||||
|
||||
# Build libssp
|
||||
|
||||
@@ -127,6 +127,34 @@ RUN cd test && \
|
||||
done; \
|
||||
done
|
||||
|
||||
# Build UASM, for building openmp. In the future, llvm-ml should be able
|
||||
# to handle it, but it doesn't yet.
|
||||
RUN git clone https://github.com/Terraspace/UASM && \
|
||||
cd UASM && \
|
||||
git checkout 16a853bd6de807fe2c42569f8375a029684c0f22 && \
|
||||
make -f gccLinux64.mak -j$(nproc) && \
|
||||
mkdir -p $TOOLCHAIN_PREFIX/bin && \
|
||||
cp GccUnixR/uasm $TOOLCHAIN_PREFIX/bin
|
||||
COPY wrappers/uasm-wrapper.sh $TOOLCHAIN_PREFIX/bin
|
||||
# Build OpenMP
|
||||
COPY build-openmp.sh ./
|
||||
RUN ./build-openmp.sh $TOOLCHAIN_PREFIX
|
||||
|
||||
# OpenMP on windows only supports x86.
|
||||
RUN cd test && \
|
||||
for arch in $TOOLCHAIN_ARCHS; do \
|
||||
case $arch in \
|
||||
i686|x86_64) \
|
||||
;; \
|
||||
*) \
|
||||
continue \
|
||||
;; \
|
||||
esac && \
|
||||
for test in hello-omp; do \
|
||||
$arch-w64-mingw32-clang $test.c -o $arch/$test.exe -fopenmp=libomp || exit 1; \
|
||||
done; \
|
||||
done
|
||||
|
||||
RUN cd test && \
|
||||
for arch in $TOOLCHAIN_ARCHS; do \
|
||||
cp $TOOLCHAIN_PREFIX/$arch-w64-mingw32/bin/*.dll $arch || exit 1; \
|
||||
|
||||
Executable
+115
@@ -0,0 +1,115 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2020 Martin Storsjo
|
||||
#
|
||||
# Permission to use, copy, modify, and/or distribute this software for any
|
||||
# purpose with or without fee is hereby granted, provided that the above
|
||||
# copyright notice and this permission notice appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
set -e
|
||||
|
||||
PREFIX="$1"
|
||||
if [ -z "$PREFIX" ]; then
|
||||
echo $0 dest
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$PREFIX"
|
||||
PREFIX="$(cd "$PREFIX" && pwd)"
|
||||
|
||||
export PATH="$PREFIX/bin:$PATH"
|
||||
|
||||
: ${ARCHS:=${TOOLCHAIN_ARCHS-i686 x86_64 armv7 aarch64}}
|
||||
|
||||
if [ ! -d llvm-project/openmp ] || [ -n "$SYNC" ]; then
|
||||
CHECKOUT_ONLY=1 ./build-llvm.sh
|
||||
fi
|
||||
|
||||
cd llvm-project/openmp
|
||||
|
||||
if [ -n "$(which ninja)" ]; then
|
||||
CMAKE_GENERATOR="Ninja"
|
||||
NINJA=1
|
||||
BUILDCMD=ninja
|
||||
else
|
||||
: ${CORES:=$(nproc 2>/dev/null)}
|
||||
: ${CORES:=$(sysctl -n hw.ncpu 2>/dev/null)}
|
||||
: ${CORES:=4}
|
||||
|
||||
case $(uname) in
|
||||
MINGW*)
|
||||
CMAKE_GENERATOR="MSYS Makefiles"
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
BUILDCMD=make
|
||||
fi
|
||||
|
||||
if [ ! -x "$(which uasm)" ]; then
|
||||
echo Building the OpenMP runtime requires UASM
|
||||
exit 1
|
||||
fi
|
||||
UASM=uasm
|
||||
case $(uname) in
|
||||
MINGW*|MSYS*)
|
||||
# On windows, only building with ninja works; building with msys make
|
||||
# ends up mangling the forward slashes in certain options to UASM.
|
||||
;;
|
||||
*)
|
||||
# UASM for unix doesn't support options with forward slashes, which CMake
|
||||
# produces in some places. And ninja on windows can't execute a
|
||||
# shell script, so this has to be done only on unix.
|
||||
UASM=uasm-wrapper.sh
|
||||
;;
|
||||
esac
|
||||
|
||||
for arch in $ARCHS; do
|
||||
CMAKEFLAGS=""
|
||||
case $arch in
|
||||
i686)
|
||||
;;
|
||||
x86_64)
|
||||
CMAKEFLAGS="$CMAKEFLAGS -DLIBOMP_ASMFLAGS=-win64"
|
||||
;;
|
||||
*)
|
||||
# Not supported
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
|
||||
[ -z "$CLEAN" ] || rm -rf build-$arch
|
||||
mkdir -p build-$arch
|
||||
cd build-$arch
|
||||
|
||||
cmake \
|
||||
${CMAKE_GENERATOR+-G} "$CMAKE_GENERATOR" \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_INSTALL_PREFIX="$PREFIX/$arch-w64-mingw32" \
|
||||
-DCMAKE_C_COMPILER=$arch-w64-mingw32-clang \
|
||||
-DCMAKE_CXX_COMPILER=$arch-w64-mingw32-clang++ \
|
||||
-DCMAKE_RC_COMPILER=$arch-w64-mingw32-windres \
|
||||
-DCMAKE_ASM_MASM_COMPILER=$UASM \
|
||||
-DCMAKE_CROSSCOMPILING=TRUE \
|
||||
-DCMAKE_SYSTEM_NAME=Windows \
|
||||
-DCMAKE_C_COMPILER_WORKS=TRUE \
|
||||
-DCMAKE_CXX_COMPILER_WORKS=TRUE \
|
||||
-DCMAKE_AR="$PREFIX/bin/llvm-ar" \
|
||||
-DCMAKE_RANLIB="$PREFIX/bin/llvm-ranlib" \
|
||||
-DLIBOMP_ENABLE_SHARED=TRUE \
|
||||
$CMAKEFLAGS \
|
||||
..
|
||||
$BUILDCMD ${CORES+-j$CORES}
|
||||
$BUILDCMD install
|
||||
rm -f $PREFIX/$arch-w64-mingw32/bin/*iomp5md*
|
||||
rm -f $PREFIX/$arch-w64-mingw32/lib/*iomp5md*
|
||||
cd ..
|
||||
done
|
||||
+11
-1
@@ -69,6 +69,7 @@ TESTS_CPP_DLL="tlstest-lib"
|
||||
TESTS_SSP="stacksmash"
|
||||
TESTS_ASAN="stacksmash"
|
||||
TESTS_UBSAN="ubsan"
|
||||
TESTS_OMP="hello-omp"
|
||||
TESTS_UWP="uwp-error"
|
||||
TESTS_IDL="idltest"
|
||||
TESTS_OTHER_TARGETS="hello"
|
||||
@@ -196,12 +197,21 @@ for arch in $ARCHS; do
|
||||
$arch-w64-mingw32-clang $test.c -o $TEST_DIR/$test.exe -fsanitize=undefined
|
||||
TESTS_EXTRA="$TESTS_EXTRA $test"
|
||||
done
|
||||
for test in $TESTS_OMP; do
|
||||
case $arch in
|
||||
# OpenMP on windows only supports x86.
|
||||
i686|x86_64) ;;
|
||||
*) continue ;;
|
||||
esac
|
||||
$arch-w64-mingw32-clang $test.c -o $TEST_DIR/$test.exe -fopenmp=libomp
|
||||
TESTS_EXTRA="$TESTS_EXTRA $test"
|
||||
done
|
||||
DLL="$TESTS_C_DLL $TESTS_CPP_DLL"
|
||||
compiler_rt_arch=$arch
|
||||
if [ "$arch" = "i686" ]; then
|
||||
compiler_rt_arch=i386
|
||||
fi
|
||||
for i in libc++ libunwind libssp-0 libclang_rt.asan_dynamic-$compiler_rt_arch; do
|
||||
for i in libc++ libunwind libssp-0 libclang_rt.asan_dynamic-$compiler_rt_arch libomp; do
|
||||
if [ -f $PREFIX/$arch-w64-mingw32/bin/$i.dll ]; then
|
||||
cp $PREFIX/$arch-w64-mingw32/bin/$i.dll $TEST_DIR
|
||||
DLL="$DLL $i"
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Martin Storsjo
|
||||
*
|
||||
* This file is part of llvm-mingw.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <omp.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
#pragma omp parallel
|
||||
printf("thread %d, nthreads %d\n", omp_get_thread_num(),
|
||||
omp_get_num_threads());
|
||||
return 0;
|
||||
}
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2020 Martin Storsjo
|
||||
#
|
||||
# Permission to use, copy, modify, and/or distribute this software for any
|
||||
# purpose with or without fee is hereby granted, provided that the above
|
||||
# copyright notice and this permission notice appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
ARGS=""
|
||||
while [ $# -gt 0 ]; do
|
||||
a="$1"
|
||||
case $a in
|
||||
/safeseh|/coff|/c|/Fo)
|
||||
a="-${a#/}"
|
||||
;;
|
||||
esac
|
||||
ARGS="$ARGS $a"
|
||||
shift
|
||||
done
|
||||
|
||||
uasm $ARGS
|
||||
Reference in new issue
Block a user