1#!/usr/bin/env bash 2 3set -ue 4 5function usage() { 6 cat <<EOM 7$(basename ${0}) [-h|--help] --libcxx-root <LIBCXX-ROOT> --libcxxabi-root <LIBCXXABI-ROOT> --std <STD> --arch <ARCHITECTURE> --deployment-target <TARGET> --sdk-version <SDK-VERSION> [--lit-args <ARGS...>] 8 9This script is used to continually test the back-deployment use case of libc++ and libc++abi on MacOS. 10 11 --libcxx-root Full path to the root of the libc++ repository to test. 12 --libcxxabi-root Full path to the root of the libc++abi repository to test. 13 --std Version of the C++ Standard to run the tests under (c++03, c++11, etc..). 14 --arch Architecture to build the tests for (32, 64). 15 --deployment-target The deployment target to run the tests for. This should be a version number of MacOS (e.g. 10.12). All MacOS versions until and including 10.7 are supported. 16 --sdk-version The version of the SDK to test with. This should be a version number of MacOS (e.g. 10.12). We'll link against the libc++ dylib in that SDK, but we'll run against the one on the given deployment target. 17 [--lit-args] Additional arguments to pass to lit (optional). If there are multiple arguments, quote them to pass them as a single argument to this script. 18 [--no-cleanup] Do not cleanup the temporary directory that was used for testing at the end. This can be useful to debug failures. Make sure to clean up manually after. 19 [-h, --help] Print this help. 20EOM 21} 22 23while [[ $# -gt 0 ]]; do 24 case "$1" in 25 --libcxx-root) 26 LIBCXX_ROOT="${2}" 27 if [[ ! -d "${LIBCXX_ROOT}" ]]; then 28 echo "--libcxx-root '${LIBCXX_ROOT}' is not a valid directory" 29 usage 30 exit 1 31 fi 32 shift; shift 33 ;; 34 --libcxxabi-root) 35 LIBCXXABI_ROOT="${2}" 36 if [[ ! -d "${LIBCXXABI_ROOT}" ]]; then 37 echo "--libcxxabi-root '${LIBCXXABI_ROOT}' is not a valid directory" 38 usage 39 exit 1 40 fi 41 shift; shift 42 ;; 43 --std) 44 STD="${2}" 45 shift; shift 46 ;; 47 --arch) 48 ARCH="${2}" 49 shift; shift 50 ;; 51 --deployment-target) 52 DEPLOYMENT_TARGET="${2}" 53 shift; shift 54 ;; 55 --sdk-version) 56 MACOS_SDK_VERSION="${2}" 57 shift; shift 58 ;; 59 --lit-args) 60 ADDITIONAL_LIT_ARGS="${2}" 61 shift; shift 62 ;; 63 --no-cleanup) 64 NO_CLEANUP="" 65 shift 66 ;; 67 -h|--help) 68 usage 69 exit 0 70 ;; 71 *) 72 echo "${1} is not a supported argument" 73 usage 74 exit 1 75 ;; 76 esac 77done 78 79if [[ -z ${LIBCXX_ROOT+x} ]]; then echo "--libcxx-root is a required parameter"; usage; exit 1; fi 80if [[ -z ${LIBCXXABI_ROOT+x} ]]; then echo "--libcxxabi-root is a required parameter"; usage; exit 1; fi 81if [[ -z ${STD+x} ]]; then echo "--std is a required parameter"; usage; exit 1; fi 82if [[ -z ${ARCH+x} ]]; then echo "--arch is a required parameter"; usage; exit 1; fi 83if [[ -z ${DEPLOYMENT_TARGET+x} ]]; then echo "--deployment-target is a required parameter"; usage; exit 1; fi 84if [[ -z ${MACOS_SDK_VERSION+x} ]]; then echo "--sdk-version is a required parameter"; usage; exit 1; fi 85if [[ -z ${ADDITIONAL_LIT_ARGS+x} ]]; then ADDITIONAL_LIT_ARGS=""; fi 86 87 88TEMP_DIR="$(mktemp -d)" 89echo "Created temporary directory ${TEMP_DIR}" 90function cleanup { 91 if [[ -z ${NO_CLEANUP+x} ]]; then 92 echo "Removing temporary directory ${TEMP_DIR}" 93 rm -rf "${TEMP_DIR}" 94 else 95 echo "Temporary directory is at '${TEMP_DIR}', make sure to clean it up yourself" 96 fi 97} 98trap cleanup EXIT 99 100 101LLVM_ROOT="${TEMP_DIR}/llvm" 102LIBCXX_BUILD_DIR="${TEMP_DIR}/libcxx-build" 103LIBCXX_INSTALL_DIR="${TEMP_DIR}/libcxx-install" 104LIBCXXABI_BUILD_DIR="${TEMP_DIR}/libcxxabi-build" 105LIBCXXABI_INSTALL_DIR="${TEMP_DIR}/libcxxabi-install" 106 107PREVIOUS_DYLIBS_URL="http://lab.llvm.org:8080/roots/libcxx-roots.tar.gz" 108LLVM_TARBALL_URL="https://github.com/llvm-mirror/llvm/archive/master.tar.gz" 109export CC="$(xcrun --find clang)" 110export CXX="$(xcrun --find clang++)" 111 112 113echo "@@@ Downloading LLVM tarball of master (only used for CMake configuration) @@@" 114mkdir "${LLVM_ROOT}" 115curl -L "${LLVM_TARBALL_URL}" | tar -xz --strip-components=1 -C "${LLVM_ROOT}" 116echo "@@@@@@" 117 118 119echo "@@@ Configuring architecture-related stuff @@@" 120if [[ "${ARCH}" == "64" ]]; then CMAKE_ARCH_STRING="x86_64"; else CMAKE_ARCH_STRING="i386"; fi 121if [[ "${ARCH}" == "64" ]]; then LIT_ARCH_STRING=""; else LIT_ARCH_STRING="--param=enable_32bit=true"; fi 122echo "@@@@@@" 123 124 125echo "@@@ Configuring CMake for libc++ @@@" 126mkdir -p "${LIBCXX_BUILD_DIR}" 127(cd "${LIBCXX_BUILD_DIR}" && 128 xcrun cmake "${LIBCXX_ROOT}" -GNinja \ 129 -DLLVM_PATH="${LLVM_ROOT}" \ 130 -DCMAKE_INSTALL_PREFIX="${LIBCXX_INSTALL_DIR}" \ 131 -DCMAKE_OSX_ARCHITECTURES="${CMAKE_ARCH_STRING}" 132) 133echo "@@@@@@" 134 135 136echo "@@@ Configuring CMake for libc++abi @@@" 137mkdir -p "${LIBCXXABI_BUILD_DIR}" 138(cd "${LIBCXXABI_BUILD_DIR}" && 139 xcrun cmake "${LIBCXXABI_ROOT}" -GNinja \ 140 -DLIBCXXABI_LIBCXX_PATH="${LIBCXX_ROOT}" \ 141 -DLLVM_PATH="${LLVM_ROOT}" \ 142 -DCMAKE_INSTALL_PREFIX="${LIBCXXABI_INSTALL_DIR}" \ 143 -DCMAKE_OSX_ARCHITECTURES="${CMAKE_ARCH_STRING}" 144) 145echo "@@@@@@" 146 147 148echo "@@@ Installing the latest libc++ headers @@@" 149ninja -C "${LIBCXX_BUILD_DIR}" install-cxx-headers 150echo "@@@@@@" 151 152 153echo "@@@ Downloading dylibs for older deployment targets @@@" 154# TODO: The tarball should contain libc++abi.dylib too, we shouldn't be relying on the system's 155# TODO: We should also link against the libc++abi.dylib that was shipped in the SDK 156PREVIOUS_DYLIBS_DIR="${TEMP_DIR}/libcxx-dylibs" 157mkdir "${PREVIOUS_DYLIBS_DIR}" 158curl "${PREVIOUS_DYLIBS_URL}" | tar -xz --strip-components=1 -C "${PREVIOUS_DYLIBS_DIR}" 159LIBCXX_ON_DEPLOYMENT_TARGET="${PREVIOUS_DYLIBS_DIR}/macOS/${DEPLOYMENT_TARGET}/libc++.dylib" 160LIBCXXABI_ON_DEPLOYMENT_TARGET="/usr/lib/libc++abi.dylib" 161LIBCXX_IN_SDK="${PREVIOUS_DYLIBS_DIR}/macOS/${MACOS_SDK_VERSION}/libc++.dylib" 162echo "@@@@@@" 163 164 165# TODO: We need to also run the tests for libc++abi. 166# TODO: Make sure lit will actually run against the libc++abi we specified 167echo "@@@ Running tests for libc++ @@@" 168"${LIBCXX_BUILD_DIR}/bin/llvm-lit" -sv "${LIBCXX_ROOT}/test" \ 169 --param=enable_experimental=false \ 170 --param=enable_filesystem=false \ 171 ${LIT_ARCH_STRING} \ 172 --param=cxx_under_test="${CXX}" \ 173 --param=cxx_headers="${LIBCXX_INSTALL_DIR}/include/c++/v1" \ 174 --param=std="${STD}" \ 175 --param=platform="macosx${DEPLOYMENT_TARGET}" \ 176 --param=cxx_runtime_root="$(dirname "${LIBCXX_ON_DEPLOYMENT_TARGET}")" \ 177 --param=abi_library_path="$(dirname "${LIBCXXABI_ON_DEPLOYMENT_TARGET}")" \ 178 --param=use_system_cxx_lib="$(dirname "${LIBCXX_IN_SDK}")" \ 179 ${ADDITIONAL_LIT_ARGS} 180echo "@@@@@@" 181