| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """This script is used to download prebuilt clang binaries. | 6 """This script is used to download prebuilt clang binaries. |
| 7 | 7 |
| 8 It is also used by package.py to build the prebuilt clang binaries.""" | 8 It is also used by package.py to build the prebuilt clang binaries.""" |
| 9 | 9 |
| 10 import argparse | 10 import argparse |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 COMPILER_RT_DIR = os.path.join(LLVM_DIR, 'compiler-rt') | 62 COMPILER_RT_DIR = os.path.join(LLVM_DIR, 'compiler-rt') |
| 63 LIBCXX_DIR = os.path.join(LLVM_DIR, 'projects', 'libcxx') | 63 LIBCXX_DIR = os.path.join(LLVM_DIR, 'projects', 'libcxx') |
| 64 LIBCXXABI_DIR = os.path.join(LLVM_DIR, 'projects', 'libcxxabi') | 64 LIBCXXABI_DIR = os.path.join(LLVM_DIR, 'projects', 'libcxxabi') |
| 65 LLVM_BUILD_TOOLS_DIR = os.path.abspath( | 65 LLVM_BUILD_TOOLS_DIR = os.path.abspath( |
| 66 os.path.join(LLVM_DIR, '..', 'llvm-build-tools')) | 66 os.path.join(LLVM_DIR, '..', 'llvm-build-tools')) |
| 67 STAMP_FILE = os.path.normpath( | 67 STAMP_FILE = os.path.normpath( |
| 68 os.path.join(LLVM_DIR, '..', 'llvm-build', 'cr_build_revision')) | 68 os.path.join(LLVM_DIR, '..', 'llvm-build', 'cr_build_revision')) |
| 69 BINUTILS_DIR = os.path.join(THIRD_PARTY_DIR, 'binutils') | 69 BINUTILS_DIR = os.path.join(THIRD_PARTY_DIR, 'binutils') |
| 70 BINUTILS_BIN_DIR = os.path.join(BINUTILS_DIR, BINUTILS_DIR, | 70 BINUTILS_BIN_DIR = os.path.join(BINUTILS_DIR, BINUTILS_DIR, |
| 71 'Linux_x64', 'Release', 'bin') | 71 'Linux_x64', 'Release', 'bin') |
| 72 BFD_PLUGINS_DIR = os.path.join(BINUTILS_DIR, 'Linux_x64', 'Release', | |
| 73 'lib', 'bfd-plugins') | |
| 74 VERSION = '4.0.0' | 72 VERSION = '4.0.0' |
| 75 ANDROID_NDK_DIR = os.path.join( | 73 ANDROID_NDK_DIR = os.path.join( |
| 76 CHROMIUM_DIR, 'third_party', 'android_tools', 'ndk') | 74 CHROMIUM_DIR, 'third_party', 'android_tools', 'ndk') |
| 77 | 75 |
| 78 # URL for pre-built binaries. | 76 # URL for pre-built binaries. |
| 79 CDS_URL = os.environ.get('CDS_CLANG_BUCKET_OVERRIDE', | 77 CDS_URL = os.environ.get('CDS_CLANG_BUCKET_OVERRIDE', |
| 80 'https://commondatastorage.googleapis.com/chromium-browser-clang') | 78 'https://commondatastorage.googleapis.com/chromium-browser-clang') |
| 81 | 79 |
| 82 LLVM_REPO_URL='https://llvm.org/svn/llvm-project' | 80 LLVM_REPO_URL='https://llvm.org/svn/llvm-project' |
| 83 if 'LLVM_REPO_URL' in os.environ: | 81 if 'LLVM_REPO_URL' in os.environ: |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 | 548 |
| 551 # Build LLVM gold plugin with LTO. That speeds up the linker by ~10%. | 549 # Build LLVM gold plugin with LTO. That speeds up the linker by ~10%. |
| 552 # We only use LTO for Linux now. | 550 # We only use LTO for Linux now. |
| 553 if args.bootstrap and args.lto_gold_plugin: | 551 if args.bootstrap and args.lto_gold_plugin: |
| 554 print 'Building LTO LLVM Gold plugin' | 552 print 'Building LTO LLVM Gold plugin' |
| 555 if os.path.exists(LLVM_LTO_GOLD_PLUGIN_DIR): | 553 if os.path.exists(LLVM_LTO_GOLD_PLUGIN_DIR): |
| 556 RmTree(LLVM_LTO_GOLD_PLUGIN_DIR) | 554 RmTree(LLVM_LTO_GOLD_PLUGIN_DIR) |
| 557 EnsureDirExists(LLVM_LTO_GOLD_PLUGIN_DIR) | 555 EnsureDirExists(LLVM_LTO_GOLD_PLUGIN_DIR) |
| 558 os.chdir(LLVM_LTO_GOLD_PLUGIN_DIR) | 556 os.chdir(LLVM_LTO_GOLD_PLUGIN_DIR) |
| 559 | 557 |
| 560 # Create a symlink to LLVMgold.so build in the previous step so that ar | |
| 561 # and ranlib could find it while linking LLVMgold.so with LTO. | |
| 562 EnsureDirExists(BFD_PLUGINS_DIR) | |
| 563 RunCommand(['ln', '-sf', | |
| 564 os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'lib', 'LLVMgold.so'), | |
| 565 os.path.join(BFD_PLUGINS_DIR, 'LLVMgold.so')]) | |
| 566 | |
| 567 lto_cflags = ['-flto'] | 558 lto_cflags = ['-flto'] |
| 568 lto_ldflags = ['-fuse-ld=gold'] | 559 lto_ldflags = ['-fuse-ld=lld'] |
| 569 if args.gcc_toolchain: | 560 if args.gcc_toolchain: |
| 570 # Tell the bootstrap compiler to use a specific gcc prefix to search | 561 # Tell the bootstrap compiler to use a specific gcc prefix to search |
| 571 # for standard library headers and shared object files. | 562 # for standard library headers and shared object files. |
| 572 lto_cflags += ['--gcc-toolchain=' + args.gcc_toolchain] | 563 lto_cflags += ['--gcc-toolchain=' + args.gcc_toolchain] |
| 573 lto_cmake_args = base_cmake_args + [ | 564 lto_cmake_args = base_cmake_args + [ |
| 574 '-DLLVM_BINUTILS_INCDIR=' + binutils_incdir, | 565 '-DLLVM_BINUTILS_INCDIR=' + binutils_incdir, |
| 566 '-DCMAKE_AR=' + os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, |
| 567 'bin', 'llvm-ar'), |
| 568 '-DCMAKE_RANLIB=' + os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, |
| 569 'bin', 'llvm-ranlib'), |
| 570 '-DLLVM_ENABLE_LTO=ON', |
| 575 '-DCMAKE_C_COMPILER=' + cc, | 571 '-DCMAKE_C_COMPILER=' + cc, |
| 576 '-DCMAKE_CXX_COMPILER=' + cxx, | 572 '-DCMAKE_CXX_COMPILER=' + cxx, |
| 577 '-DCMAKE_C_FLAGS=' + ' '.join(lto_cflags), | 573 '-DCMAKE_C_FLAGS=' + ' '.join(lto_cflags), |
| 578 '-DCMAKE_CXX_FLAGS=' + ' '.join(lto_cflags), | 574 '-DCMAKE_CXX_FLAGS=' + ' '.join(lto_cflags + ['-std=c++11']), |
| 579 '-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(lto_ldflags), | 575 '-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(lto_ldflags), |
| 580 '-DCMAKE_SHARED_LINKER_FLAGS=' + ' '.join(lto_ldflags), | 576 '-DCMAKE_SHARED_LINKER_FLAGS=' + ' '.join(lto_ldflags), |
| 581 '-DCMAKE_MODULE_LINKER_FLAGS=' + ' '.join(lto_ldflags)] | 577 '-DCMAKE_MODULE_LINKER_FLAGS=' + ' '.join(lto_ldflags)] |
| 582 | 578 |
| 583 # We need to use the proper binutils which support LLVM Gold plugin. | |
| 584 lto_env = os.environ.copy() | |
| 585 lto_env['PATH'] = BINUTILS_BIN_DIR + os.pathsep + lto_env.get('PATH', '') | |
| 586 | |
| 587 RmCmakeCache('.') | 579 RmCmakeCache('.') |
| 588 RunCommand(['cmake'] + lto_cmake_args + [LLVM_DIR], env=lto_env) | 580 RunCommand(['cmake'] + lto_cmake_args + [LLVM_DIR]) |
| 589 RunCommand(['ninja', 'LLVMgold'], env=lto_env) | 581 RunCommand(['ninja', 'LLVMgold']) |
| 590 | 582 |
| 591 | 583 |
| 592 # LLVM uses C++11 starting in llvm 3.5. On Linux, this means libstdc++4.7+ is | 584 # LLVM uses C++11 starting in llvm 3.5. On Linux, this means libstdc++4.7+ is |
| 593 # needed, on OS X it requires libc++. clang only automatically links to libc++ | 585 # needed, on OS X it requires libc++. clang only automatically links to libc++ |
| 594 # when targeting OS X 10.9+, so add stdlib=libc++ explicitly so clang can run | 586 # when targeting OS X 10.9+, so add stdlib=libc++ explicitly so clang can run |
| 595 # on OS X versions as old as 10.7. | 587 # on OS X versions as old as 10.7. |
| 596 deployment_target = '' | 588 deployment_target = '' |
| 597 | 589 |
| 598 if sys.platform == 'darwin' and args.bootstrap: | 590 if sys.platform == 'darwin' and args.bootstrap: |
| 599 # When building on 10.9, /usr/include usually doesn't exist, and while | 591 # When building on 10.9, /usr/include usually doesn't exist, and while |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 args.force_local_build = True | 895 args.force_local_build = True |
| 904 if 'OS=android' not in os.environ.get('GYP_DEFINES', ''): | 896 if 'OS=android' not in os.environ.get('GYP_DEFINES', ''): |
| 905 # Only build the Android ASan rt on ToT bots when targetting Android. | 897 # Only build the Android ASan rt on ToT bots when targetting Android. |
| 906 args.with_android = False | 898 args.with_android = False |
| 907 | 899 |
| 908 return UpdateClang(args) | 900 return UpdateClang(args) |
| 909 | 901 |
| 910 | 902 |
| 911 if __name__ == '__main__': | 903 if __name__ == '__main__': |
| 912 sys.exit(main()) | 904 sys.exit(main()) |
| OLD | NEW |