Updates vendored mason to v0.4 for LLVM 3.9.1

This commit is contained in:
Daniel J. Hofmann
2017-01-09 14:26:44 +05:30
105 changed files with 1873 additions and 1000 deletions
+68 -42
View File
@@ -9,8 +9,8 @@ export MAJOR_MINOR=$(echo ${MASON_VERSION} | cut -d '.' -f1-2)
if [[ $(uname -s) == 'Darwin' ]]; then
export BUILD_AND_LINK_LIBCXX=false
# TODO: could also use LIBCXX_INSTALL_SUPPORT_HEADERS, LIBCXX_INSTALL_LIBRARY, LIBCXX_INSTALL_HEADERS
# avoids this kind of problem with include-what-you-use:
# avoids this kind of problem with include-what-you-use
# because iwyu hardcodes at https://github.com/include-what-you-use/include-what-you-use/blob/da5c9b17fec571e6b2bbca29145463d7eaa3582e/iwyu_driver.cc#L219
: '
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:167:44: error: declaration conflicts with target of using declaration already in scope
inline _LIBCPP_INLINE_VISIBILITY long abs( long __x) _NOEXCEPT {return labs(__x);}
@@ -123,6 +123,11 @@ function mason_compile {
# knock out lldb doc building, to remove doxygen dependency
perl -i -p -e "s/add_subdirectory\(docs\)//g;" tools/lldb/CMakeLists.txt
# remove /usr/local/include from default paths (targeting linux)
# because we want users to have to explictly link things in /usr/local to avoid conflicts
# between mason and homebrew or source installs
perl -i -p -e "s/AddPath\(\"\/usr\/local\/include\"\, System\, false\)\;//g;" tools/clang/lib/Frontend/InitHeaderSearch.cpp
if [[ ${MAJOR_MINOR} == "3.8" ]]; then
# workaround https://llvm.org/bugs/show_bug.cgi?id=25565
perl -i -p -e "s/set\(codegen_deps intrinsics_gen\)/set\(codegen_deps intrinsics_gen attributes_inc\)/g;" lib/CodeGen/CMakeLists.txt
@@ -139,18 +144,35 @@ function mason_compile {
cd ./build
CMAKE_EXTRA_ARGS=""
if [[ $(uname -s) == 'Darwin' ]]; then
# This is a stable location for libc++ headers from the system
SYSTEM_LIBCXX_HEADERS="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/"
# This is the location of C headers on 10.11
OSX_10_11_SDK_C_HEADERS="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/"
# This is the location of C headers on >= 10.12 which is a symlink to the versioned SDK
OSX_10_12_AND_GREATER_SDK_HEADERS="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/"
# This allows this version of clang to find the headers from only a command line tools install (no xcode installed)
# It is debatable whether this should be supported
COMMAND_LINE_TOOLS_C_HEADERS="/usr/include"
CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -DC_INCLUDE_DIRS=:${SYSTEM_LIBCXX_HEADERS}:${OSX_10_12_AND_GREATER_SDK_HEADERS}:${OSX_10_11_SDK_C_HEADERS}:${COMMAND_LINE_TOOLS_C_HEADERS}"
: '
Note: C_INCLUDE_DIRS and DEFAULT_SYSROOT are critical options to understand to ensure C and C++ headers are predictably found.
The way things work in clang++ on OS X (inside http://clang.llvm.org/doxygen/InitHeaderSearch_8cpp.html) is:
- The `:` separated `C_INCLUDE_DIRS` are added to the include paths
- If `C_INCLUDE_DIRS` is present `InitHeaderSearch::AddDefaultCIncludePaths` returns early
- Without that early return `/usr/include` would be added by default on OS X
- If `-isysroot` is passed then absolute `C_INCLUDE_DIRS` are appended to the sysroot
- So if sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/ and
C_INCLUDE_DIRS=/usr/include the actual path searched would be:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
- Relative `C_INCLUDE_DIRS` seem pointless because they are not appended to the sysroot and so will not be portable
- clang++ finds C++ headers relative to itself at https://github.com/llvm-mirror/clang/blob/master/lib/Frontend/InitHeaderSearch.cpp#L469-L470
- So, given on OS X we want to use the XCode/Apple provided libc++ and c++ headers we symlink the relative location to /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++
- The alternative would be to symlink to the command line tools location (/Library/Developer/CommandLineTools/usr/include/c++/v1/)
Another viable sysroot would be the command line tools at /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
Generally each SDK/Platform version has its own C headers inside SDK_PATH/usr/include while all platforms share the C++ headers which
are at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/
NOTE: show search paths with: `clang -x c -v -E /dev/null` || `cpp -v` && `clang -Xlinker -v`
'
CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -DC_INCLUDE_DIRS=/usr/include"
# setting the default sysroot to an explicit SDK avoids clang++ adding `/usr/local/include` to the paths by default at https://github.com/llvm-mirror/clang/blob/91d69c3c9c62946245a0fe6526d5ec226dfe7408/lib/Frontend/InitHeaderSearch.cpp#L226
# because that value will be appended to the sysroot, not exist, and then get thrown out. If the sysroot were / then it would be added
CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -DDEFAULT_SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -DCLANG_DEFAULT_CXX_STDLIB=libc++"
CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -DDEFAULT_SYSROOT=/"
CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -DCMAKE_OSX_DEPLOYMENT_TARGET=10.11"
CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -DLLVM_CREATE_XCODE_TOOLCHAIN=ON -DLLVM_EXTERNALIZE_DEBUGINFO=ON"
fi
@@ -182,16 +204,25 @@ function mason_compile {
fi
fi
# on linux the default is to link programs compiled by clang++ to libstdc++ and below we make that explicit.
if [[ $(uname -s) == 'Linux' ]]; then
export CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -DCLANG_DEFAULT_CXX_STDLIB=libstdc++"
fi
# TODO: test this
#-DLLVM_ENABLE_LTO=ON \
# TODO: try rtlib=compiler-rt on linux
# https://blogs.gentoo.org/gsoc2016-native-clang/2016/05/31/build-gnu-free-executables-with-clang/
if [[ ${BUILD_AND_LINK_LIBCXX} == true ]]; then
CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -DLIBCXX_ENABLE_ASSERTIONS=OFF -DLIBCXX_ENABLE_SHARED=OFF -DLIBCXXABI_ENABLE_SHARED=OFF -DLIBCXXABI_USE_LLVM_UNWINDER=ON -DLIBUNWIND_ENABLE_SHARED=OFF"
fi
${MASON_CMAKE}/bin/cmake ../ -G Ninja -DCMAKE_INSTALL_PREFIX=${MASON_PREFIX} \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_TARGETS_TO_BUILD="ARM;X86;AArch64" \
-DLLVM_INCLUDE_DOCS=OFF \
-DLLVM_TARGETS_TO_BUILD="X86" \
-DCMAKE_CXX_COMPILER_LAUNCHER="${MASON_CCACHE}/bin/ccache" \
-DCMAKE_CXX_COMPILER="$CXX" \
-DCMAKE_C_COMPILER="$CC" \
@@ -205,50 +236,45 @@ function mason_compile {
-DCMAKE_MAKE_PROGRAM=${MASON_NINJA}/bin/ninja \
${CMAKE_EXTRA_ARGS}
if [[ ${BUILD_AND_LINK_LIBCXX} == true ]]; then
${MASON_NINJA}/bin/ninja unwind -j${MASON_CONCURRENCY}
# make libc++ and libc++abi first
${MASON_NINJA}/bin/ninja cxx -j${MASON_CONCURRENCY}
${MASON_NINJA}/bin/ninja lldb -j${MASON_CONCURRENCY}
fi
# then make everything else
${MASON_NINJA}/bin/ninja -j${MASON_CONCURRENCY}
# install it all
${MASON_NINJA}/bin/ninja install
if [[ $(uname -s) == 'Darwin' ]]; then
# https://reviews.llvm.org/D13605
${MASON_NINJA}/bin/ninja install-xcode-toolchain -j${MASON_CONCURRENCY}
fi
if [[ ${BUILD_AND_LINK_LIBCXX} == true ]]; then
${MASON_NINJA}/bin/ninja unwind -j${MASON_CONCURRENCY}
# make libc++ and libc++abi first
# this ensures that the LD_LIBRARY_PATH above will be valid
# and that clang++ on linux will be able to link itself to
# this same instance of libc++
${MASON_NINJA}/bin/ninja cxx -j${MASON_CONCURRENCY}
${MASON_NINJA}/bin/ninja lldb -j${MASON_CONCURRENCY}
# no move the host compilers libc++ and libc++abi shared libs out of the way
if [[ ${CXX_BOOTSTRAP:-false} != false ]]; then
mkdir -p /tmp/backup_shlibs
mv $(dirname $(dirname $CXX))/lib/*c++*so /tmp/backup_shlibs/
fi
fi
# then make everything else
${MASON_NINJA}/bin/ninja -j${MASON_CONCURRENCY}
# install it all
${MASON_NINJA}/bin/ninja install
# install the asan_symbolizer.py tool
cp -a ../projects/compiler-rt/lib/asan/scripts/asan_symbolize.py ${MASON_PREFIX}/bin/
# set up symlinks for to match what llvm.org binaries provide
# set up symlinks to match what llvm.org binaries provide
cd ${MASON_PREFIX}/bin/
ln -s "clang++" "clang++-${MAJOR_MINOR}"
ln -s "asan_symbolize.py" "asan_symbolize"
# restore host compilers sharedlibs
if [[ ${BUILD_AND_LINK_LIBCXX} == true ]]; then
if [[ ${CXX_BOOTSTRAP:-false} != false ]]; then
cp -r /tmp/backup_shlibs/* $(dirname $(dirname $CXX))/lib/
fi
# symlink so that we use the system libc++ headers on osx
if [[ $(uname -s) == 'Darwin' ]]; then
mkdir -p ${MASON_PREFIX}/include
cd ${MASON_PREFIX}/include
# note: passing -nostdinc++ will result in this local path being ignored
ln -s /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++ c++
fi
}
function mason_cflags {
:
}