Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: tools/clang/scripts/update.py

Issue 2572833003: Clang toolchain: checkout LLD on all platforms but Darwin. (Closed)
Patch Set: Add llvm-ar and lld into the distribution Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 451
452 DownloadHostGcc(args) 452 DownloadHostGcc(args)
453 AddSvnToPathOnWin() 453 AddSvnToPathOnWin()
454 AddCMakeToPath() 454 AddCMakeToPath()
455 AddGnuWinToPath() 455 AddGnuWinToPath()
456 456
457 DeleteChromeToolsShim() 457 DeleteChromeToolsShim()
458 458
459 Checkout('LLVM', LLVM_REPO_URL + '/llvm/trunk', LLVM_DIR) 459 Checkout('LLVM', LLVM_REPO_URL + '/llvm/trunk', LLVM_DIR)
460 Checkout('Clang', LLVM_REPO_URL + '/cfe/trunk', CLANG_DIR) 460 Checkout('Clang', LLVM_REPO_URL + '/cfe/trunk', CLANG_DIR)
461 if sys.platform == 'win32' or use_head_revision: 461 if sys.platform != 'darwin':
462 Checkout('LLD', LLVM_REPO_URL + '/lld/trunk', LLD_DIR) 462 Checkout('LLD', LLVM_REPO_URL + '/lld/trunk', LLD_DIR)
463 elif os.path.exists(LLD_DIR): 463 elif os.path.exists(LLD_DIR):
464 # In case someone sends a tryjob that temporary adds lld to the checkout, 464 # In case someone sends a tryjob that temporary adds lld to the checkout,
465 # make sure it's not around on future builds. 465 # make sure it's not around on future builds.
466 RmTree(LLD_DIR) 466 RmTree(LLD_DIR)
467 Checkout('compiler-rt', LLVM_REPO_URL + '/compiler-rt/trunk', COMPILER_RT_DIR) 467 Checkout('compiler-rt', LLVM_REPO_URL + '/compiler-rt/trunk', COMPILER_RT_DIR)
468 if sys.platform == 'darwin': 468 if sys.platform == 'darwin':
469 # clang needs a libc++ checkout, else -stdlib=libc++ won't find includes 469 # clang needs a libc++ checkout, else -stdlib=libc++ won't find includes
470 # (i.e. this is needed for bootstrap builds). 470 # (i.e. this is needed for bootstrap builds).
471 Checkout('libcxx', LLVM_REPO_URL + '/libcxx/trunk', LIBCXX_DIR) 471 Checkout('libcxx', LLVM_REPO_URL + '/libcxx/trunk', LIBCXX_DIR)
(...skipping 19 matching lines...) Expand all
491 [cxx, '-print-file-name=libstdc++.so.6']).rstrip() 491 [cxx, '-print-file-name=libstdc++.so.6']).rstrip()
492 os.environ['LD_LIBRARY_PATH'] = os.path.dirname(libstdcpp) 492 os.environ['LD_LIBRARY_PATH'] = os.path.dirname(libstdcpp)
493 493
494 cflags = [] 494 cflags = []
495 cxxflags = [] 495 cxxflags = []
496 ldflags = [] 496 ldflags = []
497 497
498 base_cmake_args = ['-GNinja', 498 base_cmake_args = ['-GNinja',
499 '-DCMAKE_BUILD_TYPE=Release', 499 '-DCMAKE_BUILD_TYPE=Release',
500 '-DLLVM_ENABLE_ASSERTIONS=ON', 500 '-DLLVM_ENABLE_ASSERTIONS=ON',
501 '-DLLVM_ENABLE_THREADS=OFF',
502 # Statically link MSVCRT to avoid DLL dependencies. 501 # Statically link MSVCRT to avoid DLL dependencies.
503 '-DLLVM_USE_CRT_RELEASE=MT', 502 '-DLLVM_USE_CRT_RELEASE=MT',
504 ] 503 ]
505 504
506 binutils_incdir = '' 505 binutils_incdir = ''
507 if sys.platform.startswith('linux'): 506 if sys.platform.startswith('linux'):
508 binutils_incdir = os.path.join(BINUTILS_DIR, 'Linux_x64/Release/include') 507 binutils_incdir = os.path.join(BINUTILS_DIR, 'Linux_x64/Release/include')
509 508
510 if args.bootstrap: 509 if args.bootstrap:
511 print 'Building bootstrap compiler' 510 print 'Building bootstrap compiler'
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 EnsureDirExists(LLVM_LTO_GOLD_PLUGIN_DIR) 559 EnsureDirExists(LLVM_LTO_GOLD_PLUGIN_DIR)
561 os.chdir(LLVM_LTO_GOLD_PLUGIN_DIR) 560 os.chdir(LLVM_LTO_GOLD_PLUGIN_DIR)
562 561
563 # Create a symlink to LLVMgold.so build in the previous step so that ar 562 # Create a symlink to LLVMgold.so build in the previous step so that ar
564 # and ranlib could find it while linking LLVMgold.so with LTO. 563 # and ranlib could find it while linking LLVMgold.so with LTO.
565 EnsureDirExists(BFD_PLUGINS_DIR) 564 EnsureDirExists(BFD_PLUGINS_DIR)
566 RunCommand(['ln', '-sf', 565 RunCommand(['ln', '-sf',
567 os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'lib', 'LLVMgold.so'), 566 os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'lib', 'LLVMgold.so'),
568 os.path.join(BFD_PLUGINS_DIR, 'LLVMgold.so')]) 567 os.path.join(BFD_PLUGINS_DIR, 'LLVMgold.so')])
569 568
570 lto_cflags = ['-flto'] 569 lto_cflags = ['-flto=thin']
571 lto_ldflags = ['-fuse-ld=gold'] 570 lto_ldflags = ['-fuse-ld=lld']
572 if args.gcc_toolchain: 571 if args.gcc_toolchain:
573 # Tell the bootstrap compiler to use a specific gcc prefix to search 572 # Tell the bootstrap compiler to use a specific gcc prefix to search
574 # for standard library headers and shared object files. 573 # for standard library headers and shared object files.
575 lto_cflags += ['--gcc-toolchain=' + args.gcc_toolchain] 574 lto_cflags += ['--gcc-toolchain=' + args.gcc_toolchain]
576 lto_cmake_args = base_cmake_args + [ 575 lto_cmake_args = base_cmake_args + [
577 '-DLLVM_BINUTILS_INCDIR=' + binutils_incdir, 576 '-DLLVM_BINUTILS_INCDIR=' + binutils_incdir,
578 '-DCMAKE_C_COMPILER=' + cc, 577 '-DCMAKE_C_COMPILER=' + cc,
579 '-DCMAKE_CXX_COMPILER=' + cxx, 578 '-DCMAKE_CXX_COMPILER=' + cxx,
580 '-DCMAKE_C_FLAGS=' + ' '.join(lto_cflags), 579 '-DCMAKE_C_FLAGS=' + ' '.join(lto_cflags),
581 '-DCMAKE_CXX_FLAGS=' + ' '.join(lto_cflags), 580 '-DCMAKE_CXX_FLAGS=' + ' '.join(lto_cflags),
582 '-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(lto_ldflags), 581 '-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(lto_ldflags),
583 '-DCMAKE_SHARED_LINKER_FLAGS=' + ' '.join(lto_ldflags), 582 '-DCMAKE_SHARED_LINKER_FLAGS=' + ' '.join(lto_ldflags),
584 '-DCMAKE_MODULE_LINKER_FLAGS=' + ' '.join(lto_ldflags)] 583 '-DCMAKE_MODULE_LINKER_FLAGS=' + ' '.join(lto_ldflags)]
585 584
586 # We need to use the proper binutils which support LLVM Gold plugin. 585 # We need to use the proper binutils which support LLVM Gold plugin.
587 lto_env = os.environ.copy() 586 lto_env = os.environ.copy()
588 lto_env['PATH'] = BINUTILS_BIN_DIR + os.pathsep + lto_env.get('PATH', '') 587 lto_env['PATH'] = BINUTILS_BIN_DIR + os.pathsep + lto_env.get('PATH', '')
589 588
590 RmCmakeCache('.') 589 RmCmakeCache('.')
591 RunCommand(['cmake'] + lto_cmake_args + [LLVM_DIR], env=lto_env) 590 RunCommand(['cmake'] + lto_cmake_args + [LLVM_DIR], env=lto_env)
592 RunCommand(['ninja', 'LLVMgold'], env=lto_env) 591 RunCommand(['ninja', 'LLVMgold', 'lld'], env=lto_env)
593 592
594 593
595 # LLVM uses C++11 starting in llvm 3.5. On Linux, this means libstdc++4.7+ is 594 # LLVM uses C++11 starting in llvm 3.5. On Linux, this means libstdc++4.7+ is
596 # needed, on OS X it requires libc++. clang only automatically links to libc++ 595 # needed, on OS X it requires libc++. clang only automatically links to libc++
597 # when targeting OS X 10.9+, so add stdlib=libc++ explicitly so clang can run 596 # when targeting OS X 10.9+, so add stdlib=libc++ explicitly so clang can run
598 # on OS X versions as old as 10.7. 597 # on OS X versions as old as 10.7.
599 deployment_target = '' 598 deployment_target = ''
600 599
601 if sys.platform == 'darwin' and args.bootstrap: 600 if sys.platform == 'darwin' and args.bootstrap:
602 # When building on 10.9, /usr/include usually doesn't exist, and while 601 # When building on 10.9, /usr/include usually doesn't exist, and while
(...skipping 24 matching lines...) Expand all
627 deployment_env['MACOSX_DEPLOYMENT_TARGET'] = deployment_target 626 deployment_env['MACOSX_DEPLOYMENT_TARGET'] = deployment_target
628 627
629 cmake_args = [] 628 cmake_args = []
630 # TODO(thakis): Unconditionally append this to base_cmake_args instead once 629 # TODO(thakis): Unconditionally append this to base_cmake_args instead once
631 # compiler-rt can build with clang-cl on Windows (http://llvm.org/PR23698) 630 # compiler-rt can build with clang-cl on Windows (http://llvm.org/PR23698)
632 cc_args = base_cmake_args if sys.platform != 'win32' else cmake_args 631 cc_args = base_cmake_args if sys.platform != 'win32' else cmake_args
633 if cc is not None: cc_args.append('-DCMAKE_C_COMPILER=' + cc) 632 if cc is not None: cc_args.append('-DCMAKE_C_COMPILER=' + cc)
634 if cxx is not None: cc_args.append('-DCMAKE_CXX_COMPILER=' + cxx) 633 if cxx is not None: cc_args.append('-DCMAKE_CXX_COMPILER=' + cxx)
635 chrome_tools = list(set(['plugins', 'blink_gc_plugin'] + args.extra_tools)) 634 chrome_tools = list(set(['plugins', 'blink_gc_plugin'] + args.extra_tools))
636 cmake_args += base_cmake_args + [ 635 cmake_args += base_cmake_args + [
636 '-DLLVM_ENABLE_THREADS=OFF',
637 '-DLLVM_BINUTILS_INCDIR=' + binutils_incdir, 637 '-DLLVM_BINUTILS_INCDIR=' + binutils_incdir,
638 '-DCMAKE_C_FLAGS=' + ' '.join(cflags), 638 '-DCMAKE_C_FLAGS=' + ' '.join(cflags),
639 '-DCMAKE_CXX_FLAGS=' + ' '.join(cxxflags), 639 '-DCMAKE_CXX_FLAGS=' + ' '.join(cxxflags),
640 '-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(ldflags), 640 '-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(ldflags),
641 '-DCMAKE_SHARED_LINKER_FLAGS=' + ' '.join(ldflags), 641 '-DCMAKE_SHARED_LINKER_FLAGS=' + ' '.join(ldflags),
642 '-DCMAKE_MODULE_LINKER_FLAGS=' + ' '.join(ldflags), 642 '-DCMAKE_MODULE_LINKER_FLAGS=' + ' '.join(ldflags),
643 '-DCMAKE_INSTALL_PREFIX=' + LLVM_BUILD_DIR, 643 '-DCMAKE_INSTALL_PREFIX=' + LLVM_BUILD_DIR,
644 # TODO(thakis): Remove this once official builds pass -Wl,--build-id 644 # TODO(thakis): Remove this once official builds pass -Wl,--build-id
645 # explicitly, https://crbug.com/622775 645 # explicitly, https://crbug.com/622775
646 '-DENABLE_LINKER_BUILD_ID=ON', 646 '-DENABLE_LINKER_BUILD_ID=ON',
647 '-DCHROMIUM_TOOLS_SRC=%s' % os.path.join(CHROMIUM_DIR, 'tools', 'clang'), 647 '-DCHROMIUM_TOOLS_SRC=%s' % os.path.join(CHROMIUM_DIR, 'tools', 'clang'),
648 '-DCHROMIUM_TOOLS=%s' % ';'.join(chrome_tools)] 648 '-DCHROMIUM_TOOLS=%s' % ';'.join(chrome_tools)]
649 649
650 EnsureDirExists(LLVM_BUILD_DIR) 650 EnsureDirExists(LLVM_BUILD_DIR)
651 os.chdir(LLVM_BUILD_DIR) 651 os.chdir(LLVM_BUILD_DIR)
652 RmCmakeCache('.') 652 RmCmakeCache('.')
653 RunCommand(['cmake'] + cmake_args + [LLVM_DIR], 653 RunCommand(['cmake'] + cmake_args + [LLVM_DIR],
654 msvc_arch='x64', env=deployment_env) 654 msvc_arch='x64', env=deployment_env)
655 655
656 if args.gcc_toolchain: 656 if args.gcc_toolchain:
657 # Copy in the right stdlibc++.so.6 so clang can start. 657 # Copy in the right stdlibc++.so.6 so clang can start.
658 if not os.path.exists(os.path.join(LLVM_BUILD_DIR, 'lib')): 658 if not os.path.exists(os.path.join(LLVM_BUILD_DIR, 'lib')):
659 os.mkdir(os.path.join(LLVM_BUILD_DIR, 'lib')) 659 os.mkdir(os.path.join(LLVM_BUILD_DIR, 'lib'))
660 libstdcpp = subprocess.check_output( 660 libstdcpp = subprocess.check_output(
661 [cxx] + cxxflags + ['-print-file-name=libstdc++.so.6']).rstrip() 661 [cxx] + cxxflags + ['-print-file-name=libstdc++.so.6']).rstrip()
662 CopyFile(libstdcpp, os.path.join(LLVM_BUILD_DIR, 'lib')) 662 CopyFile(libstdcpp, os.path.join(LLVM_BUILD_DIR, 'lib'))
663 663
664 RunCommand(['ninja'], msvc_arch='x64') 664 RunCommand(['ninja'], msvc_arch='x64')
665 665
666 # Copy LTO-optimized lld, if any.
667 if args.bootstrap and args.lto_gold_plugin:
668 CopyFile(os.path.join(LLVM_LTO_GOLD_PLUGIN_DIR, 'bin', 'lld'),
669 os.path.join(LLVM_BUILD_DIR, 'bin'))
670
666 if chrome_tools: 671 if chrome_tools:
667 # If any Chromium tools were built, install those now. 672 # If any Chromium tools were built, install those now.
668 RunCommand(['ninja', 'cr-install'], msvc_arch='x64') 673 RunCommand(['ninja', 'cr-install'], msvc_arch='x64')
669 674
670 if sys.platform == 'darwin': 675 if sys.platform == 'darwin':
671 # See http://crbug.com/256342 676 # See http://crbug.com/256342
672 RunCommand(['strip', '-x', os.path.join(LLVM_BUILD_DIR, 'bin', 'clang')]) 677 RunCommand(['strip', '-x', os.path.join(LLVM_BUILD_DIR, 'bin', 'clang')])
673 elif sys.platform.startswith('linux'): 678 elif sys.platform.startswith('linux'):
674 RunCommand(['strip', os.path.join(LLVM_BUILD_DIR, 'bin', 'clang')]) 679 RunCommand(['strip', os.path.join(LLVM_BUILD_DIR, 'bin', 'clang')])
675 680
676 VeryifyVersionOfBuiltClangMatchesVERSION() 681 VeryifyVersionOfBuiltClangMatchesVERSION()
677 682
678 # Do an out-of-tree build of compiler-rt. 683 # Do an out-of-tree build of compiler-rt.
679 # On Windows, this is used to get the 32-bit ASan run-time. 684 # On Windows, this is used to get the 32-bit ASan run-time.
680 # TODO(hans): Remove once the regular build above produces this. 685 # TODO(hans): Remove once the regular build above produces this.
681 # On Mac and Linux, this is used to get the regular 64-bit run-time. 686 # On Mac and Linux, this is used to get the regular 64-bit run-time.
682 # Do a clobbered build due to cmake changes. 687 # Do a clobbered build due to cmake changes.
683 if os.path.isdir(COMPILER_RT_BUILD_DIR): 688 if os.path.isdir(COMPILER_RT_BUILD_DIR):
684 RmTree(COMPILER_RT_BUILD_DIR) 689 RmTree(COMPILER_RT_BUILD_DIR)
685 os.makedirs(COMPILER_RT_BUILD_DIR) 690 os.makedirs(COMPILER_RT_BUILD_DIR)
686 os.chdir(COMPILER_RT_BUILD_DIR) 691 os.chdir(COMPILER_RT_BUILD_DIR)
687 # TODO(thakis): Add this once compiler-rt can build with clang-cl (see 692 # TODO(thakis): Add this once compiler-rt can build with clang-cl (see
688 # above). 693 # above).
689 #if args.bootstrap and sys.platform == 'win32': 694 #if args.bootstrap and sys.platform == 'win32':
690 # The bootstrap compiler produces 64-bit binaries by default. 695 # The bootstrap compiler produces 64-bit binaries by default.
691 #cflags += ['-m32'] 696 #cflags += ['-m32']
692 #cxxflags += ['-m32'] 697 #cxxflags += ['-m32']
693 compiler_rt_args = base_cmake_args + [ 698 compiler_rt_args = base_cmake_args + [
699 '-DLLVM_ENABLE_THREADS=OFF',
694 '-DCMAKE_C_FLAGS=' + ' '.join(cflags), 700 '-DCMAKE_C_FLAGS=' + ' '.join(cflags),
695 '-DCMAKE_CXX_FLAGS=' + ' '.join(cxxflags)] 701 '-DCMAKE_CXX_FLAGS=' + ' '.join(cxxflags)]
696 if sys.platform == 'darwin': 702 if sys.platform == 'darwin':
697 compiler_rt_args += ['-DCOMPILER_RT_ENABLE_IOS=ON'] 703 compiler_rt_args += ['-DCOMPILER_RT_ENABLE_IOS=ON']
698 if sys.platform != 'win32': 704 if sys.platform != 'win32':
699 compiler_rt_args += ['-DLLVM_CONFIG_PATH=' + 705 compiler_rt_args += ['-DLLVM_CONFIG_PATH=' +
700 os.path.join(LLVM_BUILD_DIR, 'bin', 'llvm-config'), 706 os.path.join(LLVM_BUILD_DIR, 'bin', 'llvm-config'),
701 '-DSANITIZER_MIN_OSX_VERSION="10.7"'] 707 '-DSANITIZER_MIN_OSX_VERSION="10.7"']
702 # compiler-rt is part of the llvm checkout on Windows but a stand-alone 708 # compiler-rt is part of the llvm checkout on Windows but a stand-alone
703 # directory elsewhere, see the TODO above COMPILER_RT_DIR. 709 # directory elsewhere, see the TODO above COMPILER_RT_DIR.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 792
787 # Build ASan runtime for Android in a separate build tree. 793 # Build ASan runtime for Android in a separate build tree.
788 build_dir = os.path.join(LLVM_BUILD_DIR, 'android-' + target_arch) 794 build_dir = os.path.join(LLVM_BUILD_DIR, 'android-' + target_arch)
789 if not os.path.exists(build_dir): 795 if not os.path.exists(build_dir):
790 os.mkdir(os.path.join(build_dir)) 796 os.mkdir(os.path.join(build_dir))
791 os.chdir(build_dir) 797 os.chdir(build_dir)
792 cflags = ['--target=%s-linux-androideabi' % target_arch, 798 cflags = ['--target=%s-linux-androideabi' % target_arch,
793 '--sysroot=%s/sysroot' % toolchain_dir, 799 '--sysroot=%s/sysroot' % toolchain_dir,
794 '-B%s' % toolchain_dir] 800 '-B%s' % toolchain_dir]
795 android_args = base_cmake_args + [ 801 android_args = base_cmake_args + [
802 '-DLLVM_ENABLE_THREADS=OFF',
796 '-DCMAKE_C_COMPILER=' + os.path.join(LLVM_BUILD_DIR, 'bin/clang'), 803 '-DCMAKE_C_COMPILER=' + os.path.join(LLVM_BUILD_DIR, 'bin/clang'),
797 '-DCMAKE_CXX_COMPILER=' + os.path.join(LLVM_BUILD_DIR, 'bin/clang++'), 804 '-DCMAKE_CXX_COMPILER=' + os.path.join(LLVM_BUILD_DIR, 'bin/clang++'),
798 '-DLLVM_CONFIG_PATH=' + os.path.join(LLVM_BUILD_DIR, 'bin/llvm-config'), 805 '-DLLVM_CONFIG_PATH=' + os.path.join(LLVM_BUILD_DIR, 'bin/llvm-config'),
799 '-DCMAKE_C_FLAGS=' + ' '.join(cflags), 806 '-DCMAKE_C_FLAGS=' + ' '.join(cflags),
800 '-DCMAKE_CXX_FLAGS=' + ' '.join(cflags), 807 '-DCMAKE_CXX_FLAGS=' + ' '.join(cflags),
801 '-DANDROID=1'] 808 '-DANDROID=1']
802 RmCmakeCache('.') 809 RmCmakeCache('.')
803 RunCommand(['cmake'] + android_args + [COMPILER_RT_DIR]) 810 RunCommand(['cmake'] + android_args + [COMPILER_RT_DIR])
804 RunCommand(['ninja', 'libclang_rt.asan-%s-android.so' % target_arch]) 811 RunCommand(['ninja', 'libclang_rt.asan-%s-android.so' % target_arch])
805 812
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 args.force_local_build = True 918 args.force_local_build = True
912 if 'OS=android' not in os.environ.get('GYP_DEFINES', ''): 919 if 'OS=android' not in os.environ.get('GYP_DEFINES', ''):
913 # Only build the Android ASan rt on ToT bots when targetting Android. 920 # Only build the Android ASan rt on ToT bots when targetting Android.
914 args.with_android = False 921 args.with_android = False
915 922
916 return UpdateClang(args) 923 return UpdateClang(args)
917 924
918 925
919 if __name__ == '__main__': 926 if __name__ == '__main__':
920 sys.exit(main()) 927 sys.exit(main())
OLDNEW
« tools/clang/scripts/package.py ('K') | « tools/clang/scripts/package.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698