Bug 1682660 - Wrap clang to pass all the necessary flags when building compiler-rt. r=dmajor

When building compiler-rt for macOS, its build system assumes the
compiler used is a native macOS clang, drops all the cmake C/C++ flags,
and adds its own.

Because we do need to pass `-target $target` (otherwise we end up with
ELF x86_64 objects) and `-mcpu=apple-a12` for the correct baseline for
arm64 macOS, and because there is unfortunately no cmake variable that
the compiler-rt build system will use, and because CMAKE_C*_COMPILER
need to be a program without arguments, we need to wrap the compiler.

While here, add `-v` to the ninja call to have more useful logs.

Differential Revision: https://phabricator.services.mozilla.com/D99841
This commit is contained in:
Mike Hommey 2020-12-18 01:50:07 +00:00
parent a3d4bafed6
commit a734bb41a9

View File

@ -9,19 +9,26 @@ export PATH="$MOZ_FETCHES_DIR/cctools/bin:$PATH"
mkdir compiler-rt
cd compiler-rt
compiler_wrapper() {
cat > $1 <<EOF
exec \$MOZ_FETCHES_DIR/clang/bin/$1 -target aarch64-apple-darwin -mcpu=apple-a12 -isysroot \$MOZ_FETCHES_DIR/MacOSX11.0.sdk "\$@"
EOF
chmod +x $1
}
compiler_wrapper clang
compiler_wrapper clang++
cmake \
$MOZ_FETCHES_DIR/llvm-project/compiler-rt \
-GNinja \
-DCMAKE_C_COMPILER=$MOZ_FETCHES_DIR/clang/bin/clang \
-DCMAKE_CXX_COMPILER=$MOZ_FETCHES_DIR/clang/bin/clang++ \
-DCMAKE_C_COMPILER=$PWD/clang \
-DCMAKE_CXX_COMPILER=$PWD/clang++ \
-DCMAKE_LINKER=$MOZ_FETCHES_DIR/cctools/bin/aarch64-apple-darwin-ld \
-DCMAKE_LIPO=$MOZ_FETCHES_DIR/cctools/bin/lipo \
-DCMAKE_AR=$MOZ_FETCHES_DIR/cctools/bin/aarch64-apple-darwin-ar \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=OFF \
-DLLVM_CONFIG_PATH=$MOZ_FETCHES_DIR/clang/bin/llvm-config \
-DCMAKE_C_FLAGS="-target aarch64-apple-darwin -mcpu=apple-a12 -isysroot $MOZ_FETCHES_DIR/MacOSX11.0.sdk" \
-DCMAKE_CXX_FLAGS="-target aarch64-apple-darwin -mcpu=apple-a12 -isysroot $MOZ_FETCHES_DIR/MacOSX11.0.sdk" \
-DCMAKE_SYSTEM_NAME=Darwin \
-DCMAKE_SYSTEM_VERSION=11.0 \
-DDARWIN_osx_ARCHS=arm64 \
@ -35,7 +42,7 @@ cmake \
echo "#!/bin/sh" > codesign
chmod +x codesign
PATH=$PATH:$PWD ninja
PATH=$PATH:$PWD ninja -v
cd ..