[MD settings] moving attached() code
[chromium-blink-merge.git] / tools / clang / scripts / update.sh
blob6e0b25464985dbbc1b288e8f975a8316533bf5bf
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.
6 # This script will check out llvm and clang into third_party/llvm and build it.
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=245965
13 # This is incremented when pushing a new build of Clang at the same revision.
14 CLANG_SUB_REVISION=1
16 PACKAGE_VERSION="${CLANG_REVISION}-${CLANG_SUB_REVISION}"
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"
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}"
41 # ${A:-a} returns $A if it's set, a else.
42 LLVM_REPO_URL=${LLVM_URL:-https://llvm.org/svn/llvm-project}
44 CDS_URL=https://commondatastorage.googleapis.com/chromium-browser-clang
46 if [[ -z "$GYP_DEFINES" ]]; then
47 GYP_DEFINES=
49 if [[ -z "$GYP_GENERATORS" ]]; then
50 GYP_GENERATORS=
52 if [[ -z "$LLVM_DOWNLOAD_GOLD_PLUGIN" ]]; then
53 LLVM_DOWNLOAD_GOLD_PLUGIN=
57 # Die if any command dies, error on undefined variable expansions.
58 set -eu
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"
69 OS="$(uname -s)"
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
81 if [[ "${OS}" = "Darwin" ]]; then
82 with_android=
85 while [[ $# > 0 ]]; do
86 case $1 in
87 --bootstrap)
88 bootstrap=yes
90 --if-needed)
91 if_needed=yes
93 --force-local-build)
94 force_local_build=yes
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
102 exit 0
104 --run-tests)
105 run_tests=yes
107 --without-android)
108 with_android=
110 --without-patches)
111 with_patches=
113 --with-chrome-tools)
114 shift
115 if [[ $# == 0 ]]; then
116 echo "--with-chrome-tools requires an argument."
117 exit 1
119 chrome_tools=$1
121 --gcc-toolchain)
122 shift
123 if [[ $# == 0 ]]; then
124 echo "--gcc-toolchain requires an argument."
125 exit 1
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
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
155 echo "Unknown argument: '$1'."
156 echo "Use --help for help."
157 exit 1
159 esac
160 shift
161 done
163 if [[ -n ${LLVM_FORCE_HEAD_REVISION:-''} ]]; then
164 force_local_build=yes
166 # Skip local patches when using HEAD: they probably don't apply anymore.
167 with_patches=
169 if ! [[ "$GYP_DEFINES" =~ .*OS=android.* ]]; then
170 # Only build the Android ASan rt when targetting Android.
171 with_android=
174 LLVM_BUILD_TOOLS_DIR="${ABS_LLVM_DIR}/../llvm-build-tools"
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
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)))"
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
203 export PATH="${LLVM_BUILD_TOOLS_DIR}/cmake310/bin:${PATH}"
207 echo "LLVM_FORCE_HEAD_REVISION was set; using r${CLANG_REVISION}"
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
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
241 # To always force a new build if someone interrupts their build half way.
242 rm -f "${STAMP_FILE}"
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}"
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
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
278 exit 0
279 else
280 echo Did not find prebuilt clang "${PACKAGE_VERSION}", building
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
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
298 if ! which ninja > /dev/null; then
299 echo "ninja needed to build clang, please install"
300 exit 1
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_libcdep.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}"
335 done
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}
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}"
349 echo Getting clang r"${CLANG_REVISION}" in "${CLANG_DIR}"
350 svn co --force "${LLVM_REPO_URL}/cfe/trunk@${CLANG_REVISION}" "${CLANG_DIR}"
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"
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}"
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}"
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}"
376 if [[ -n "$with_patches" ]]; then
377 # No patches.
378 true
381 # Echo all commands.
382 set -x
384 # Set default values for CC and CXX if they're not set in the environment.
385 CC=${CC:-cc}
386 CXX=${CXX:-c++}
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))"
397 CFLAGS=""
398 CXXFLAGS=""
399 LDFLAGS=""
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=""
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}"
416 if [[ -n "${bootstrap}" ]]; then
417 deployment_target=10.6
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}"
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
440 ninja
441 if [[ -n "${run_tests}" ]]; then
442 ninja check-all
445 ninja install
446 if [[ -n "${gcc_toolchain}" ]]; then
447 # Copy that gcc's stdlibc++.so.6 to the build dir, so the bootstrap
448 # compiler can start.
449 cp -v "$(${CXX} -print-file-name=libstdc++.so.6)" \
450 "${ABS_INSTALL_DIR}/lib/"
453 popd
454 CC="${ABS_INSTALL_DIR}/bin/clang"
455 CXX="${ABS_INSTALL_DIR}/bin/clang++"
457 if [[ -n "${gcc_toolchain}" ]]; then
458 # Tell the bootstrap compiler to use a specific gcc prefix to search
459 # for standard library headers and shared object files.
460 CFLAGS="--gcc-toolchain=${gcc_toolchain}"
461 CXXFLAGS="--gcc-toolchain=${gcc_toolchain}"
464 echo "Building final compiler"
467 # Build clang (in a separate directory).
468 # The clang bots have this path hardcoded in built/scripts/slave/compile.py,
469 # so if you change it you also need to change these links.
470 mkdir -p "${LLVM_BUILD_DIR}"
471 pushd "${LLVM_BUILD_DIR}"
473 # Build libc++.dylib while some bots are still on OS X 10.6.
474 if [ "${OS}" = "Darwin" ]; then
475 rm -rf libcxxbuild
476 LIBCXXFLAGS="-O3 -std=c++11 -fstrict-aliasing"
478 # libcxx and libcxxabi both have a file stdexcept.cpp, so put their .o files
479 # into different subdirectories.
480 mkdir -p libcxxbuild/libcxx
481 pushd libcxxbuild/libcxx
482 ${CXX:-c++} -c ${CXXFLAGS} ${LIBCXXFLAGS} "${ABS_LIBCXX_DIR}"/src/*.cpp
483 popd
485 mkdir -p libcxxbuild/libcxxabi
486 pushd libcxxbuild/libcxxabi
487 ${CXX:-c++} -c ${CXXFLAGS} ${LIBCXXFLAGS} "${ABS_LIBCXXABI_DIR}"/src/*.cpp -I"${ABS_LIBCXXABI_DIR}/include"
488 popd
490 pushd libcxxbuild
491 ${CC:-cc} libcxx/*.o libcxxabi/*.o -o libc++.1.dylib -dynamiclib \
492 -nodefaultlibs -current_version 1 -compatibility_version 1 \
493 -lSystem -install_name @executable_path/libc++.dylib \
494 -Wl,-unexported_symbols_list,${ABS_LIBCXX_DIR}/lib/libc++unexp.exp \
495 -Wl,-force_symbols_not_weak_list,${ABS_LIBCXX_DIR}/lib/notweak.exp \
496 -Wl,-force_symbols_weak_list,${ABS_LIBCXX_DIR}/lib/weak.exp
497 ln -sf libc++.1.dylib libc++.dylib
498 popd
499 LDFLAGS+="-stdlib=libc++ -L${PWD}/libcxxbuild"
501 if [[ -n "${bootstrap}" ]]; then
502 # Now that the libc++ headers have been installed and libc++.dylib is built,
503 # delete the libc++ checkout again so that it's not part of the main
504 # build below -- the libc++(abi) tests don't pass on OS X in bootstrap
505 # builds (http://llvm.org/PR24068)
506 rm -rf "${ABS_LIBCXX_DIR}"
507 rm -rf "${ABS_LIBCXXABI_DIR}"
508 CXXFLAGS="-stdlib=libc++ -nostdinc++ -I${ABS_INSTALL_DIR}/include/c++/v1 ${CFLAGS}"
512 # Find the binutils include dir for the gold plugin.
513 BINUTILS_INCDIR=""
514 if [ "${OS}" = "Linux" ]; then
515 BINUTILS_INCDIR="${ABS_BINUTILS_DIR}/Linux_x64/Release/include"
519 # If building at head, define a macro that plugins can use for #ifdefing
520 # out code that builds at head, but not at CLANG_REVISION or vice versa.
521 if [[ -n ${LLVM_FORCE_HEAD_REVISION:-''} ]]; then
522 CFLAGS="${CFLAGS} -DLLVM_FORCE_HEAD_REVISION"
523 CXXFLAGS="${CXXFLAGS} -DLLVM_FORCE_HEAD_REVISION"
526 # Hook the Chromium tools into the LLVM build. Several Chromium tools have
527 # dependencies on LLVM/Clang libraries. The LLVM build detects implicit tools
528 # in the tools subdirectory, so install a shim CMakeLists.txt that forwards to
529 # the real directory for the Chromium tools.
530 # Note that the shim directory name intentionally has no _ or _. The implicit
531 # tool detection logic munges them in a weird way.
532 mkdir -v ${CHROME_TOOLS_SHIM_DIR}
533 cat > ${CHROME_TOOLS_SHIM_DIR}/CMakeLists.txt << EOF
534 # Since tools/clang isn't actually a subdirectory, use the two argument version
535 # to specify where build artifacts go. CMake doesn't allow reusing the same
536 # binary dir for multiple source dirs, so the build artifacts have to go into a
537 # subdirectory...
538 add_subdirectory(\${CHROMIUM_TOOLS_SRC} \${CMAKE_CURRENT_BINARY_DIR}/a)
540 rm -fv CMakeCache.txt
541 MACOSX_DEPLOYMENT_TARGET=${deployment_target} cmake -GNinja \
542 -DCMAKE_BUILD_TYPE=Release \
543 -DLLVM_ENABLE_ASSERTIONS=ON \
544 -DLLVM_ENABLE_THREADS=OFF \
545 -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly \
546 -DLLVM_BINUTILS_INCDIR="${BINUTILS_INCDIR}" \
547 -DCMAKE_C_COMPILER="${CC}" \
548 -DCMAKE_CXX_COMPILER="${CXX}" \
549 -DCMAKE_C_FLAGS="${CFLAGS}" \
550 -DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
551 -DCMAKE_EXE_LINKER_FLAGS="${LDFLAGS}" \
552 -DCMAKE_SHARED_LINKER_FLAGS="${LDFLAGS}" \
553 -DCMAKE_MODULE_LINKER_FLAGS="${LDFLAGS}" \
554 -DCMAKE_INSTALL_PREFIX="${ABS_LLVM_BUILD_DIR}" \
555 -DCHROMIUM_TOOLS_SRC="${ABS_CHROMIUM_TOOLS_DIR}" \
556 -DCHROMIUM_TOOLS="${chrome_tools}" \
557 "${ABS_LLVM_DIR}"
560 if [[ -n "${gcc_toolchain}" ]]; then
561 # Copy in the right stdlibc++.so.6 so clang can start.
562 mkdir -p lib
563 cp -v "$(${CXX} ${CXXFLAGS} -print-file-name=libstdc++.so.6)" lib/
566 ninja
567 # If any Chromium tools were built, install those now.
568 if [[ -n "${chrome_tools}" ]]; then
569 ninja cr-install
572 STRIP_FLAGS=
573 if [ "${OS}" = "Darwin" ]; then
574 # See http://crbug.com/256342
575 STRIP_FLAGS=-x
577 cp libcxxbuild/libc++.1.dylib bin/
579 strip ${STRIP_FLAGS} bin/clang
580 popd
582 # Build compiler-rt out-of-tree.
583 mkdir -p "${COMPILER_RT_BUILD_DIR}"
584 pushd "${COMPILER_RT_BUILD_DIR}"
586 rm -fv CMakeCache.txt
587 MACOSX_DEPLOYMENT_TARGET=${deployment_target} cmake -GNinja \
588 -DCMAKE_BUILD_TYPE=Release \
589 -DLLVM_ENABLE_ASSERTIONS=ON \
590 -DLLVM_ENABLE_THREADS=OFF \
591 -DCMAKE_C_COMPILER="${CC}" \
592 -DCMAKE_CXX_COMPILER="${CXX}" \
593 -DSANITIZER_MIN_OSX_VERSION="10.7" \
594 -DLLVM_CONFIG_PATH="${ABS_LLVM_BUILD_DIR}/bin/llvm-config" \
595 "${ABS_COMPILER_RT_DIR}"
597 ninja
599 # Copy selected output to the main tree.
600 # Darwin doesn't support cp --parents, so pipe through tar instead.
601 CLANG_VERSION=$("${ABS_LLVM_BUILD_DIR}/bin/clang" --version | \
602 sed -ne 's/clang version \([0-9]\.[0-9]\.[0-9]\).*/\1/p')
603 ABS_LLVM_CLANG_LIB_DIR="${ABS_LLVM_BUILD_DIR}/lib/clang/${CLANG_VERSION}"
604 tar -c *blacklist.txt | tar -C ${ABS_LLVM_CLANG_LIB_DIR} -xv
605 tar -c include/sanitizer | tar -C ${ABS_LLVM_CLANG_LIB_DIR} -xv
606 if [[ "${OS}" = "Darwin" ]]; then
607 tar -c lib/darwin | tar -C ${ABS_LLVM_CLANG_LIB_DIR} -xv
608 else
609 tar -c lib/linux | tar -C ${ABS_LLVM_CLANG_LIB_DIR} -xv
612 popd
614 if [[ -n "${with_android}" ]]; then
615 # Make a standalone Android toolchain.
616 ${ANDROID_NDK_DIR}/build/tools/make-standalone-toolchain.sh \
617 --platform=android-19 \
618 --install-dir="${LLVM_BUILD_DIR}/android-toolchain-arm" \
619 --system=linux-x86_64 \
620 --stl=stlport \
621 --toolchain=arm-linux-androideabi-4.9
623 # Do the same for x86.
624 ${ANDROID_NDK_DIR}/build/tools/make-standalone-toolchain.sh \
625 --platform=android-19 \
626 --install-dir="${LLVM_BUILD_DIR}/android-toolchain-i686" \
627 --system=linux-x86_64 \
628 --stl=stlport \
629 --toolchain=x86-4.9
631 for target_arch in "arm" "i686"; do
632 # Android NDK r9d copies a broken unwind.h into the toolchain, see
633 # http://crbug.com/357890
634 rm -v "${LLVM_BUILD_DIR}"/android-toolchain-${target_arch}/include/c++/*/unwind.h
636 # Build ASan runtime for Android in a separate build tree.
637 mkdir -p ${LLVM_BUILD_DIR}/android-${target_arch}
638 pushd ${LLVM_BUILD_DIR}/android-${target_arch}
639 rm -fv CMakeCache.txt
640 MACOSX_DEPLOYMENT_TARGET=${deployment_target} cmake -GNinja \
641 -DCMAKE_BUILD_TYPE=Release \
642 -DLLVM_ENABLE_ASSERTIONS=ON \
643 -DLLVM_ENABLE_THREADS=OFF \
644 -DCMAKE_C_COMPILER=${PWD}/../bin/clang \
645 -DCMAKE_CXX_COMPILER=${PWD}/../bin/clang++ \
646 -DLLVM_CONFIG_PATH=${PWD}/../bin/llvm-config \
647 -DCMAKE_C_FLAGS="--target=${target_arch}-linux-androideabi --sysroot=${PWD}/../android-toolchain-${target_arch}/sysroot -B${PWD}/../android-toolchain-${target_arch}" \
648 -DCMAKE_CXX_FLAGS="--target=${target_arch}-linux-androideabi --sysroot=${PWD}/../android-toolchain-${target_arch}/sysroot -B${PWD}/../android-toolchain-${target_arch}" \
649 -DANDROID=1 \
650 "${ABS_COMPILER_RT_DIR}"
651 ninja libclang_rt.asan-${target_arch}-android.so
653 # And copy it into the main build tree.
654 cp "$(find -name libclang_rt.asan-${target_arch}-android.so)" "${ABS_LLVM_CLANG_LIB_DIR}/lib/linux/"
655 popd
656 done
659 if [[ -n "$run_tests" || -n "${LLVM_FORCE_HEAD_REVISION:-''}" ]]; then
660 # Run Chrome tool tests.
661 ninja -C "${LLVM_BUILD_DIR}" cr-check-all
663 if [[ -n "$run_tests" ]]; then
664 # Run the LLVM and Clang tests.
665 ninja -C "${LLVM_BUILD_DIR}" check-all
668 # After everything is done, log success for this revision.
669 echo "${PACKAGE_VERSION}" > "${STAMP_FILE}"