Reland "Enable libc++ on Android"
[chromium-blink-merge.git] / tools / clang / scripts / update.sh
blobdd6f089dc0a20aca68c1e7d837344a1398c7cd90
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=233105
13 # This is incremented when pushing a new build of Clang at the same revision.
14 CLANG_SUB_REVISION=2
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=
54 # Die if any command dies, error on undefined variable expansions.
55 set -eu
58 if [[ -n ${LLVM_FORCE_HEAD_REVISION:-''} ]]; then
59 # Use a real version number rather than HEAD to make sure that
60 # --print-revision, stamp file logic, etc. all works naturally.
61 CLANG_REVISION=$(svn info "$LLVM_REPO_URL" \
62 | grep 'Last Changed Rev' | awk '{ printf $4; }')
63 PACKAGE_VERSION="${CLANG_REVISION}-0"
66 OS="$(uname -s)"
68 # Parse command line options.
69 if_needed=
70 force_local_build=
71 run_tests=
72 bootstrap=
73 with_android=yes
74 chrome_tools="plugins;blink_gc_plugin"
75 gcc_toolchain=
76 with_patches=yes
78 if [[ "${OS}" = "Darwin" ]]; then
79 with_android=
82 while [[ $# > 0 ]]; do
83 case $1 in
84 --bootstrap)
85 bootstrap=yes
87 --if-needed)
88 if_needed=yes
90 --force-local-build)
91 force_local_build=yes
93 --print-revision)
94 echo $PACKAGE_VERSION
95 exit 0
97 --run-tests)
98 run_tests=yes
100 --without-android)
101 with_android=
103 --without-patches)
104 with_patches=
106 --with-chrome-tools)
107 shift
108 if [[ $# == 0 ]]; then
109 echo "--with-chrome-tools requires an argument."
110 exit 1
112 chrome_tools=$1
114 --gcc-toolchain)
115 shift
116 if [[ $# == 0 ]]; then
117 echo "--gcc-toolchain requires an argument."
118 exit 1
120 if [[ -x "$1/bin/gcc" ]]; then
121 gcc_toolchain=$1
122 else
123 echo "Invalid --gcc-toolchain: '$1'."
124 echo "'$1/bin/gcc' does not appear to be valid."
125 exit 1
129 --help)
130 echo "usage: $0 [--force-local-build] [--if-needed] [--run-tests] "
131 echo "--bootstrap: First build clang with CC, then with itself."
132 echo "--force-local-build: Don't try to download prebuilt binaries."
133 echo "--if-needed: Download clang only if the script thinks it is needed."
134 echo "--run-tests: Run tests after building. Only for local builds."
135 echo "--print-revision: Print current clang revision and exit."
136 echo "--without-android: Don't build ASan Android runtime library."
137 echo "--with-chrome-tools: Select which chrome tools to build." \
138 "Defaults to plugins;blink_gc_plugin."
139 echo " Example: --with-chrome-tools plugins;empty-string"
140 echo "--gcc-toolchain: Set the prefix for which GCC version should"
141 echo " be used for building. For example, to use gcc in"
142 echo " /opt/foo/bin/gcc, use '--gcc-toolchain '/opt/foo"
143 echo "--without-patches: Don't apply local patches."
144 echo
145 exit 1
148 echo "Unknown argument: '$1'."
149 echo "Use --help for help."
150 exit 1
152 esac
153 shift
154 done
156 if [[ -n ${LLVM_FORCE_HEAD_REVISION:-''} ]]; then
157 force_local_build=yes
159 # Skip local patches when using HEAD: they probably don't apply anymore.
160 with_patches=
162 if ! [[ "$GYP_DEFINES" =~ .*OS=android.* ]]; then
163 # Only build the Android ASan rt when targetting Android.
164 with_android=
167 LLVM_BUILD_TOOLS_DIR="${ABS_LLVM_DIR}/../llvm-build-tools"
169 if [[ "${OS}" == "Linux" ]] && [[ -z "${gcc_toolchain}" ]]; then
170 if [[ $(gcc -dumpversion) < "4.7.0" ]]; then
171 # We need a newer GCC version.
172 if [[ ! -e "${LLVM_BUILD_TOOLS_DIR}/gcc482" ]]; then
173 echo "Downloading pre-built GCC 4.8.2..."
174 mkdir -p "${LLVM_BUILD_TOOLS_DIR}"
175 curl --fail -L "${CDS_URL}/tools/gcc482.tgz" | \
176 tar zxf - -C "${LLVM_BUILD_TOOLS_DIR}"
177 echo Done
179 gcc_toolchain="${LLVM_BUILD_TOOLS_DIR}/gcc482"
180 else
181 # Always set gcc_toolchain; llvm-symbolizer needs the bundled libstdc++.
182 gcc_toolchain="$(dirname $(dirname $(which gcc)))"
186 if [[ "${OS}" == "Linux" || "${OS}" == "Darwin" ]]; then
187 if [[ $(cmake --version | grep -Eo '[0-9.]+') < "3.0" ]]; then
188 # We need a newer CMake version.
189 if [[ ! -e "${LLVM_BUILD_TOOLS_DIR}/cmake310" ]]; then
190 echo "Downloading pre-built CMake 3.10..."
191 mkdir -p "${LLVM_BUILD_TOOLS_DIR}"
192 curl --fail -L "${CDS_URL}/tools/cmake310_${OS}.tgz" | \
193 tar zxf - -C "${LLVM_BUILD_TOOLS_DIR}"
194 echo Done
196 export PATH="${LLVM_BUILD_TOOLS_DIR}/cmake310/bin:${PATH}"
200 echo "LLVM_FORCE_HEAD_REVISION was set; using r${CLANG_REVISION}"
203 if [[ -n "$if_needed" ]]; then
204 if [[ "${OS}" == "Darwin" ]]; then
205 # clang is used on Mac.
206 true
207 elif [[ "$GYP_DEFINES" =~ .*(clang|tsan|asan|lsan|msan)=1.* ]]; then
208 # clang requested via $GYP_DEFINES.
209 true
210 elif [[ -d "${LLVM_BUILD_DIR}" ]]; then
211 # clang previously downloaded, remove third_party/llvm-build to prevent
212 # updating.
213 true
214 elif [[ "${OS}" == "Linux" ]]; then
215 # Temporarily use clang on linux. Leave a stamp file behind, so that
216 # this script can remove clang again on machines where it was autoinstalled.
217 mkdir -p "${LLVM_BUILD_DIR}"
218 touch "${LLVM_BUILD_DIR}/autoinstall_stamp"
219 true
220 else
221 # clang wasn't needed, not doing anything.
222 exit 0
227 # Check if there's anything to be done, exit early if not.
228 if [[ -f "${STAMP_FILE}" ]]; then
229 PREVIOUSLY_BUILT_REVISON=$(cat "${STAMP_FILE}")
230 if [[ -z "$force_local_build" ]] && \
231 [[ "${PREVIOUSLY_BUILT_REVISON}" = \
232 "${PACKAGE_VERSION}" ]]; then
233 echo "Clang already at ${PACKAGE_VERSION}"
234 exit 0
237 # To always force a new build if someone interrupts their build half way.
238 rm -f "${STAMP_FILE}"
241 if [[ -z "$force_local_build" ]]; then
242 # Check if there's a prebuilt binary and if so just fetch that. That's faster,
243 # and goma relies on having matching binary hashes on client and server too.
244 CDS_FILE="clang-${PACKAGE_VERSION}.tgz"
245 CDS_OUT_DIR=$(mktemp -d -t clang_download.XXXXXX)
246 CDS_OUTPUT="${CDS_OUT_DIR}/${CDS_FILE}"
247 if [ "${OS}" = "Linux" ]; then
248 CDS_FULL_URL="${CDS_URL}/Linux_x64/${CDS_FILE}"
249 elif [ "${OS}" = "Darwin" ]; then
250 CDS_FULL_URL="${CDS_URL}/Mac/${CDS_FILE}"
252 echo Trying to download prebuilt clang
253 if which curl > /dev/null; then
254 curl -L --fail "${CDS_FULL_URL}" -o "${CDS_OUTPUT}" || \
255 rm -rf "${CDS_OUT_DIR}"
256 elif which wget > /dev/null; then
257 wget "${CDS_FULL_URL}" -O "${CDS_OUTPUT}" || rm -rf "${CDS_OUT_DIR}"
258 else
259 echo "Neither curl nor wget found. Please install one of these."
260 exit 1
262 if [ -f "${CDS_OUTPUT}" ]; then
263 rm -rf "${LLVM_BUILD_DIR}"
264 mkdir -p "${LLVM_BUILD_DIR}"
265 tar -xzf "${CDS_OUTPUT}" -C "${LLVM_BUILD_DIR}"
266 echo clang "${PACKAGE_VERSION}" unpacked
267 echo "${PACKAGE_VERSION}" > "${STAMP_FILE}"
268 rm -rf "${CDS_OUT_DIR}"
269 exit 0
270 else
271 echo Did not find prebuilt clang "${PACKAGE_VERSION}", building
275 if [[ -n "${with_android}" ]] && ! [[ -d "${ANDROID_NDK_DIR}" ]]; then
276 echo "Android NDK not found at ${ANDROID_NDK_DIR}"
277 echo "The Android NDK is needed to build a Clang whose -fsanitize=address"
278 echo "works on Android. See "
279 echo "http://code.google.com/p/chromium/wiki/AndroidBuildInstructions for how"
280 echo "to install the NDK, or pass --without-android."
281 exit 1
284 # Check that cmake and ninja are available.
285 if ! which cmake > /dev/null; then
286 echo "CMake needed to build clang; please install"
287 exit 1
289 if ! which ninja > /dev/null; then
290 echo "ninja needed to build clang, please install"
291 exit 1
294 echo Reverting previously patched files
295 for i in \
296 "${CLANG_DIR}/test/Index/crash-recovery-modules.m" \
297 "${CLANG_DIR}/unittests/libclang/LibclangTest.cpp" \
298 "${COMPILER_RT_DIR}/lib/asan/asan_rtl.cc" \
299 "${COMPILER_RT_DIR}/test/asan/TestCases/Linux/new_array_cookie_test.cc" \
300 "${LLVM_DIR}/test/DebugInfo/gmlt.ll" \
301 "${LLVM_DIR}/lib/CodeGen/SpillPlacement.cpp" \
302 "${LLVM_DIR}/lib/CodeGen/SpillPlacement.h" \
303 "${LLVM_DIR}/lib/Transforms/Instrumentation/MemorySanitizer.cpp" \
304 "${CLANG_DIR}/test/Driver/env.c" \
305 "${CLANG_DIR}/lib/Frontend/InitPreprocessor.cpp" \
306 "${CLANG_DIR}/test/Frontend/exceptions.c" \
307 "${CLANG_DIR}/test/Preprocessor/predefined-exceptions.m" \
308 "${LLVM_DIR}/test/Bindings/Go/go.test" \
309 "${CLANG_DIR}/lib/Parse/ParseExpr.cpp" \
310 "${CLANG_DIR}/lib/Parse/ParseTemplate.cpp" \
311 "${CLANG_DIR}/lib/Sema/SemaDeclCXX.cpp" \
312 "${CLANG_DIR}/lib/Sema/SemaExprCXX.cpp" \
313 "${CLANG_DIR}/test/SemaCXX/default2.cpp" \
314 "${CLANG_DIR}/test/SemaCXX/typo-correction-delayed.cpp" \
315 "${COMPILER_RT_DIR}/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc" \
316 "${COMPILER_RT_DIR}/test/tsan/signal_segv_handler.cc" \
317 "${COMPILER_RT_DIR}/lib/sanitizer_common/sanitizer_coverage_libcdep.cc" \
318 ; do
319 if [[ -e "${i}" ]]; then
320 rm -f "${i}" # For unversioned files.
321 svn revert "${i}"
323 done
325 echo Remove the Clang tools shim dir
326 CHROME_TOOLS_SHIM_DIR=${ABS_LLVM_DIR}/tools/chrometools
327 rm -rfv ${CHROME_TOOLS_SHIM_DIR}
329 echo Getting LLVM r"${CLANG_REVISION}" in "${LLVM_DIR}"
330 if ! svn co --force "${LLVM_REPO_URL}/llvm/trunk@${CLANG_REVISION}" \
331 "${LLVM_DIR}"; then
332 echo Checkout failed, retrying
333 rm -rf "${LLVM_DIR}"
334 svn co --force "${LLVM_REPO_URL}/llvm/trunk@${CLANG_REVISION}" "${LLVM_DIR}"
337 echo Getting clang r"${CLANG_REVISION}" in "${CLANG_DIR}"
338 svn co --force "${LLVM_REPO_URL}/cfe/trunk@${CLANG_REVISION}" "${CLANG_DIR}"
340 # We have moved from building compiler-rt in the LLVM tree, to a separate
341 # directory. Nuke any previous checkout to avoid building it.
342 rm -rf "${LLVM_DIR}/projects/compiler-rt"
344 echo Getting compiler-rt r"${CLANG_REVISION}" in "${COMPILER_RT_DIR}"
345 svn co --force "${LLVM_REPO_URL}/compiler-rt/trunk@${CLANG_REVISION}" \
346 "${COMPILER_RT_DIR}"
348 # clang needs a libc++ checkout, else -stdlib=libc++ won't find includes
349 # (i.e. this is needed for bootstrap builds).
350 if [ "${OS}" = "Darwin" ]; then
351 echo Getting libc++ r"${CLANG_REVISION}" in "${LIBCXX_DIR}"
352 svn co --force "${LLVM_REPO_URL}/libcxx/trunk@${CLANG_REVISION}" \
353 "${LIBCXX_DIR}"
356 # While we're bundling our own libc++ on OS X, we need to compile libc++abi
357 # into it too (since OS X 10.6 doesn't have libc++abi.dylib either).
358 if [ "${OS}" = "Darwin" ]; then
359 echo Getting libc++abi r"${CLANG_REVISION}" in "${LIBCXXABI_DIR}"
360 svn co --force "${LLVM_REPO_URL}/libcxxabi/trunk@${CLANG_REVISION}" \
361 "${LIBCXXABI_DIR}"
364 if [[ -n "$with_patches" ]]; then
366 # Apply patch for tests failing with --disable-pthreads (llvm.org/PR11974)
367 pushd "${CLANG_DIR}"
368 cat << 'EOF' |
369 --- third_party/llvm/tools/clang/test/Index/crash-recovery-modules.m (revision 202554)
370 +++ third_party/llvm/tools/clang/test/Index/crash-recovery-modules.m (working copy)
371 @@ -12,6 +12,8 @@
373 // REQUIRES: crash-recovery
374 // REQUIRES: shell
375 +// XFAIL: *
376 +// (PR11974)
378 @import Crash;
380 patch -p4
381 popd
383 pushd "${CLANG_DIR}"
384 cat << 'EOF' |
385 --- unittests/libclang/LibclangTest.cpp (revision 215949)
386 +++ unittests/libclang/LibclangTest.cpp (working copy)
387 @@ -431,7 +431,7 @@
388 EXPECT_EQ(0U, clang_getNumDiagnostics(ClangTU));
391 -TEST_F(LibclangReparseTest, ReparseWithModule) {
392 +TEST_F(LibclangReparseTest, DISABLED_ReparseWithModule) {
393 const char *HeaderTop = "#ifndef H\n#define H\nstruct Foo { int bar;";
394 const char *HeaderBottom = "\n};\n#endif\n";
395 const char *MFile = "#include \"HeaderFile.h\"\nint main() {"
397 patch -p0
398 popd
400 # Cherry-pick r234010 [sancov] Shrink pc array on Android back to 2**24."
401 pushd "${COMPILER_RT_DIR}"
402 cat << 'EOF' |
403 diff --git a/lib/sanitizer_common/sanitizer_coverage_libcdep.cc b/lib/sanitizer_common/sanitizer_coverage_libcdep.cc
404 index 4b976fc..cfd9e7e 100644
405 --- a/lib/sanitizer_common/sanitizer_coverage_libcdep.cc
406 +++ b/lib/sanitizer_common/sanitizer_coverage_libcdep.cc
407 @@ -109,7 +109,8 @@ class CoverageData {
409 // Maximal size pc array may ever grow.
410 // We MmapNoReserve this space to ensure that the array is contiguous.
411 - static const uptr kPcArrayMaxSize = FIRST_32_SECOND_64(1 << 26, 1 << 27);
412 + static const uptr kPcArrayMaxSize =
413 + FIRST_32_SECOND_64(1 << (SANITIZER_ANDROID ? 24 : 26), 1 << 27);
414 // The amount file mapping for the pc array is grown by.
415 static const uptr kPcArrayMmapSize = 64 * 1024;
418 patch -p1
419 popd
421 # This Go bindings test doesn't work after the bootstrap build on Linux. (PR21552)
422 pushd "${LLVM_DIR}"
423 cat << 'EOF' |
424 Index: test/Bindings/Go/go.test
425 ===================================================================
426 --- test/Bindings/Go/go.test (revision 223109)
427 +++ test/Bindings/Go/go.test (working copy)
428 @@ -1,3 +1,3 @@
429 -; RUN: llvm-go test llvm.org/llvm/bindings/go/llvm
430 +; RUN: true
432 ; REQUIRES: shell
434 patch -p0
435 popd
440 # Echo all commands.
441 set -x
443 # Set default values for CC and CXX if they're not set in the environment.
444 CC=${CC:-cc}
445 CXX=${CXX:-c++}
447 if [[ -n "${gcc_toolchain}" ]]; then
448 # Use the specified gcc installation for building.
449 CC="$gcc_toolchain/bin/gcc"
450 CXX="$gcc_toolchain/bin/g++"
451 # Set LD_LIBRARY_PATH to make auxiliary targets (tablegen, bootstrap compiler,
452 # etc.) find the .so.
453 export LD_LIBRARY_PATH="$(dirname $(${CXX} -print-file-name=libstdc++.so.6))"
456 CFLAGS=""
457 CXXFLAGS=""
458 LDFLAGS=""
460 # LLVM uses C++11 starting in llvm 3.5. On Linux, this means libstdc++4.7+ is
461 # needed, on OS X it requires libc++. clang only automatically links to libc++
462 # when targeting OS X 10.9+, so add stdlib=libc++ explicitly so clang can run on
463 # OS X versions as old as 10.7.
464 # TODO(thakis): Some bots are still on 10.6, so for now bundle libc++.dylib.
465 # Remove this once all bots are on 10.7+, then use --enable-libcpp=yes and
466 # change deployment_target to 10.7.
467 deployment_target=""
469 if [ "${OS}" = "Darwin" ]; then
470 # When building on 10.9, /usr/include usually doesn't exist, and while
471 # Xcode's clang automatically sets a sysroot, self-built clangs don't.
472 CFLAGS="-isysroot $(xcrun --show-sdk-path)"
473 CPPFLAGS="${CFLAGS}"
474 CXXFLAGS="-stdlib=libc++ -nostdinc++ -I${ABS_LIBCXX_DIR}/include ${CFLAGS}"
476 if [[ -n "${bootstrap}" ]]; then
477 deployment_target=10.6
481 # Build bootstrap clang if requested.
482 if [[ -n "${bootstrap}" ]]; then
483 ABS_INSTALL_DIR="${PWD}/${LLVM_BOOTSTRAP_INSTALL_DIR}"
484 echo "Building bootstrap compiler"
485 mkdir -p "${LLVM_BOOTSTRAP_DIR}"
486 pushd "${LLVM_BOOTSTRAP_DIR}"
488 cmake -GNinja \
489 -DCMAKE_BUILD_TYPE=Release \
490 -DLLVM_ENABLE_ASSERTIONS=ON \
491 -DLLVM_TARGETS_TO_BUILD=host \
492 -DLLVM_ENABLE_THREADS=OFF \
493 -DCMAKE_INSTALL_PREFIX="${ABS_INSTALL_DIR}" \
494 -DCMAKE_C_COMPILER="${CC}" \
495 -DCMAKE_CXX_COMPILER="${CXX}" \
496 -DCMAKE_C_FLAGS="${CFLAGS}" \
497 -DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
498 ../llvm
500 ninja
501 if [[ -n "${run_tests}" ]]; then
502 ninja check-all
505 ninja install
506 if [[ -n "${gcc_toolchain}" ]]; then
507 # Copy that gcc's stdlibc++.so.6 to the build dir, so the bootstrap
508 # compiler can start.
509 cp -v "$(${CXX} -print-file-name=libstdc++.so.6)" \
510 "${ABS_INSTALL_DIR}/lib/"
513 popd
514 CC="${ABS_INSTALL_DIR}/bin/clang"
515 CXX="${ABS_INSTALL_DIR}/bin/clang++"
517 if [[ -n "${gcc_toolchain}" ]]; then
518 # Tell the bootstrap compiler to use a specific gcc prefix to search
519 # for standard library headers and shared object file.
520 CFLAGS="--gcc-toolchain=${gcc_toolchain}"
521 CXXFLAGS="--gcc-toolchain=${gcc_toolchain}"
524 echo "Building final compiler"
527 # Build clang (in a separate directory).
528 # The clang bots have this path hardcoded in built/scripts/slave/compile.py,
529 # so if you change it you also need to change these links.
530 mkdir -p "${LLVM_BUILD_DIR}"
531 pushd "${LLVM_BUILD_DIR}"
533 # Build libc++.dylib while some bots are still on OS X 10.6.
534 if [ "${OS}" = "Darwin" ]; then
535 rm -rf libcxxbuild
536 LIBCXXFLAGS="-O3 -std=c++11 -fstrict-aliasing"
538 # libcxx and libcxxabi both have a file stdexcept.cpp, so put their .o files
539 # into different subdirectories.
540 mkdir -p libcxxbuild/libcxx
541 pushd libcxxbuild/libcxx
542 ${CXX:-c++} -c ${CXXFLAGS} ${LIBCXXFLAGS} "${ABS_LIBCXX_DIR}"/src/*.cpp
543 popd
545 mkdir -p libcxxbuild/libcxxabi
546 pushd libcxxbuild/libcxxabi
547 ${CXX:-c++} -c ${CXXFLAGS} ${LIBCXXFLAGS} "${ABS_LIBCXXABI_DIR}"/src/*.cpp -I"${ABS_LIBCXXABI_DIR}/include"
548 popd
550 pushd libcxxbuild
551 ${CC:-cc} libcxx/*.o libcxxabi/*.o -o libc++.1.dylib -dynamiclib \
552 -nodefaultlibs -current_version 1 -compatibility_version 1 \
553 -lSystem -install_name @executable_path/libc++.dylib \
554 -Wl,-unexported_symbols_list,${ABS_LIBCXX_DIR}/lib/libc++unexp.exp \
555 -Wl,-force_symbols_not_weak_list,${ABS_LIBCXX_DIR}/lib/notweak.exp \
556 -Wl,-force_symbols_weak_list,${ABS_LIBCXX_DIR}/lib/weak.exp
557 ln -sf libc++.1.dylib libc++.dylib
558 popd
559 LDFLAGS+="-stdlib=libc++ -L${PWD}/libcxxbuild"
562 # Find the binutils include dir for the gold plugin.
563 BINUTILS_INCDIR=""
564 if [ "${OS}" = "Linux" ]; then
565 BINUTILS_INCDIR="${ABS_BINUTILS_DIR}/Linux_x64/Release/include"
569 # If building at head, define a macro that plugins can use for #ifdefing
570 # out code that builds at head, but not at CLANG_REVISION or vice versa.
571 if [[ -n ${LLVM_FORCE_HEAD_REVISION:-''} ]]; then
572 CFLAGS="${CFLAGS} -DLLVM_FORCE_HEAD_REVISION"
573 CXXFLAGS="${CXXFLAGS} -DLLVM_FORCE_HEAD_REVISION"
576 # Hook the Chromium tools into the LLVM build. Several Chromium tools have
577 # dependencies on LLVM/Clang libraries. The LLVM build detects implicit tools
578 # in the tools subdirectory, so install a shim CMakeLists.txt that forwards to
579 # the real directory for the Chromium tools.
580 # Note that the shim directory name intentionally has no _ or _. The implicit
581 # tool detection logic munges them in a weird way.
582 mkdir -v ${CHROME_TOOLS_SHIM_DIR}
583 cat > ${CHROME_TOOLS_SHIM_DIR}/CMakeLists.txt << EOF
584 # Since tools/clang isn't actually a subdirectory, use the two argument version
585 # to specify where build artifacts go. CMake doesn't allow reusing the same
586 # binary dir for multiple source dirs, so the build artifacts have to go into a
587 # subdirectory...
588 add_subdirectory(\${CHROMIUM_TOOLS_SRC} \${CMAKE_CURRENT_BINARY_DIR}/a)
590 rm -fv CMakeCache.txt
591 MACOSX_DEPLOYMENT_TARGET=${deployment_target} cmake -GNinja \
592 -DCMAKE_BUILD_TYPE=Release \
593 -DLLVM_ENABLE_ASSERTIONS=ON \
594 -DLLVM_ENABLE_THREADS=OFF \
595 -DLLVM_BINUTILS_INCDIR="${BINUTILS_INCDIR}" \
596 -DCMAKE_C_COMPILER="${CC}" \
597 -DCMAKE_CXX_COMPILER="${CXX}" \
598 -DCMAKE_C_FLAGS="${CFLAGS}" \
599 -DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
600 -DCMAKE_EXE_LINKER_FLAGS="${LDFLAGS}" \
601 -DCMAKE_SHARED_LINKER_FLAGS="${LDFLAGS}" \
602 -DCMAKE_MODULE_LINKER_FLAGS="${LDFLAGS}" \
603 -DCMAKE_INSTALL_PREFIX="${ABS_LLVM_BUILD_DIR}" \
604 -DCHROMIUM_TOOLS_SRC="${ABS_CHROMIUM_TOOLS_DIR}" \
605 -DCHROMIUM_TOOLS="${chrome_tools}" \
606 "${ABS_LLVM_DIR}"
609 if [[ -n "${gcc_toolchain}" ]]; then
610 # Copy in the right stdlibc++.so.6 so clang can start.
611 mkdir -p lib
612 cp -v "$(${CXX} ${CXXFLAGS} -print-file-name=libstdc++.so.6)" lib/
615 ninja
616 # If any Chromium tools were built, install those now.
617 if [[ -n "${chrome_tools}" ]]; then
618 ninja cr-install
621 STRIP_FLAGS=
622 if [ "${OS}" = "Darwin" ]; then
623 # See http://crbug.com/256342
624 STRIP_FLAGS=-x
626 cp libcxxbuild/libc++.1.dylib bin/
628 strip ${STRIP_FLAGS} bin/clang
629 popd
631 # Build compiler-rt out-of-tree.
632 mkdir -p "${COMPILER_RT_BUILD_DIR}"
633 pushd "${COMPILER_RT_BUILD_DIR}"
635 rm -fv CMakeCache.txt
636 MACOSX_DEPLOYMENT_TARGET=${deployment_target} cmake -GNinja \
637 -DCMAKE_BUILD_TYPE=Release \
638 -DLLVM_ENABLE_ASSERTIONS=ON \
639 -DLLVM_ENABLE_THREADS=OFF \
640 -DCMAKE_C_COMPILER="${CC}" \
641 -DCMAKE_CXX_COMPILER="${CXX}" \
642 -DLLVM_CONFIG_PATH="${ABS_LLVM_BUILD_DIR}/bin/llvm-config" \
643 "${ABS_COMPILER_RT_DIR}"
645 ninja
647 # Copy selected output to the main tree.
648 # Darwin doesn't support cp --parents, so pipe through tar instead.
649 CLANG_VERSION=$("${ABS_LLVM_BUILD_DIR}/bin/clang" --version | \
650 sed -ne 's/clang version \([0-9]\.[0-9]\.[0-9]\).*/\1/p')
651 ABS_LLVM_CLANG_LIB_DIR="${ABS_LLVM_BUILD_DIR}/lib/clang/${CLANG_VERSION}"
652 tar -c *blacklist.txt | tar -C ${ABS_LLVM_CLANG_LIB_DIR} -xv
653 tar -c include/sanitizer | tar -C ${ABS_LLVM_CLANG_LIB_DIR} -xv
654 if [[ "${OS}" = "Darwin" ]]; then
655 tar -c lib/darwin | tar -C ${ABS_LLVM_CLANG_LIB_DIR} -xv
656 else
657 tar -c lib/linux | tar -C ${ABS_LLVM_CLANG_LIB_DIR} -xv
660 popd
662 if [[ -n "${with_android}" ]]; then
663 # Make a standalone Android toolchain.
664 ${ANDROID_NDK_DIR}/build/tools/make-standalone-toolchain.sh \
665 --platform=android-14 \
666 --install-dir="${LLVM_BUILD_DIR}/android-toolchain" \
667 --system=linux-x86_64 \
668 --stl=libcxx \
669 --toolchain=arm-linux-androideabi-4.9
671 # Android NDK r9d copies a broken unwind.h into the toolchain, see
672 # http://crbug.com/357890
673 rm -v "${LLVM_BUILD_DIR}"/android-toolchain/include/c++/*/unwind.h
675 # Build ASan runtime for Android in a separate build tree.
676 mkdir -p ${LLVM_BUILD_DIR}/android
677 pushd ${LLVM_BUILD_DIR}/android
678 rm -fv CMakeCache.txt
679 MACOSX_DEPLOYMENT_TARGET=${deployment_target} cmake -GNinja \
680 -DCMAKE_BUILD_TYPE=Release \
681 -DLLVM_ENABLE_ASSERTIONS=ON \
682 -DLLVM_ENABLE_THREADS=OFF \
683 -DCMAKE_C_COMPILER=${PWD}/../bin/clang \
684 -DCMAKE_CXX_COMPILER=${PWD}/../bin/clang++ \
685 -DLLVM_CONFIG_PATH=${PWD}/../bin/llvm-config \
686 -DCMAKE_C_FLAGS="--target=arm-linux-androideabi --sysroot=${PWD}/../android-toolchain/sysroot -B${PWD}/../android-toolchain" \
687 -DCMAKE_CXX_FLAGS="--target=arm-linux-androideabi --sysroot=${PWD}/../android-toolchain/sysroot -B${PWD}/../android-toolchain" \
688 -DANDROID=1 \
689 "${ABS_COMPILER_RT_DIR}"
690 ninja libclang_rt.asan-arm-android.so
692 # And copy it into the main build tree.
693 cp "$(find -name libclang_rt.asan-arm-android.so)" "${ABS_LLVM_CLANG_LIB_DIR}/lib/linux/"
694 popd
697 if [[ -n "$run_tests" ]]; then
698 # Run Chrome tool tests.
699 ninja -C "${LLVM_BUILD_DIR}" cr-check-all
700 # Run the LLVM and Clang tests.
701 ninja -C "${LLVM_BUILD_DIR}" check-all
704 # After everything is done, log success for this revision.
705 echo "${PACKAGE_VERSION}" > "${STAMP_FILE}"