#!/bin/bash set -x -e -v # This script is for building a mingw-clang toolchain for use on Linux. if [[ $# -eq 0 ]]; then echo "Provide either x86 or x64 to specify a toolchain." exit 1; elif [ "$1" == "x86" ]; then machine="i686" compiler_rt_machine="i386" crt_flags="--enable-lib32 --disable-lib64" elif [ "$1" == "x64" ]; then machine="x86_64" compiler_rt_machine="x86_64" crt_flags="--disable-lib32 --enable-lib64" else echo "Provide either x86 or x64 to specify a toolchain." exit 1; fi WORKSPACE=$HOME/workspace HOME_DIR=$WORKSPACE/build UPLOAD_DIR=$HOME/artifacts TOOLCHAIN_DIR=$WORKSPACE/moz-toolchain INSTALL_DIR=$TOOLCHAIN_DIR/build/stage3/clang CROSS_PREFIX_DIR=$INSTALL_DIR/$machine-w64-mingw32 SRC_DIR=$TOOLCHAIN_DIR/src CLANG_VERSION=7.0.0 make_flags="-j$(nproc)" mingw_version=cfd85ebed773810429bf2164c3a985895b7dbfe3 libunwind_version=86ab23972978242b6f9e27cebc239f3e8428b1af binutils_version=2.27 binutils_ext=bz2 binutils_sha=369737ce51587f92466041a97ab7d2358c6d9e1b6490b3940eb09fb0a9a6ac88 # This is default value of _WIN32_WINNT. Gecko configure script explicitly sets this, # so this is not used to build Gecko itself. We default to 0x600, which is Windows Vista. default_win32_winnt=0x600 cd $HOME_DIR/src . taskcluster/scripts/misc/tooltool-download.sh prepare() { mkdir -p $TOOLCHAIN_DIR touch $TOOLCHAIN_DIR/.build-clang mkdir -p $SRC_DIR pushd $SRC_DIR git clone -n git://git.code.sf.net/p/mingw-w64/mingw-w64 pushd mingw-w64 git checkout $mingw_version popd git clone https://github.com/llvm-mirror/libunwind.git pushd libunwind git checkout $libunwind_version popd wget -c --progress=dot:mega ftp://ftp.gnu.org/gnu/binutils/binutils-$binutils_version.tar.$binutils_ext if [ "$(sha256sum binutils-$binutils_version.tar.$binutils_ext)" != "$binutils_sha binutils-$binutils_version.tar.$binutils_ext" ]; then echo Corrupted binutils archive exit 1 fi tar -jxf binutils-$binutils_version.tar.$binutils_ext popd } install_wrappers() { pushd $INSTALL_DIR/bin cat <$machine-w64-mingw32-clang #!/bin/sh DIR="\$(cd "\$(dirname "\$0")" && pwd)" \$DIR/clang -target $machine-w64-mingw32 --sysroot \$DIR/../$machine-w64-mingw32 -rtlib=compiler-rt -stdlib=libc++ -fuse-ld=lld -fdwarf-exceptions -Qunused-arguments "\$@" EOF chmod +x $machine-w64-mingw32-clang cat <$machine-w64-mingw32-clang++ #!/bin/sh DIR="\$(cd "\$(dirname "\$0")" && pwd)" \$DIR/clang -target $machine-w64-mingw32 --sysroot \$DIR/../$machine-w64-mingw32 --driver-mode=g++ -rtlib=compiler-rt -stdlib=libc++ -fuse-ld=lld -fdwarf-exceptions -Qunused-arguments "\$@" EOF chmod +x $machine-w64-mingw32-clang++ CC="$machine-w64-mingw32-clang" CXX="$machine-w64-mingw32-clang++" popd } build_mingw() { mkdir mingw-w64-headers pushd mingw-w64-headers $SRC_DIR/mingw-w64/mingw-w64-headers/configure --host=$machine-w64-mingw32 \ --enable-sdk=all \ --enable-secure-api \ --enable-idl \ --with-default-msvcrt=ucrt \ --with-default-win32-winnt=$default_win32_winnt \ --prefix=$CROSS_PREFIX_DIR make $make_flags install popd mkdir mingw-w64-crt pushd mingw-w64-crt $SRC_DIR/mingw-w64/mingw-w64-crt/configure --host=$machine-w64-mingw32 \ $crt_flags \ --with-default-msvcrt=ucrt \ CC="$CC" \ AR=llvm-ar \ RANLIB=llvm-ranlib \ DLLTOOL=llvm-dlltool \ --prefix=$CROSS_PREFIX_DIR make $make_flags make $make_flags install popd mkdir widl pushd widl $SRC_DIR/mingw-w64/mingw-w64-tools/widl/configure --target=$machine-w64-mingw32 --prefix=$INSTALL_DIR make $make_flags make $make_flags install popd } build_compiler_rt() { mkdir compiler-rt pushd compiler-rt cmake \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_C_COMPILER=$CC \ -DCMAKE_SYSTEM_NAME=Windows \ -DCMAKE_AR=$INSTALL_DIR/bin/llvm-ar \ -DCMAKE_RANLIB=$INSTALL_DIR/bin/llvm-ranlib \ -DCMAKE_C_COMPILER_WORKS=1 \ -DCMAKE_C_COMPILER_TARGET=$compiler_rt_machine-windows-gnu \ -DCOMPILER_RT_DEFAULT_TARGET_ONLY=TRUE \ $SRC_DIR/compiler-rt/lib/builtins make $make_flags mkdir -p $INSTALL_DIR/lib/clang/$CLANG_VERSION/lib/windows cp lib/windows/libclang_rt.builtins-$compiler_rt_machine.a $INSTALL_DIR/lib/clang/$CLANG_VERSION/lib/windows/ popd } merge_libs() { cat <