OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env bash |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 # This script will check out llvm and clang into third_party/llvm and build it. |
| 7 |
| 8 # Do NOT CHANGE this if you don't know what you're doing -- see |
| 9 # https://code.google.com/p/chromium/wiki/UpdatingClang |
| 10 # Reverting problematic clang rolls is safe, though. |
| 11 CLANG_REVISION=246985 |
| 12 |
| 13 # This is incremented when pushing a new build of Clang at the same revision. |
| 14 CLANG_SUB_REVISION=1 |
| 15 |
| 16 PACKAGE_VERSION="${CLANG_REVISION}-${CLANG_SUB_REVISION}" |
| 17 |
| 18 THIS_DIR="$(dirname "${0}")" |
| 19 LLVM_DIR="${THIS_DIR}/../../../third_party/llvm" |
| 20 LLVM_BUILD_DIR="${LLVM_DIR}/../llvm-build/Release+Asserts" |
| 21 COMPILER_RT_BUILD_DIR="${LLVM_DIR}/../llvm-build/compiler-rt" |
| 22 LLVM_BOOTSTRAP_DIR="${LLVM_DIR}/../llvm-bootstrap" |
| 23 LLVM_BOOTSTRAP_INSTALL_DIR="${LLVM_DIR}/../llvm-bootstrap-install" |
| 24 CLANG_DIR="${LLVM_DIR}/tools/clang" |
| 25 COMPILER_RT_DIR="${LLVM_DIR}/compiler-rt" |
| 26 LIBCXX_DIR="${LLVM_DIR}/projects/libcxx" |
| 27 LIBCXXABI_DIR="${LLVM_DIR}/projects/libcxxabi" |
| 28 ANDROID_NDK_DIR="${THIS_DIR}/../../../third_party/android_tools/ndk" |
| 29 STAMP_FILE="${LLVM_DIR}/../llvm-build/cr_build_revision" |
| 30 CHROMIUM_TOOLS_DIR="${THIS_DIR}/.." |
| 31 BINUTILS_DIR="${THIS_DIR}/../../../third_party/binutils" |
| 32 |
| 33 ABS_CHROMIUM_TOOLS_DIR="${PWD}/${CHROMIUM_TOOLS_DIR}" |
| 34 ABS_LIBCXX_DIR="${PWD}/${LIBCXX_DIR}" |
| 35 ABS_LIBCXXABI_DIR="${PWD}/${LIBCXXABI_DIR}" |
| 36 ABS_LLVM_DIR="${PWD}/${LLVM_DIR}" |
| 37 ABS_LLVM_BUILD_DIR="${PWD}/${LLVM_BUILD_DIR}" |
| 38 ABS_COMPILER_RT_DIR="${PWD}/${COMPILER_RT_DIR}" |
| 39 ABS_BINUTILS_DIR="${PWD}/${BINUTILS_DIR}" |
| 40 |
| 41 # ${A:-a} returns $A if it's set, a else. |
| 42 LLVM_REPO_URL=${LLVM_URL:-https://llvm.org/svn/llvm-project} |
| 43 |
| 44 CDS_URL=https://commondatastorage.googleapis.com/chromium-browser-clang |
| 45 |
| 46 if [[ -z "$GYP_DEFINES" ]]; then |
| 47 GYP_DEFINES= |
| 48 fi |
| 49 if [[ -z "$GYP_GENERATORS" ]]; then |
| 50 GYP_GENERATORS= |
| 51 fi |
| 52 if [[ -z "$LLVM_DOWNLOAD_GOLD_PLUGIN" ]]; then |
| 53 LLVM_DOWNLOAD_GOLD_PLUGIN= |
| 54 fi |
| 55 |
| 56 |
| 57 # Die if any command dies, error on undefined variable expansions. |
| 58 set -eu |
| 59 |
| 60 |
| 61 if [[ -n ${LLVM_FORCE_HEAD_REVISION:-''} ]]; then |
| 62 # Use a real revision number rather than HEAD to make sure that the stamp file |
| 63 # logic works. |
| 64 CLANG_REVISION=$(svn info "$LLVM_REPO_URL" \ |
| 65 | grep 'Revision:' | awk '{ printf $2; }') |
| 66 PACKAGE_VERSION="${CLANG_REVISION}-0" |
| 67 fi |
| 68 |
| 69 OS="$(uname -s)" |
| 70 |
| 71 # Parse command line options. |
| 72 if_needed= |
| 73 force_local_build= |
| 74 run_tests= |
| 75 bootstrap= |
| 76 with_android=yes |
| 77 chrome_tools="plugins;blink_gc_plugin" |
| 78 gcc_toolchain= |
| 79 with_patches=yes |
| 80 |
| 81 if [[ "${OS}" = "Darwin" ]]; then |
| 82 with_android= |
| 83 fi |
| 84 |
| 85 while [[ $# > 0 ]]; do |
| 86 case $1 in |
| 87 --bootstrap) |
| 88 bootstrap=yes |
| 89 ;; |
| 90 --if-needed) |
| 91 if_needed=yes |
| 92 ;; |
| 93 --force-local-build) |
| 94 force_local_build=yes |
| 95 ;; |
| 96 --print-revision) |
| 97 if [[ -n ${LLVM_FORCE_HEAD_REVISION:-''} ]]; then |
| 98 svn info "$LLVM_DIR" | grep 'Revision:' | awk '{ printf $2; }' |
| 99 else |
| 100 echo $PACKAGE_VERSION |
| 101 fi |
| 102 exit 0 |
| 103 ;; |
| 104 --run-tests) |
| 105 run_tests=yes |
| 106 ;; |
| 107 --without-android) |
| 108 with_android= |
| 109 ;; |
| 110 --without-patches) |
| 111 with_patches= |
| 112 ;; |
| 113 --with-chrome-tools) |
| 114 shift |
| 115 if [[ $# == 0 ]]; then |
| 116 echo "--with-chrome-tools requires an argument." |
| 117 exit 1 |
| 118 fi |
| 119 chrome_tools=$1 |
| 120 ;; |
| 121 --gcc-toolchain) |
| 122 shift |
| 123 if [[ $# == 0 ]]; then |
| 124 echo "--gcc-toolchain requires an argument." |
| 125 exit 1 |
| 126 fi |
| 127 if [[ -x "$1/bin/gcc" ]]; then |
| 128 gcc_toolchain=$1 |
| 129 else |
| 130 echo "Invalid --gcc-toolchain: '$1'." |
| 131 echo "'$1/bin/gcc' does not appear to be valid." |
| 132 exit 1 |
| 133 fi |
| 134 ;; |
| 135 |
| 136 --help) |
| 137 echo "usage: $0 [--force-local-build] [--if-needed] [--run-tests] " |
| 138 echo "--bootstrap: First build clang with CC, then with itself." |
| 139 echo "--force-local-build: Don't try to download prebuilt binaries." |
| 140 echo "--if-needed: Download clang only if the script thinks it is needed." |
| 141 echo "--run-tests: Run tests after building. Only for local builds." |
| 142 echo "--print-revision: Print current clang revision and exit." |
| 143 echo "--without-android: Don't build ASan Android runtime library." |
| 144 echo "--with-chrome-tools: Select which chrome tools to build." \ |
| 145 "Defaults to plugins;blink_gc_plugin." |
| 146 echo " Example: --with-chrome-tools plugins;empty-string" |
| 147 echo "--gcc-toolchain: Set the prefix for which GCC version should" |
| 148 echo " be used for building. For example, to use gcc in" |
| 149 echo " /opt/foo/bin/gcc, use '--gcc-toolchain '/opt/foo" |
| 150 echo "--without-patches: Don't apply local patches." |
| 151 echo |
| 152 exit 1 |
| 153 ;; |
| 154 *) |
| 155 echo "Unknown argument: '$1'." |
| 156 echo "Use --help for help." |
| 157 exit 1 |
| 158 ;; |
| 159 esac |
| 160 shift |
| 161 done |
| 162 |
| 163 if [[ -n ${LLVM_FORCE_HEAD_REVISION:-''} ]]; then |
| 164 force_local_build=yes |
| 165 |
| 166 # Skip local patches when using HEAD: they probably don't apply anymore. |
| 167 with_patches= |
| 168 |
| 169 if ! [[ "$GYP_DEFINES" =~ .*OS=android.* ]]; then |
| 170 # Only build the Android ASan rt when targetting Android. |
| 171 with_android= |
| 172 fi |
| 173 |
| 174 LLVM_BUILD_TOOLS_DIR="${ABS_LLVM_DIR}/../llvm-build-tools" |
| 175 |
| 176 if [[ "${OS}" == "Linux" ]] && [[ -z "${gcc_toolchain}" ]]; then |
| 177 if [[ $(gcc -dumpversion) < "4.7.0" ]]; then |
| 178 # We need a newer GCC version. |
| 179 if [[ ! -e "${LLVM_BUILD_TOOLS_DIR}/gcc482" ]]; then |
| 180 echo "Downloading pre-built GCC 4.8.2..." |
| 181 mkdir -p "${LLVM_BUILD_TOOLS_DIR}" |
| 182 curl --fail -L "${CDS_URL}/tools/gcc482.tgz" | \ |
| 183 tar zxf - -C "${LLVM_BUILD_TOOLS_DIR}" |
| 184 echo Done |
| 185 fi |
| 186 gcc_toolchain="${LLVM_BUILD_TOOLS_DIR}/gcc482" |
| 187 else |
| 188 # Always set gcc_toolchain; llvm-symbolizer needs the bundled libstdc++. |
| 189 gcc_toolchain="$(dirname $(dirname $(which gcc)))" |
| 190 fi |
| 191 fi |
| 192 |
| 193 if [[ "${OS}" == "Linux" || "${OS}" == "Darwin" ]]; then |
| 194 if [[ $(cmake --version | grep -Eo '[0-9.]+') < "3.0" ]]; then |
| 195 # We need a newer CMake version. |
| 196 if [[ ! -e "${LLVM_BUILD_TOOLS_DIR}/cmake310" ]]; then |
| 197 echo "Downloading pre-built CMake 3.10..." |
| 198 mkdir -p "${LLVM_BUILD_TOOLS_DIR}" |
| 199 curl --fail -L "${CDS_URL}/tools/cmake310_${OS}.tgz" | \ |
| 200 tar zxf - -C "${LLVM_BUILD_TOOLS_DIR}" |
| 201 echo Done |
| 202 fi |
| 203 export PATH="${LLVM_BUILD_TOOLS_DIR}/cmake310/bin:${PATH}" |
| 204 fi |
| 205 fi |
| 206 |
| 207 echo "LLVM_FORCE_HEAD_REVISION was set; using r${CLANG_REVISION}" |
| 208 fi |
| 209 |
| 210 if [[ -n "$if_needed" ]]; then |
| 211 if [[ "${OS}" == "Darwin" ]]; then |
| 212 # clang is always used on Mac. |
| 213 true |
| 214 elif [[ "${OS}" == "Linux" ]]; then |
| 215 # clang is also aways used on Linux. |
| 216 true |
| 217 elif [[ "$GYP_DEFINES" =~ .*(clang|tsan|asan|lsan|msan)=1.* ]]; then |
| 218 # clang requested via $GYP_DEFINES. |
| 219 true |
| 220 elif [[ -d "${LLVM_BUILD_DIR}" ]]; then |
| 221 # clang previously downloaded, keep it up-to-date. |
| 222 # If you don't want this, delete third_party/llvm-build on your machine. |
| 223 true |
| 224 else |
| 225 # clang wasn't needed, not doing anything. |
| 226 exit 0 |
| 227 fi |
| 228 fi |
| 229 |
| 230 |
| 231 # Check if there's anything to be done, exit early if not. |
| 232 if [[ -f "${STAMP_FILE}" ]]; then |
| 233 PREVIOUSLY_BUILT_REVISON=$(cat "${STAMP_FILE}") |
| 234 if [[ -z "$force_local_build" ]] && \ |
| 235 [[ "${PREVIOUSLY_BUILT_REVISON}" = \ |
| 236 "${PACKAGE_VERSION}" ]]; then |
| 237 echo "Clang already at ${PACKAGE_VERSION}" |
| 238 exit 0 |
| 239 fi |
| 240 fi |
| 241 # To always force a new build if someone interrupts their build half way. |
| 242 rm -f "${STAMP_FILE}" |
| 243 |
| 244 |
| 245 if [[ -z "$force_local_build" ]]; then |
| 246 # Check if there's a prebuilt binary and if so just fetch that. That's faster, |
| 247 # and goma relies on having matching binary hashes on client and server too. |
| 248 CDS_FILE="clang-${PACKAGE_VERSION}.tgz" |
| 249 CDS_OUT_DIR=$(mktemp -d -t clang_download.XXXXXX) |
| 250 CDS_OUTPUT="${CDS_OUT_DIR}/${CDS_FILE}" |
| 251 if [ "${OS}" = "Linux" ]; then |
| 252 CDS_FULL_URL="${CDS_URL}/Linux_x64/${CDS_FILE}" |
| 253 elif [ "${OS}" = "Darwin" ]; then |
| 254 CDS_FULL_URL="${CDS_URL}/Mac/${CDS_FILE}" |
| 255 fi |
| 256 echo Trying to download prebuilt clang |
| 257 if which curl > /dev/null; then |
| 258 curl -L --fail "${CDS_FULL_URL}" -o "${CDS_OUTPUT}" || \ |
| 259 rm -rf "${CDS_OUT_DIR}" |
| 260 elif which wget > /dev/null; then |
| 261 wget "${CDS_FULL_URL}" -O "${CDS_OUTPUT}" || rm -rf "${CDS_OUT_DIR}" |
| 262 else |
| 263 echo "Neither curl nor wget found. Please install one of these." |
| 264 exit 1 |
| 265 fi |
| 266 if [ -f "${CDS_OUTPUT}" ]; then |
| 267 rm -rf "${LLVM_BUILD_DIR}" |
| 268 mkdir -p "${LLVM_BUILD_DIR}" |
| 269 tar -xzf "${CDS_OUTPUT}" -C "${LLVM_BUILD_DIR}" |
| 270 echo clang "${PACKAGE_VERSION}" unpacked |
| 271 echo "${PACKAGE_VERSION}" > "${STAMP_FILE}" |
| 272 rm -rf "${CDS_OUT_DIR}" |
| 273 # Download the gold plugin if requested to by an environment variable. |
| 274 # This is used by the CFI ClusterFuzz bot. |
| 275 if [[ -n "${LLVM_DOWNLOAD_GOLD_PLUGIN}" ]]; then |
| 276 ${THIS_DIR}/../../../build/download_gold_plugin.py |
| 277 fi |
| 278 exit 0 |
| 279 else |
| 280 echo Did not find prebuilt clang "${PACKAGE_VERSION}", building |
| 281 fi |
| 282 fi |
| 283 |
| 284 if [[ -n "${with_android}" ]] && ! [[ -d "${ANDROID_NDK_DIR}" ]]; then |
| 285 echo "Android NDK not found at ${ANDROID_NDK_DIR}" |
| 286 echo "The Android NDK is needed to build a Clang whose -fsanitize=address" |
| 287 echo "works on Android. See " |
| 288 echo "http://code.google.com/p/chromium/wiki/AndroidBuildInstructions for how" |
| 289 echo "to install the NDK, or pass --without-android." |
| 290 exit 1 |
| 291 fi |
| 292 |
| 293 # Check that cmake and ninja are available. |
| 294 if ! which cmake > /dev/null; then |
| 295 echo "CMake needed to build clang; please install" |
| 296 exit 1 |
| 297 fi |
| 298 if ! which ninja > /dev/null; then |
| 299 echo "ninja needed to build clang, please install" |
| 300 exit 1 |
| 301 fi |
| 302 |
| 303 echo Reverting previously patched files |
| 304 for i in \ |
| 305 "${CLANG_DIR}/test/Index/crash-recovery-modules.m" \ |
| 306 "${CLANG_DIR}/unittests/libclang/LibclangTest.cpp" \ |
| 307 "${COMPILER_RT_DIR}/lib/asan/asan_rtl.cc" \ |
| 308 "${COMPILER_RT_DIR}/test/asan/TestCases/Linux/new_array_cookie_test.cc" \ |
| 309 "${LLVM_DIR}/test/DebugInfo/gmlt.ll" \ |
| 310 "${LLVM_DIR}/lib/CodeGen/SpillPlacement.cpp" \ |
| 311 "${LLVM_DIR}/lib/CodeGen/SpillPlacement.h" \ |
| 312 "${LLVM_DIR}/lib/Transforms/Instrumentation/MemorySanitizer.cpp" \ |
| 313 "${CLANG_DIR}/test/Driver/env.c" \ |
| 314 "${CLANG_DIR}/lib/Frontend/InitPreprocessor.cpp" \ |
| 315 "${CLANG_DIR}/test/Frontend/exceptions.c" \ |
| 316 "${CLANG_DIR}/test/Preprocessor/predefined-exceptions.m" \ |
| 317 "${LLVM_DIR}/test/Bindings/Go/go.test" \ |
| 318 "${CLANG_DIR}/lib/Parse/ParseExpr.cpp" \ |
| 319 "${CLANG_DIR}/lib/Parse/ParseTemplate.cpp" \ |
| 320 "${CLANG_DIR}/lib/Sema/SemaDeclCXX.cpp" \ |
| 321 "${CLANG_DIR}/lib/Sema/SemaExprCXX.cpp" \ |
| 322 "${CLANG_DIR}/test/SemaCXX/default2.cpp" \ |
| 323 "${CLANG_DIR}/test/SemaCXX/typo-correction-delayed.cpp" \ |
| 324 "${COMPILER_RT_DIR}/lib/sanitizer_common/sanitizer_stoptheworld_linux_libc
dep.cc" \ |
| 325 "${COMPILER_RT_DIR}/test/tsan/signal_segv_handler.cc" \ |
| 326 "${COMPILER_RT_DIR}/lib/sanitizer_common/sanitizer_coverage_libcdep.cc" \ |
| 327 "${COMPILER_RT_DIR}/cmake/config-ix.cmake" \ |
| 328 "${COMPILER_RT_DIR}/CMakeLists.txt" \ |
| 329 "${COMPILER_RT_DIR}/lib/ubsan/ubsan_platform.h" \ |
| 330 ; do |
| 331 if [[ -e "${i}" ]]; then |
| 332 rm -f "${i}" # For unversioned files. |
| 333 svn revert "${i}" |
| 334 fi; |
| 335 done |
| 336 |
| 337 echo Remove the Clang tools shim dir |
| 338 CHROME_TOOLS_SHIM_DIR=${ABS_LLVM_DIR}/tools/chrometools |
| 339 rm -rfv ${CHROME_TOOLS_SHIM_DIR} |
| 340 |
| 341 echo Getting LLVM r"${CLANG_REVISION}" in "${LLVM_DIR}" |
| 342 if ! svn co --force "${LLVM_REPO_URL}/llvm/trunk@${CLANG_REVISION}" \ |
| 343 "${LLVM_DIR}"; then |
| 344 echo Checkout failed, retrying |
| 345 rm -rf "${LLVM_DIR}" |
| 346 svn co --force "${LLVM_REPO_URL}/llvm/trunk@${CLANG_REVISION}" "${LLVM_DIR}" |
| 347 fi |
| 348 |
| 349 echo Getting clang r"${CLANG_REVISION}" in "${CLANG_DIR}" |
| 350 svn co --force "${LLVM_REPO_URL}/cfe/trunk@${CLANG_REVISION}" "${CLANG_DIR}" |
| 351 |
| 352 # We have moved from building compiler-rt in the LLVM tree, to a separate |
| 353 # directory. Nuke any previous checkout to avoid building it. |
| 354 rm -rf "${LLVM_DIR}/projects/compiler-rt" |
| 355 |
| 356 echo Getting compiler-rt r"${CLANG_REVISION}" in "${COMPILER_RT_DIR}" |
| 357 svn co --force "${LLVM_REPO_URL}/compiler-rt/trunk@${CLANG_REVISION}" \ |
| 358 "${COMPILER_RT_DIR}" |
| 359 |
| 360 # clang needs a libc++ checkout, else -stdlib=libc++ won't find includes |
| 361 # (i.e. this is needed for bootstrap builds). |
| 362 if [ "${OS}" = "Darwin" ]; then |
| 363 echo Getting libc++ r"${CLANG_REVISION}" in "${LIBCXX_DIR}" |
| 364 svn co --force "${LLVM_REPO_URL}/libcxx/trunk@${CLANG_REVISION}" \ |
| 365 "${LIBCXX_DIR}" |
| 366 fi |
| 367 |
| 368 # While we're bundling our own libc++ on OS X, we need to compile libc++abi |
| 369 # into it too (since OS X 10.6 doesn't have libc++abi.dylib either). |
| 370 if [ "${OS}" = "Darwin" ]; then |
| 371 echo Getting libc++abi r"${CLANG_REVISION}" in "${LIBCXXABI_DIR}" |
| 372 svn co --force "${LLVM_REPO_URL}/libcxxabi/trunk@${CLANG_REVISION}" \ |
| 373 "${LIBCXXABI_DIR}" |
| 374 fi |
| 375 |
| 376 if [[ -n "$with_patches" ]]; then |
| 377 # No patches. |
| 378 true |
| 379 fi |
| 380 |
| 381 # Echo all commands. |
| 382 set -x |
| 383 |
| 384 # Set default values for CC and CXX if they're not set in the environment. |
| 385 CC=${CC:-cc} |
| 386 CXX=${CXX:-c++} |
| 387 |
| 388 if [[ -n "${gcc_toolchain}" ]]; then |
| 389 # Use the specified gcc installation for building. |
| 390 CC="$gcc_toolchain/bin/gcc" |
| 391 CXX="$gcc_toolchain/bin/g++" |
| 392 # Set LD_LIBRARY_PATH to make auxiliary targets (tablegen, bootstrap compiler, |
| 393 # etc.) find the .so. |
| 394 export LD_LIBRARY_PATH="$(dirname $(${CXX} -print-file-name=libstdc++.so.6))" |
| 395 fi |
| 396 |
| 397 CFLAGS="" |
| 398 CXXFLAGS="" |
| 399 LDFLAGS="" |
| 400 |
| 401 # LLVM uses C++11 starting in llvm 3.5. On Linux, this means libstdc++4.7+ is |
| 402 # needed, on OS X it requires libc++. clang only automatically links to libc++ |
| 403 # when targeting OS X 10.9+, so add stdlib=libc++ explicitly so clang can run on |
| 404 # OS X versions as old as 10.7. |
| 405 # TODO(thakis): Some bots are still on 10.6 (nacl...), so for now bundle |
| 406 # libc++.dylib. Remove this once all bots are on 10.7+, then use |
| 407 # -DLLVM_ENABLE_LIBCXX=ON and change deployment_target to 10.7. |
| 408 deployment_target="" |
| 409 |
| 410 if [ "${OS}" = "Darwin" ]; then |
| 411 # When building on 10.9, /usr/include usually doesn't exist, and while |
| 412 # Xcode's clang automatically sets a sysroot, self-built clangs don't. |
| 413 CFLAGS="-isysroot $(xcrun --show-sdk-path)" |
| 414 CXXFLAGS="-stdlib=libc++ -nostdinc++ -I${ABS_LIBCXX_DIR}/include ${CFLAGS}" |
| 415 |
| 416 if [[ -n "${bootstrap}" ]]; then |
| 417 deployment_target=10.6 |
| 418 fi |
| 419 fi |
| 420 |
| 421 # Build bootstrap clang if requested. |
| 422 if [[ -n "${bootstrap}" ]]; then |
| 423 ABS_INSTALL_DIR="${PWD}/${LLVM_BOOTSTRAP_INSTALL_DIR}" |
| 424 echo "Building bootstrap compiler" |
| 425 mkdir -p "${LLVM_BOOTSTRAP_DIR}" |
| 426 pushd "${LLVM_BOOTSTRAP_DIR}" |
| 427 |
| 428 cmake -GNinja \ |
| 429 -DCMAKE_BUILD_TYPE=Release \ |
| 430 -DLLVM_ENABLE_ASSERTIONS=ON \ |
| 431 -DLLVM_TARGETS_TO_BUILD=host \ |
| 432 -DLLVM_ENABLE_THREADS=OFF \ |
| 433 -DCMAKE_INSTALL_PREFIX="${ABS_INSTALL_DIR}" \ |
| 434 -DCMAKE_C_COMPILER="${CC}" \ |
| 435 -DCMAKE_CXX_COMPILER="${CXX}" \ |
| 436 -DCMAKE_C_FLAGS="${CFLAGS}" \ |
| 437 -DCMAKE_CXX_FLAGS="${CXXFLAGS}" \ |
| 438 ../llvm |
| 439 |
| 440 ninja |
| 441 |
| 442 ninja install |
| 443 if [[ -n "${gcc_toolchain}" ]]; then |
| 444 # Copy that gcc's stdlibc++.so.6 to the build dir, so the bootstrap |
| 445 # compiler can start. |
| 446 cp -v "$(${CXX} -print-file-name=libstdc++.so.6)" \ |
| 447 "${ABS_INSTALL_DIR}/lib/" |
| 448 fi |
| 449 |
| 450 popd |
| 451 CC="${ABS_INSTALL_DIR}/bin/clang" |
| 452 CXX="${ABS_INSTALL_DIR}/bin/clang++" |
| 453 |
| 454 if [[ -n "${gcc_toolchain}" ]]; then |
| 455 # Tell the bootstrap compiler to use a specific gcc prefix to search |
| 456 # for standard library headers and shared object files. |
| 457 CFLAGS="--gcc-toolchain=${gcc_toolchain}" |
| 458 CXXFLAGS="--gcc-toolchain=${gcc_toolchain}" |
| 459 fi |
| 460 |
| 461 echo "Building final compiler" |
| 462 fi |
| 463 |
| 464 # Build clang (in a separate directory). |
| 465 # The clang bots have this path hardcoded in built/scripts/slave/compile.py, |
| 466 # so if you change it you also need to change these links. |
| 467 mkdir -p "${LLVM_BUILD_DIR}" |
| 468 pushd "${LLVM_BUILD_DIR}" |
| 469 |
| 470 # Build libc++.dylib while some bots are still on OS X 10.6. |
| 471 if [ "${OS}" = "Darwin" ]; then |
| 472 rm -rf libcxxbuild |
| 473 LIBCXXFLAGS="-O3 -std=c++11 -fstrict-aliasing" |
| 474 |
| 475 # libcxx and libcxxabi both have a file stdexcept.cpp, so put their .o files |
| 476 # into different subdirectories. |
| 477 mkdir -p libcxxbuild/libcxx |
| 478 pushd libcxxbuild/libcxx |
| 479 ${CXX:-c++} -c ${CXXFLAGS} ${LIBCXXFLAGS} "${ABS_LIBCXX_DIR}"/src/*.cpp |
| 480 popd |
| 481 |
| 482 mkdir -p libcxxbuild/libcxxabi |
| 483 pushd libcxxbuild/libcxxabi |
| 484 ${CXX:-c++} -c ${CXXFLAGS} ${LIBCXXFLAGS} "${ABS_LIBCXXABI_DIR}"/src/*.cpp -I"
${ABS_LIBCXXABI_DIR}/include" |
| 485 popd |
| 486 |
| 487 pushd libcxxbuild |
| 488 ${CC:-cc} libcxx/*.o libcxxabi/*.o -o libc++.1.dylib -dynamiclib \ |
| 489 -nodefaultlibs -current_version 1 -compatibility_version 1 \ |
| 490 -lSystem -install_name @executable_path/libc++.dylib \ |
| 491 -Wl,-unexported_symbols_list,${ABS_LIBCXX_DIR}/lib/libc++unexp.exp \ |
| 492 -Wl,-force_symbols_not_weak_list,${ABS_LIBCXX_DIR}/lib/notweak.exp \ |
| 493 -Wl,-force_symbols_weak_list,${ABS_LIBCXX_DIR}/lib/weak.exp |
| 494 ln -sf libc++.1.dylib libc++.dylib |
| 495 popd |
| 496 LDFLAGS+="-stdlib=libc++ -L${PWD}/libcxxbuild" |
| 497 |
| 498 if [[ -n "${bootstrap}" ]]; then |
| 499 # Now that the libc++ headers have been installed and libc++.dylib is built, |
| 500 # delete the libc++ checkout again so that it's not part of the main |
| 501 # build below -- the libc++(abi) tests don't pass on OS X in bootstrap |
| 502 # builds (http://llvm.org/PR24068) |
| 503 rm -rf "${ABS_LIBCXX_DIR}" |
| 504 rm -rf "${ABS_LIBCXXABI_DIR}" |
| 505 CXXFLAGS="-stdlib=libc++ -nostdinc++ -I${ABS_INSTALL_DIR}/include/c++/v1 ${C
FLAGS}" |
| 506 fi |
| 507 fi |
| 508 |
| 509 # Find the binutils include dir for the gold plugin. |
| 510 BINUTILS_INCDIR="" |
| 511 if [ "${OS}" = "Linux" ]; then |
| 512 BINUTILS_INCDIR="${ABS_BINUTILS_DIR}/Linux_x64/Release/include" |
| 513 fi |
| 514 |
| 515 |
| 516 # If building at head, define a macro that plugins can use for #ifdefing |
| 517 # out code that builds at head, but not at CLANG_REVISION or vice versa. |
| 518 if [[ -n ${LLVM_FORCE_HEAD_REVISION:-''} ]]; then |
| 519 CFLAGS="${CFLAGS} -DLLVM_FORCE_HEAD_REVISION" |
| 520 CXXFLAGS="${CXXFLAGS} -DLLVM_FORCE_HEAD_REVISION" |
| 521 fi |
| 522 |
| 523 # Hook the Chromium tools into the LLVM build. Several Chromium tools have |
| 524 # dependencies on LLVM/Clang libraries. The LLVM build detects implicit tools |
| 525 # in the tools subdirectory, so install a shim CMakeLists.txt that forwards to |
| 526 # the real directory for the Chromium tools. |
| 527 # Note that the shim directory name intentionally has no _ or _. The implicit |
| 528 # tool detection logic munges them in a weird way. |
| 529 mkdir -v ${CHROME_TOOLS_SHIM_DIR} |
| 530 cat > ${CHROME_TOOLS_SHIM_DIR}/CMakeLists.txt << EOF |
| 531 # Since tools/clang isn't actually a subdirectory, use the two argument version |
| 532 # to specify where build artifacts go. CMake doesn't allow reusing the same |
| 533 # binary dir for multiple source dirs, so the build artifacts have to go into a |
| 534 # subdirectory... |
| 535 add_subdirectory(\${CHROMIUM_TOOLS_SRC} \${CMAKE_CURRENT_BINARY_DIR}/a) |
| 536 EOF |
| 537 rm -fv CMakeCache.txt |
| 538 MACOSX_DEPLOYMENT_TARGET=${deployment_target} cmake -GNinja \ |
| 539 -DCMAKE_BUILD_TYPE=Release \ |
| 540 -DLLVM_ENABLE_ASSERTIONS=ON \ |
| 541 -DLLVM_ENABLE_THREADS=OFF \ |
| 542 -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly \ |
| 543 -DLLVM_BINUTILS_INCDIR="${BINUTILS_INCDIR}" \ |
| 544 -DCMAKE_C_COMPILER="${CC}" \ |
| 545 -DCMAKE_CXX_COMPILER="${CXX}" \ |
| 546 -DCMAKE_C_FLAGS="${CFLAGS}" \ |
| 547 -DCMAKE_CXX_FLAGS="${CXXFLAGS}" \ |
| 548 -DCMAKE_EXE_LINKER_FLAGS="${LDFLAGS}" \ |
| 549 -DCMAKE_SHARED_LINKER_FLAGS="${LDFLAGS}" \ |
| 550 -DCMAKE_MODULE_LINKER_FLAGS="${LDFLAGS}" \ |
| 551 -DCMAKE_INSTALL_PREFIX="${ABS_LLVM_BUILD_DIR}" \ |
| 552 -DCHROMIUM_TOOLS_SRC="${ABS_CHROMIUM_TOOLS_DIR}" \ |
| 553 -DCHROMIUM_TOOLS="${chrome_tools}" \ |
| 554 "${ABS_LLVM_DIR}" |
| 555 env |
| 556 |
| 557 if [[ -n "${gcc_toolchain}" ]]; then |
| 558 # Copy in the right stdlibc++.so.6 so clang can start. |
| 559 mkdir -p lib |
| 560 cp -v "$(${CXX} ${CXXFLAGS} -print-file-name=libstdc++.so.6)" lib/ |
| 561 fi |
| 562 |
| 563 ninja |
| 564 # If any Chromium tools were built, install those now. |
| 565 if [[ -n "${chrome_tools}" ]]; then |
| 566 ninja cr-install |
| 567 fi |
| 568 |
| 569 STRIP_FLAGS= |
| 570 if [ "${OS}" = "Darwin" ]; then |
| 571 # See http://crbug.com/256342 |
| 572 STRIP_FLAGS=-x |
| 573 |
| 574 cp libcxxbuild/libc++.1.dylib bin/ |
| 575 fi |
| 576 strip ${STRIP_FLAGS} bin/clang |
| 577 popd |
| 578 |
| 579 # Build compiler-rt out-of-tree. |
| 580 # Do a clobbered build due to cmake changes. |
| 581 rm -rf "${COMPILER_RT_BUILD_DIR}" |
| 582 mkdir -p "${COMPILER_RT_BUILD_DIR}" |
| 583 pushd "${COMPILER_RT_BUILD_DIR}" |
| 584 |
| 585 rm -fv CMakeCache.txt |
| 586 MACOSX_DEPLOYMENT_TARGET=${deployment_target} CC="" CXX="" cmake -GNinja \ |
| 587 -DCMAKE_BUILD_TYPE=Release \ |
| 588 -DLLVM_ENABLE_ASSERTIONS=ON \ |
| 589 -DLLVM_ENABLE_THREADS=OFF \ |
| 590 -DCMAKE_C_COMPILER="${ABS_LLVM_BUILD_DIR}/bin/clang" \ |
| 591 -DCMAKE_CXX_COMPILER="${ABS_LLVM_BUILD_DIR}/bin/clang++" \ |
| 592 -DSANITIZER_MIN_OSX_VERSION="10.7" \ |
| 593 -DLLVM_CONFIG_PATH="${ABS_LLVM_BUILD_DIR}/bin/llvm-config" \ |
| 594 "${ABS_COMPILER_RT_DIR}" |
| 595 |
| 596 ninja |
| 597 |
| 598 # Copy selected output to the main tree. |
| 599 # Darwin doesn't support cp --parents, so pipe through tar instead. |
| 600 CLANG_VERSION=$("${ABS_LLVM_BUILD_DIR}/bin/clang" --version | \ |
| 601 sed -ne 's/clang version \([0-9]\.[0-9]\.[0-9]\).*/\1/p') |
| 602 ABS_LLVM_CLANG_LIB_DIR="${ABS_LLVM_BUILD_DIR}/lib/clang/${CLANG_VERSION}" |
| 603 tar -c *blacklist.txt | tar -C ${ABS_LLVM_CLANG_LIB_DIR} -xv |
| 604 tar -c include/sanitizer | tar -C ${ABS_LLVM_CLANG_LIB_DIR} -xv |
| 605 if [[ "${OS}" = "Darwin" ]]; then |
| 606 tar -c lib/darwin | tar -C ${ABS_LLVM_CLANG_LIB_DIR} -xv |
| 607 else |
| 608 tar -c lib/linux | tar -C ${ABS_LLVM_CLANG_LIB_DIR} -xv |
| 609 fi |
| 610 |
| 611 popd |
| 612 |
| 613 if [[ -n "${with_android}" ]]; then |
| 614 # Make a standalone Android toolchain. |
| 615 ${ANDROID_NDK_DIR}/build/tools/make-standalone-toolchain.sh \ |
| 616 --platform=android-19 \ |
| 617 --install-dir="${LLVM_BUILD_DIR}/android-toolchain-arm" \ |
| 618 --system=linux-x86_64 \ |
| 619 --stl=stlport \ |
| 620 --toolchain=arm-linux-androideabi-4.9 |
| 621 |
| 622 # Do the same for x86. |
| 623 ${ANDROID_NDK_DIR}/build/tools/make-standalone-toolchain.sh \ |
| 624 --platform=android-19 \ |
| 625 --install-dir="${LLVM_BUILD_DIR}/android-toolchain-i686" \ |
| 626 --system=linux-x86_64 \ |
| 627 --stl=stlport \ |
| 628 --toolchain=x86-4.9 |
| 629 |
| 630 for target_arch in "arm" "i686"; do |
| 631 # Android NDK r9d copies a broken unwind.h into the toolchain, see |
| 632 # http://crbug.com/357890 |
| 633 rm -v "${LLVM_BUILD_DIR}"/android-toolchain-${target_arch}/include/c++/*/unw
ind.h |
| 634 |
| 635 # Build ASan runtime for Android in a separate build tree. |
| 636 mkdir -p ${LLVM_BUILD_DIR}/android-${target_arch} |
| 637 pushd ${LLVM_BUILD_DIR}/android-${target_arch} |
| 638 rm -fv CMakeCache.txt |
| 639 MACOSX_DEPLOYMENT_TARGET=${deployment_target} cmake -GNinja \ |
| 640 -DCMAKE_BUILD_TYPE=Release \ |
| 641 -DLLVM_ENABLE_ASSERTIONS=ON \ |
| 642 -DLLVM_ENABLE_THREADS=OFF \ |
| 643 -DCMAKE_C_COMPILER=${PWD}/../bin/clang \ |
| 644 -DCMAKE_CXX_COMPILER=${PWD}/../bin/clang++ \ |
| 645 -DLLVM_CONFIG_PATH=${PWD}/../bin/llvm-config \ |
| 646 -DCMAKE_C_FLAGS="--target=${target_arch}-linux-androideabi --sysroot=${P
WD}/../android-toolchain-${target_arch}/sysroot -B${PWD}/../android-toolchain-${
target_arch}" \ |
| 647 -DCMAKE_CXX_FLAGS="--target=${target_arch}-linux-androideabi --sysroot=$
{PWD}/../android-toolchain-${target_arch}/sysroot -B${PWD}/../android-toolchain-
${target_arch}" \ |
| 648 -DANDROID=1 \ |
| 649 "${ABS_COMPILER_RT_DIR}" |
| 650 ninja libclang_rt.asan-${target_arch}-android.so |
| 651 |
| 652 # And copy it into the main build tree. |
| 653 cp "$(find -name libclang_rt.asan-${target_arch}-android.so)" "${ABS_LLVM_CL
ANG_LIB_DIR}/lib/linux/" |
| 654 popd |
| 655 done |
| 656 fi |
| 657 |
| 658 # After everything is done, log success for this revision. |
| 659 echo "${PACKAGE_VERSION}" > "${STAMP_FILE}" |
OLD | NEW |