build.py 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307
  1. #!/usr/bin/env python3
  2. # Copyright 2019 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. """This script is used to build clang binaries. It is used by package.py to
  6. create the prebuilt binaries downloaded by update.py and used by developers.
  7. The expectation is that update.py downloads prebuilt binaries for everyone, and
  8. nobody should run this script as part of normal development.
  9. """
  10. from __future__ import print_function
  11. import argparse
  12. import glob
  13. import io
  14. import json
  15. import os
  16. import pipes
  17. import platform
  18. import re
  19. import shutil
  20. import subprocess
  21. import sys
  22. import tempfile
  23. from update import (CDS_URL, CHROMIUM_DIR, CLANG_REVISION, LLVM_BUILD_DIR,
  24. FORCE_HEAD_REVISION_FILE, PACKAGE_VERSION, RELEASE_VERSION,
  25. STAMP_FILE, DownloadUrl, DownloadAndUnpack, EnsureDirExists,
  26. ReadStampFile, RmTree, WriteStampFile)
  27. # Path constants. (All of these should be absolute paths.)
  28. THIRD_PARTY_DIR = os.path.join(CHROMIUM_DIR, 'third_party')
  29. LLVM_DIR = os.path.join(THIRD_PARTY_DIR, 'llvm')
  30. COMPILER_RT_DIR = os.path.join(LLVM_DIR, 'compiler-rt')
  31. LLVM_BOOTSTRAP_DIR = os.path.join(THIRD_PARTY_DIR, 'llvm-bootstrap')
  32. LLVM_BOOTSTRAP_INSTALL_DIR = os.path.join(THIRD_PARTY_DIR,
  33. 'llvm-bootstrap-install')
  34. LLVM_INSTRUMENTED_DIR = os.path.join(THIRD_PARTY_DIR, 'llvm-instrumented')
  35. LLVM_PROFDATA_FILE = os.path.join(LLVM_INSTRUMENTED_DIR, 'profdata.prof')
  36. LLVM_BUILD_TOOLS_DIR = os.path.abspath(
  37. os.path.join(LLVM_DIR, '..', 'llvm-build-tools'))
  38. ANDROID_NDK_DIR = os.path.join(
  39. CHROMIUM_DIR, 'third_party', 'android_ndk')
  40. FUCHSIA_SDK_DIR = os.path.join(CHROMIUM_DIR, 'third_party', 'fuchsia-sdk',
  41. 'sdk')
  42. PINNED_CLANG_DIR = os.path.join(LLVM_BUILD_TOOLS_DIR, 'pinned-clang')
  43. BUG_REPORT_URL = ('https://crbug.com and run'
  44. ' tools/clang/scripts/process_crashreports.py'
  45. ' (only works inside Google) which will upload a report')
  46. win_sdk_dir = None
  47. def GetWinSDKDir():
  48. """Get the location of the current SDK."""
  49. global win_sdk_dir
  50. if win_sdk_dir:
  51. return win_sdk_dir
  52. # Don't let vs_toolchain overwrite our environment.
  53. environ_bak = os.environ
  54. sys.path.append(os.path.join(CHROMIUM_DIR, 'build'))
  55. import vs_toolchain
  56. win_sdk_dir = vs_toolchain.SetEnvironmentAndGetSDKDir()
  57. msvs_version = vs_toolchain.GetVisualStudioVersion()
  58. if bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1'))):
  59. dia_path = os.path.join(win_sdk_dir, '..', 'DIA SDK', 'bin', 'amd64')
  60. else:
  61. if 'GYP_MSVS_OVERRIDE_PATH' not in os.environ:
  62. vs_path = vs_toolchain.DetectVisualStudioPath()
  63. else:
  64. vs_path = os.environ['GYP_MSVS_OVERRIDE_PATH']
  65. dia_path = os.path.join(vs_path, 'DIA SDK', 'bin', 'amd64')
  66. os.environ = environ_bak
  67. return win_sdk_dir
  68. def RunCommand(command, msvc_arch=None, env=None, fail_hard=True):
  69. """Run command and return success (True) or failure; or if fail_hard is
  70. True, exit on failure. If msvc_arch is set, runs the command in a
  71. shell with the msvc tools for that architecture."""
  72. if msvc_arch and sys.platform == 'win32':
  73. command = [os.path.join(GetWinSDKDir(), 'bin', 'SetEnv.cmd'),
  74. "/" + msvc_arch, '&&'] + command
  75. # https://docs.python.org/2/library/subprocess.html:
  76. # "On Unix with shell=True [...] if args is a sequence, the first item
  77. # specifies the command string, and any additional items will be treated as
  78. # additional arguments to the shell itself. That is to say, Popen does the
  79. # equivalent of:
  80. # Popen(['/bin/sh', '-c', args[0], args[1], ...])"
  81. #
  82. # We want to pass additional arguments to command[0], not to the shell,
  83. # so manually join everything into a single string.
  84. # Annoyingly, for "svn co url c:\path", pipes.quote() thinks that it should
  85. # quote c:\path but svn can't handle quoted paths on Windows. Since on
  86. # Windows follow-on args are passed to args[0] instead of the shell, don't
  87. # do the single-string transformation there.
  88. if sys.platform != 'win32':
  89. command = ' '.join([pipes.quote(c) for c in command])
  90. print('Running', command)
  91. if subprocess.call(command, env=env, shell=True) == 0:
  92. return True
  93. print('Failed.')
  94. if fail_hard:
  95. sys.exit(1)
  96. return False
  97. def CopyFile(src, dst):
  98. """Copy a file from src to dst."""
  99. print("Copying %s to %s" % (src, dst))
  100. shutil.copy(src, dst)
  101. def CopyDirectoryContents(src, dst):
  102. """Copy the files from directory src to dst."""
  103. dst = os.path.realpath(dst) # realpath() in case dst ends in /..
  104. EnsureDirExists(dst)
  105. for f in os.listdir(src):
  106. CopyFile(os.path.join(src, f), dst)
  107. def CheckoutLLVM(commit, dir):
  108. """Checkout the LLVM monorepo at a certain git commit in dir. Any local
  109. modifications in dir will be lost."""
  110. print('Checking out LLVM monorepo %s into %s' % (commit, dir))
  111. # Try updating the current repo if it exists and has no local diff.
  112. if os.path.isdir(dir):
  113. os.chdir(dir)
  114. # git diff-index --quiet returns success when there is no diff.
  115. # Also check that the first commit is reachable.
  116. if (RunCommand(['git', 'diff-index', '--quiet', 'HEAD'], fail_hard=False)
  117. and RunCommand(['git', 'fetch'], fail_hard=False)
  118. and RunCommand(['git', 'checkout', commit], fail_hard=False)):
  119. return
  120. # If we can't use the current repo, delete it.
  121. os.chdir(CHROMIUM_DIR) # Can't remove dir if we're in it.
  122. print('Removing %s.' % dir)
  123. RmTree(dir)
  124. clone_cmd = ['git', 'clone', 'https://github.com/llvm/llvm-project/', dir]
  125. if RunCommand(clone_cmd, fail_hard=False):
  126. os.chdir(dir)
  127. if RunCommand(['git', 'checkout', commit], fail_hard=False):
  128. return
  129. print('CheckoutLLVM failed.')
  130. sys.exit(1)
  131. def UrlOpen(url):
  132. # TODO(crbug.com/1067752): Use urllib once certificates are fixed.
  133. return subprocess.check_output(['curl', '--silent', url],
  134. universal_newlines=True)
  135. def GetLatestLLVMCommit():
  136. """Get the latest commit hash in the LLVM monorepo."""
  137. ref = json.loads(
  138. UrlOpen(('https://api.github.com/repos/'
  139. 'llvm/llvm-project/git/refs/heads/main')))
  140. assert ref['object']['type'] == 'commit'
  141. return ref['object']['sha']
  142. def GetCommitDescription(commit):
  143. """Get the output of `git describe`.
  144. Needs to be called from inside the git repository dir."""
  145. git_exe = 'git.bat' if sys.platform.startswith('win') else 'git'
  146. return subprocess.check_output(
  147. [git_exe, 'describe', '--long', '--abbrev=8', commit],
  148. universal_newlines=True).rstrip()
  149. def DeleteChromeToolsShim():
  150. # TODO: These dirs are no longer used. Remove this code after a while.
  151. OLD_SHIM_DIR = os.path.join(LLVM_DIR, 'tools', 'zzz-chrometools')
  152. shutil.rmtree(OLD_SHIM_DIR, ignore_errors=True)
  153. CHROME_TOOLS_SHIM_DIR = os.path.join(LLVM_DIR, 'llvm', 'tools', 'chrometools')
  154. shutil.rmtree(CHROME_TOOLS_SHIM_DIR, ignore_errors=True)
  155. def AddCMakeToPath(args):
  156. """Download CMake and add it to PATH."""
  157. if args.use_system_cmake:
  158. return
  159. if sys.platform == 'win32':
  160. zip_name = 'cmake-3.23.0-windows-x86_64.zip'
  161. dir_name = ['cmake-3.23.0-windows-x86_64', 'bin']
  162. elif sys.platform == 'darwin':
  163. zip_name = 'cmake-3.23.0-macos-universal.tar.gz'
  164. dir_name = ['cmake-3.23.0-macos-universal', 'CMake.app', 'Contents', 'bin']
  165. else:
  166. zip_name = 'cmake-3.23.0-linux-x86_64.tar.gz'
  167. dir_name = ['cmake-3.23.0-linux-x86_64', 'bin']
  168. cmake_dir = os.path.join(LLVM_BUILD_TOOLS_DIR, *dir_name)
  169. if not os.path.exists(cmake_dir):
  170. DownloadAndUnpack(CDS_URL + '/tools/' + zip_name, LLVM_BUILD_TOOLS_DIR)
  171. os.environ['PATH'] = cmake_dir + os.pathsep + os.environ.get('PATH', '')
  172. def AddGnuWinToPath():
  173. """Download some GNU win tools and add them to PATH."""
  174. if sys.platform != 'win32':
  175. return
  176. gnuwin_dir = os.path.join(LLVM_BUILD_TOOLS_DIR, 'gnuwin')
  177. GNUWIN_VERSION = '14'
  178. GNUWIN_STAMP = os.path.join(gnuwin_dir, 'stamp')
  179. if ReadStampFile(GNUWIN_STAMP) == GNUWIN_VERSION:
  180. print('GNU Win tools already up to date.')
  181. else:
  182. zip_name = 'gnuwin-%s.zip' % GNUWIN_VERSION
  183. DownloadAndUnpack(CDS_URL + '/tools/' + zip_name, LLVM_BUILD_TOOLS_DIR)
  184. WriteStampFile(GNUWIN_VERSION, GNUWIN_STAMP)
  185. os.environ['PATH'] = gnuwin_dir + os.pathsep + os.environ.get('PATH', '')
  186. # find.exe, mv.exe and rm.exe are from MSYS (see crrev.com/389632). MSYS uses
  187. # Cygwin under the hood, and initializing Cygwin has a race-condition when
  188. # getting group and user data from the Active Directory is slow. To work
  189. # around this, use a horrible hack telling it not to do that.
  190. # See https://crbug.com/905289
  191. etc = os.path.join(gnuwin_dir, '..', '..', 'etc')
  192. EnsureDirExists(etc)
  193. with open(os.path.join(etc, 'nsswitch.conf'), 'w') as f:
  194. f.write('passwd: files\n')
  195. f.write('group: files\n')
  196. def AddZlibToPath():
  197. """Download and build zlib, and add to PATH."""
  198. zlib_dir = os.path.join(LLVM_BUILD_TOOLS_DIR, 'zlib-1.2.11')
  199. if os.path.exists(zlib_dir):
  200. RmTree(zlib_dir)
  201. zip_name = 'zlib-1.2.11.tar.gz'
  202. DownloadAndUnpack(CDS_URL + '/tools/' + zip_name, LLVM_BUILD_TOOLS_DIR)
  203. os.chdir(zlib_dir)
  204. zlib_files = [
  205. 'adler32', 'compress', 'crc32', 'deflate', 'gzclose', 'gzlib', 'gzread',
  206. 'gzwrite', 'inflate', 'infback', 'inftrees', 'inffast', 'trees',
  207. 'uncompr', 'zutil'
  208. ]
  209. cl_flags = [
  210. '/nologo', '/O2', '/DZLIB_DLL', '/c', '/D_CRT_SECURE_NO_DEPRECATE',
  211. '/D_CRT_NONSTDC_NO_DEPRECATE'
  212. ]
  213. RunCommand(
  214. ['cl.exe'] + [f + '.c' for f in zlib_files] + cl_flags, msvc_arch='x64')
  215. RunCommand(
  216. ['lib.exe'] + [f + '.obj'
  217. for f in zlib_files] + ['/nologo', '/out:zlib.lib'],
  218. msvc_arch='x64')
  219. # Remove the test directory so it isn't found when trying to find
  220. # test.exe.
  221. shutil.rmtree('test')
  222. os.environ['PATH'] = zlib_dir + os.pathsep + os.environ.get('PATH', '')
  223. return zlib_dir
  224. def BuildLibXml2():
  225. """Download and build libxml2"""
  226. # The .tar.gz on GCS was uploaded as follows.
  227. # The gitlab page has more up-to-date packages than http://xmlsoft.org/,
  228. # and the official releases on xmlsoft.org are only available over ftp too.
  229. # $ VER=v2.9.12
  230. # $ curl -O \
  231. # https://gitlab.gnome.org/GNOME/libxml2/-/archive/$VER/libxml2-$VER.tar.gz
  232. # $ gsutil cp -n -a public-read libxml2-$VER.tar.gz \
  233. # gs://chromium-browser-clang/tools
  234. libxml2_version = 'libxml2-v2.9.12'
  235. libxml2_dir = os.path.join(LLVM_BUILD_TOOLS_DIR, libxml2_version)
  236. if os.path.exists(libxml2_dir):
  237. RmTree(libxml2_dir)
  238. zip_name = libxml2_version + '.tar.gz'
  239. DownloadAndUnpack(CDS_URL + '/tools/' + zip_name, LLVM_BUILD_TOOLS_DIR)
  240. os.chdir(libxml2_dir)
  241. os.mkdir('build')
  242. os.chdir('build')
  243. libxml2_install_dir = os.path.join(libxml2_dir, 'build', 'install')
  244. # Disable everything except WITH_TREE and WITH_OUTPUT, both needed by LLVM's
  245. # WindowsManifestMerger.
  246. # Also enable WITH_THREADS, else libxml doesn't compile on Linux.
  247. RunCommand(
  248. [
  249. 'cmake',
  250. '-GNinja',
  251. '-DCMAKE_BUILD_TYPE=Release',
  252. '-DCMAKE_INSTALL_PREFIX=install',
  253. # The mac_arm bot builds a clang arm binary, but currently on an intel
  254. # host. If we ever move it to run on an arm mac, this can go. We
  255. # could pass this only if args.build_mac_arm, but libxml is small, so
  256. # might as well build it universal always for a few years.
  257. '-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64',
  258. '-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded', # /MT to match LLVM.
  259. '-DBUILD_SHARED_LIBS=OFF',
  260. '-DLIBXML2_WITH_C14N=OFF',
  261. '-DLIBXML2_WITH_CATALOG=OFF',
  262. '-DLIBXML2_WITH_DEBUG=OFF',
  263. '-DLIBXML2_WITH_DOCB=OFF',
  264. '-DLIBXML2_WITH_FTP=OFF',
  265. '-DLIBXML2_WITH_HTML=OFF',
  266. '-DLIBXML2_WITH_HTTP=OFF',
  267. '-DLIBXML2_WITH_ICONV=OFF',
  268. '-DLIBXML2_WITH_ICU=OFF',
  269. '-DLIBXML2_WITH_ISO8859X=OFF',
  270. '-DLIBXML2_WITH_LEGACY=OFF',
  271. '-DLIBXML2_WITH_LZMA=OFF',
  272. '-DLIBXML2_WITH_MEM_DEBUG=OFF',
  273. '-DLIBXML2_WITH_MODULES=OFF',
  274. '-DLIBXML2_WITH_OUTPUT=ON',
  275. '-DLIBXML2_WITH_PATTERN=OFF',
  276. '-DLIBXML2_WITH_PROGRAMS=OFF',
  277. '-DLIBXML2_WITH_PUSH=OFF',
  278. '-DLIBXML2_WITH_PYTHON=OFF',
  279. '-DLIBXML2_WITH_READER=OFF',
  280. '-DLIBXML2_WITH_REGEXPS=OFF',
  281. '-DLIBXML2_WITH_RUN_DEBUG=OFF',
  282. '-DLIBXML2_WITH_SAX1=OFF',
  283. '-DLIBXML2_WITH_SCHEMAS=OFF',
  284. '-DLIBXML2_WITH_SCHEMATRON=OFF',
  285. '-DLIBXML2_WITH_TESTS=OFF',
  286. '-DLIBXML2_WITH_THREADS=ON',
  287. '-DLIBXML2_WITH_THREAD_ALLOC=OFF',
  288. '-DLIBXML2_WITH_TREE=ON',
  289. '-DLIBXML2_WITH_VALID=OFF',
  290. '-DLIBXML2_WITH_WRITER=OFF',
  291. '-DLIBXML2_WITH_XINCLUDE=OFF',
  292. '-DLIBXML2_WITH_XPATH=OFF',
  293. '-DLIBXML2_WITH_XPTR=OFF',
  294. '-DLIBXML2_WITH_ZLIB=OFF',
  295. '..',
  296. ],
  297. msvc_arch='x64')
  298. RunCommand(['ninja', 'install'], msvc_arch='x64')
  299. libxml2_include_dir = os.path.join(libxml2_install_dir, 'include', 'libxml2')
  300. if sys.platform == 'win32':
  301. libxml2_lib = os.path.join(libxml2_install_dir, 'lib', 'libxml2s.lib')
  302. else:
  303. libxml2_lib = os.path.join(libxml2_install_dir, 'lib', 'libxml2.a')
  304. extra_cmake_flags = [
  305. '-DLLVM_ENABLE_LIBXML2=FORCE_ON',
  306. '-DLIBXML2_INCLUDE_DIR=' + libxml2_include_dir.replace('\\', '/'),
  307. '-DLIBXML2_LIBRARIES=' + libxml2_lib.replace('\\', '/'),
  308. ]
  309. extra_cflags = ['-DLIBXML_STATIC']
  310. return extra_cmake_flags, extra_cflags
  311. def DownloadRPMalloc():
  312. """Download rpmalloc."""
  313. rpmalloc_dir = os.path.join(LLVM_BUILD_TOOLS_DIR, 'rpmalloc')
  314. if os.path.exists(rpmalloc_dir):
  315. RmTree(rpmalloc_dir)
  316. # Using rpmalloc bc1923f rather than the latest release (1.4.1) because
  317. # it contains the fix for https://github.com/mjansson/rpmalloc/pull/186
  318. # which would cause lld to deadlock.
  319. # The zip file was created and uploaded as follows:
  320. # $ mkdir rpmalloc
  321. # $ curl -L https://github.com/mjansson/rpmalloc/archive/bc1923f436539327707b08ef9751a7a87bdd9d2f.tar.gz \
  322. # | tar -C rpmalloc --strip-components=1 -xzf -
  323. # $ GZIP=-9 tar vzcf rpmalloc-bc1923f.tgz rpmalloc
  324. # $ gsutil.py cp -n -a public-read rpmalloc-bc1923f.tgz \
  325. # gs://chromium-browser-clang/tools/
  326. zip_name = 'rpmalloc-bc1923f.tgz'
  327. DownloadAndUnpack(CDS_URL + '/tools/' + zip_name, LLVM_BUILD_TOOLS_DIR)
  328. rpmalloc_dir = rpmalloc_dir.replace('\\', '/')
  329. return rpmalloc_dir
  330. def DownloadPinnedClang():
  331. # The update.py in this current revision may have a patched revision while
  332. # building new clang packages. Get update.py off HEAD~ to pull the current
  333. # pinned clang.
  334. with tempfile.NamedTemporaryFile() as f:
  335. subprocess.check_call(
  336. ['git', 'show', 'HEAD~:tools/clang/scripts/update.py'],
  337. stdout=f,
  338. cwd=CHROMIUM_DIR)
  339. print("Running update.py")
  340. # Without the flush, the subprocess call below doesn't work.
  341. f.flush()
  342. subprocess.check_call(
  343. [sys.executable, f.name, '--output-dir=' + PINNED_CLANG_DIR])
  344. # TODO(crbug.com/929645): Remove once we don't need gcc's libstdc++.
  345. def MaybeDownloadHostGcc(args):
  346. """Download a modern GCC host compiler on Linux."""
  347. assert sys.platform.startswith('linux')
  348. if args.gcc_toolchain:
  349. return
  350. gcc_dir = os.path.join(LLVM_BUILD_TOOLS_DIR, 'gcc-10.2.0-trusty')
  351. if not os.path.exists(gcc_dir):
  352. DownloadAndUnpack(CDS_URL + '/tools/gcc-10.2.0-trusty.tgz', gcc_dir)
  353. args.gcc_toolchain = gcc_dir
  354. def VerifyVersionOfBuiltClangMatchesVERSION():
  355. """Checks that `clang --version` outputs RELEASE_VERSION. If this
  356. fails, update.RELEASE_VERSION is out-of-date and needs to be updated (possibly
  357. in an `if args.llvm_force_head_revision:` block inupdate. main() first)."""
  358. clang = os.path.join(LLVM_BUILD_DIR, 'bin', 'clang')
  359. if sys.platform == 'win32':
  360. clang += '-cl.exe'
  361. version_out = subprocess.check_output([clang, '--version'],
  362. universal_newlines=True)
  363. version_out = re.match(r'clang version ([0-9.]+)', version_out).group(1)
  364. if version_out != RELEASE_VERSION:
  365. print(('unexpected clang version %s (not %s), '
  366. 'update RELEASE_VERSION in update.py')
  367. % (version_out, RELEASE_VERSION))
  368. sys.exit(1)
  369. def VerifyZlibSupport():
  370. """Check that clang was built with zlib support enabled."""
  371. clang = os.path.join(LLVM_BUILD_DIR, 'bin', 'clang')
  372. test_file = '/dev/null'
  373. if sys.platform == 'win32':
  374. clang += '.exe'
  375. test_file = 'nul'
  376. print('Checking for zlib support')
  377. clang_out = subprocess.check_output([
  378. clang, '-target', 'x86_64-unknown-linux-gnu', '-gz', '-c', '-###', '-x',
  379. 'c', test_file
  380. ],
  381. stderr=subprocess.STDOUT,
  382. universal_newlines=True)
  383. if (re.search(r'--compress-debug-sections', clang_out)):
  384. print('OK')
  385. else:
  386. print(('Failed to detect zlib support!\n\n(driver output: %s)') % clang_out)
  387. sys.exit(1)
  388. # TODO(https://crbug.com/1286289): remove once Chrome targets don't rely on
  389. # libstdc++.so existing in the clang package.
  390. def CopyLibstdcpp(args, build_dir):
  391. if not args.gcc_toolchain:
  392. return
  393. # Find libstdc++.so.6
  394. libstdcpp = subprocess.check_output([
  395. os.path.join(args.gcc_toolchain, 'bin', 'g++'),
  396. '-print-file-name=libstdc++.so.6'
  397. ],
  398. universal_newlines=True).rstrip()
  399. EnsureDirExists(os.path.join(build_dir, 'lib'))
  400. CopyFile(libstdcpp, os.path.join(build_dir, 'lib'))
  401. def gn_arg(v):
  402. if v == 'True':
  403. return True
  404. if v == 'False':
  405. return False
  406. raise argparse.ArgumentTypeError('Expected one of %r or %r' % (
  407. 'True', 'False'))
  408. def main():
  409. parser = argparse.ArgumentParser(description='Build Clang.')
  410. parser.add_argument('--bootstrap', action='store_true',
  411. help='first build clang with CC, then with itself.')
  412. parser.add_argument('--build-mac-arm', action='store_true',
  413. help='Build arm binaries. Only valid on macOS.')
  414. parser.add_argument('--disable-asserts', action='store_true',
  415. help='build with asserts disabled')
  416. parser.add_argument('--gcc-toolchain', help='what gcc toolchain to use for '
  417. 'building; --gcc-toolchain=/opt/foo picks '
  418. '/opt/foo/bin/gcc')
  419. parser.add_argument('--pgo', action='store_true', help='build with PGO')
  420. parser.add_argument('--thinlto',
  421. action='store_true',
  422. help='build with ThinLTO')
  423. parser.add_argument('--llvm-force-head-revision', action='store_true',
  424. help='build the latest revision')
  425. parser.add_argument('--run-tests', action='store_true',
  426. help='run tests after building')
  427. parser.add_argument('--skip-build', action='store_true',
  428. help='do not build anything')
  429. parser.add_argument('--skip-checkout', action='store_true',
  430. help='do not create or update any checkouts')
  431. parser.add_argument('--build-dir',
  432. help='Override build directory')
  433. parser.add_argument('--extra-tools', nargs='*', default=[],
  434. help='select additional chrome tools to build')
  435. parser.add_argument('--use-system-cmake', action='store_true',
  436. help='use the cmake from PATH instead of downloading '
  437. 'and using prebuilt cmake binaries')
  438. parser.add_argument('--with-android', type=gn_arg, nargs='?', const=True,
  439. help='build the Android ASan runtime (linux only)',
  440. default=sys.platform.startswith('linux'))
  441. parser.add_argument('--with-fuchsia',
  442. type=gn_arg,
  443. nargs='?',
  444. const=True,
  445. help='build the Fuchsia runtimes (linux and mac only)',
  446. default=sys.platform.startswith('linux')
  447. or sys.platform.startswith('darwin'))
  448. parser.add_argument('--without-android', action='store_false',
  449. help='don\'t build Android ASan runtime (linux only)',
  450. dest='with_android')
  451. parser.add_argument('--without-fuchsia', action='store_false',
  452. help='don\'t build Fuchsia clang_rt runtime (linux/mac)',
  453. dest='with_fuchsia',
  454. default=sys.platform in ('linux2', 'darwin'))
  455. args = parser.parse_args()
  456. global CLANG_REVISION, PACKAGE_VERSION, LLVM_BUILD_DIR
  457. if (args.pgo or args.thinlto) and not args.bootstrap:
  458. print('--pgo/--thinlto requires --bootstrap')
  459. return 1
  460. if args.with_android and not os.path.exists(ANDROID_NDK_DIR):
  461. print('Android NDK not found at ' + ANDROID_NDK_DIR)
  462. print('The Android NDK is needed to build a Clang whose -fsanitize=address')
  463. print('works on Android. See ')
  464. print('https://www.chromium.org/developers/how-tos/android-build-instructions')
  465. print('for how to install the NDK, or pass --without-android.')
  466. return 1
  467. if args.with_fuchsia and not os.path.exists(FUCHSIA_SDK_DIR):
  468. print('Fuchsia SDK not found at ' + FUCHSIA_SDK_DIR)
  469. print('The Fuchsia SDK is needed to build libclang_rt for Fuchsia.')
  470. print('Install the Fuchsia SDK by adding fuchsia to the ')
  471. print('target_os section in your .gclient and running hooks, ')
  472. print('or pass --without-fuchsia.')
  473. print(
  474. 'https://chromium.googlesource.com/chromium/src/+/main/docs/fuchsia/build_instructions.md'
  475. )
  476. print('for general Fuchsia build instructions.')
  477. return 1
  478. if args.build_mac_arm and sys.platform != 'darwin':
  479. print('--build-mac-arm only valid on macOS')
  480. return 1
  481. if args.build_mac_arm and platform.machine() == 'arm64':
  482. print('--build-mac-arm only valid on intel to cross-build arm')
  483. return 1
  484. # Don't buffer stdout, so that print statements are immediately flushed.
  485. # LLVM tests print output without newlines, so with buffering they won't be
  486. # immediately printed.
  487. major, _, _, _, _ = sys.version_info
  488. if major == 3:
  489. # Python3 only allows unbuffered output for binary streams. This
  490. # workaround comes from https://stackoverflow.com/a/181654/4052492.
  491. sys.stdout = io.TextIOWrapper(open(sys.stdout.fileno(), 'wb', 0),
  492. write_through=True)
  493. else:
  494. sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
  495. # The gnuwin package also includes curl, which is needed to interact with the
  496. # github API below.
  497. # TODO(crbug.com/1067752): Use urllib once certificates are fixed, and
  498. # move this down to where we fetch other build tools.
  499. AddGnuWinToPath()
  500. if sys.platform == 'darwin':
  501. isysroot = subprocess.check_output(['xcrun', '--show-sdk-path'],
  502. universal_newlines=True).rstrip()
  503. if args.build_dir:
  504. LLVM_BUILD_DIR = args.build_dir
  505. if args.llvm_force_head_revision:
  506. checkout_revision = GetLatestLLVMCommit()
  507. else:
  508. checkout_revision = CLANG_REVISION
  509. if not args.skip_checkout:
  510. CheckoutLLVM(checkout_revision, LLVM_DIR)
  511. if args.llvm_force_head_revision:
  512. CLANG_REVISION = GetCommitDescription(checkout_revision)
  513. PACKAGE_VERSION = '%s-0' % CLANG_REVISION
  514. print('Locally building clang %s...' % PACKAGE_VERSION)
  515. WriteStampFile('', STAMP_FILE)
  516. WriteStampFile('', FORCE_HEAD_REVISION_FILE)
  517. AddCMakeToPath(args)
  518. DeleteChromeToolsShim()
  519. if args.skip_build:
  520. return 0
  521. # The variable "lld" is only used on Windows because only there does setting
  522. # CMAKE_LINKER have an effect: On Windows, the linker is called directly,
  523. # while elsewhere it's called through the compiler driver, and we pass
  524. # -fuse-ld=lld there to make the compiler driver call the linker (by setting
  525. # LLVM_ENABLE_LLD).
  526. cc, cxx, lld = None, None, None
  527. cflags = []
  528. cxxflags = []
  529. ldflags = []
  530. targets = 'AArch64;ARM;Mips;PowerPC;RISCV;SystemZ;WebAssembly;X86'
  531. projects = 'clang;compiler-rt;lld;clang-tools-extra'
  532. if sys.platform == 'darwin':
  533. # clang needs libc++, else -stdlib=libc++ won't find includes
  534. # (this is needed for bootstrap builds and for building the fuchsia runtime)
  535. projects += ';libcxx'
  536. base_cmake_args = [
  537. '-GNinja',
  538. '-DCMAKE_BUILD_TYPE=Release',
  539. '-DLLVM_ENABLE_ASSERTIONS=%s' % ('OFF' if args.disable_asserts else 'ON'),
  540. '-DLLVM_ENABLE_PROJECTS=' + projects,
  541. '-DLLVM_TARGETS_TO_BUILD=' + targets,
  542. # PIC needed for Rust build (links LLVM into shared object)
  543. '-DLLVM_ENABLE_PIC=ON',
  544. '-DLLVM_ENABLE_UNWIND_TABLES=OFF',
  545. '-DLLVM_ENABLE_TERMINFO=OFF',
  546. '-DLLVM_ENABLE_Z3_SOLVER=OFF',
  547. '-DCLANG_PLUGIN_SUPPORT=OFF',
  548. '-DCLANG_ENABLE_STATIC_ANALYZER=OFF',
  549. '-DCLANG_ENABLE_ARCMT=OFF',
  550. '-DBUG_REPORT_URL=' + BUG_REPORT_URL,
  551. # Don't run Go bindings tests; PGO makes them confused.
  552. '-DLLVM_INCLUDE_GO_TESTS=OFF',
  553. # TODO(crbug.com/1113475): Update binutils.
  554. '-DENABLE_X86_RELAX_RELOCATIONS=NO',
  555. # See crbug.com/1126219: Use native symbolizer instead of DIA
  556. '-DLLVM_ENABLE_DIA_SDK=OFF',
  557. # StarFive: Required for native RISCV build
  558. '-DSANITIZER_COMMON_LINK_LIBS=-latomic',
  559. # See crbug.com/1205046: don't build scudo (and others we don't need).
  560. '-DCOMPILER_RT_SANITIZERS_TO_BUILD=asan;dfsan;msan;hwasan;tsan;cfi',
  561. # The default value differs per platform, force it off everywhere.
  562. '-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF',
  563. # Don't use curl.
  564. '-DLLVM_ENABLE_CURL=OFF',
  565. # Build libclang.a as well as libclang.so
  566. '-DLIBCLANG_BUILD_STATIC=ON',
  567. ]
  568. if sys.platform.startswith('linux'):
  569. MaybeDownloadHostGcc(args)
  570. DownloadPinnedClang()
  571. cc = os.path.join(PINNED_CLANG_DIR, 'bin', 'clang')
  572. cxx = os.path.join(PINNED_CLANG_DIR, 'bin', 'clang++')
  573. # Use the libraries in the specified gcc installation for building.
  574. cflags.append('--gcc-toolchain=' + args.gcc_toolchain)
  575. cxxflags.append('--gcc-toolchain=' + args.gcc_toolchain)
  576. base_cmake_args += [
  577. # The host clang has lld.
  578. '-DLLVM_ENABLE_LLD=ON',
  579. '-DLLVM_STATIC_LINK_CXX_STDLIB=ON',
  580. # Force compiler-rt tests to use our gcc toolchain
  581. # because the one on the host may be too old.
  582. # Even with -static-libstdc++ the compiler-rt tests add -lstdc++
  583. # which adds a DT_NEEDED to libstdc++.so so we need to add RPATHs
  584. # to the gcc toolchain.
  585. '-DCOMPILER_RT_TEST_COMPILER_CFLAGS=--gcc-toolchain=' +
  586. args.gcc_toolchain + ' -Wl,-rpath,' +
  587. os.path.join(args.gcc_toolchain, 'lib64') + ' -Wl,-rpath,' +
  588. os.path.join(args.gcc_toolchain, 'lib32')
  589. ]
  590. if sys.platform == 'darwin':
  591. # For libc++, we only want the headers.
  592. base_cmake_args.extend([
  593. '-DLIBCXX_ENABLE_SHARED=OFF',
  594. '-DLIBCXX_ENABLE_STATIC=OFF',
  595. '-DLIBCXX_INCLUDE_TESTS=OFF',
  596. '-DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=OFF',
  597. ])
  598. if sys.platform == 'win32':
  599. base_cmake_args.append('-DLLVM_USE_CRT_RELEASE=MT')
  600. # Require zlib compression.
  601. zlib_dir = AddZlibToPath()
  602. cflags.append('-I' + zlib_dir)
  603. cxxflags.append('-I' + zlib_dir)
  604. ldflags.append('-LIBPATH:' + zlib_dir)
  605. # Use rpmalloc. For faster ThinLTO linking.
  606. rpmalloc_dir = DownloadRPMalloc()
  607. base_cmake_args.append('-DLLVM_INTEGRATED_CRT_ALLOC=' + rpmalloc_dir)
  608. # Statically link libxml2 to make lld-link not require mt.exe on Windows,
  609. # and to make sure lld-link output on other platforms is identical to
  610. # lld-link on Windows (for cross-builds).
  611. libxml_cmake_args, libxml_cflags = BuildLibXml2()
  612. base_cmake_args += libxml_cmake_args
  613. cflags += libxml_cflags
  614. cxxflags += libxml_cflags
  615. if args.bootstrap:
  616. print('Building bootstrap compiler')
  617. if os.path.exists(LLVM_BOOTSTRAP_DIR):
  618. RmTree(LLVM_BOOTSTRAP_DIR)
  619. EnsureDirExists(LLVM_BOOTSTRAP_DIR)
  620. os.chdir(LLVM_BOOTSTRAP_DIR)
  621. projects = 'clang'
  622. if args.pgo:
  623. # Need libclang_rt.profile
  624. projects += ';compiler-rt'
  625. if sys.platform != 'darwin':
  626. projects += ';lld'
  627. if sys.platform == 'darwin':
  628. # Need libc++ and compiler-rt for the bootstrap compiler on mac.
  629. projects += ';libcxx;compiler-rt'
  630. bootstrap_targets = 'X86'
  631. if sys.platform == 'darwin':
  632. # Need ARM and AArch64 for building the ios clang_rt.
  633. bootstrap_targets += ';ARM;AArch64'
  634. bootstrap_args = base_cmake_args + [
  635. '-DLLVM_TARGETS_TO_BUILD=' + bootstrap_targets,
  636. '-DLLVM_ENABLE_PROJECTS=' + projects,
  637. '-DCMAKE_INSTALL_PREFIX=' + LLVM_BOOTSTRAP_INSTALL_DIR,
  638. '-DCMAKE_C_FLAGS=' + ' '.join(cflags),
  639. '-DCMAKE_CXX_FLAGS=' + ' '.join(cxxflags),
  640. '-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(ldflags),
  641. '-DCMAKE_SHARED_LINKER_FLAGS=' + ' '.join(ldflags),
  642. '-DCMAKE_MODULE_LINKER_FLAGS=' + ' '.join(ldflags),
  643. # Ignore args.disable_asserts for the bootstrap compiler.
  644. '-DLLVM_ENABLE_ASSERTIONS=ON',
  645. ]
  646. if sys.platform == 'darwin':
  647. # On macOS, the bootstrap toolchain needs to have compiler-rt because
  648. # dsymutil's link needs libclang_rt.osx.a. Only the x86_64 osx
  649. # libraries are needed though, and only libclang_rt (i.e.
  650. # COMPILER_RT_BUILD_BUILTINS).
  651. bootstrap_args.extend([
  652. '-DCOMPILER_RT_BUILD_BUILTINS=ON',
  653. '-DCOMPILER_RT_BUILD_CRT=OFF',
  654. '-DCOMPILER_RT_BUILD_LIBFUZZER=OFF',
  655. '-DCOMPILER_RT_BUILD_MEMPROF=OFF',
  656. '-DCOMPILER_RT_BUILD_ORC=OFF',
  657. '-DCOMPILER_RT_BUILD_SANITIZERS=OFF',
  658. '-DCOMPILER_RT_BUILD_XRAY=OFF',
  659. '-DCOMPILER_RT_ENABLE_IOS=OFF',
  660. '-DCOMPILER_RT_ENABLE_WATCHOS=OFF',
  661. '-DCOMPILER_RT_ENABLE_TVOS=OFF',
  662. ])
  663. if platform.machine() == 'arm64':
  664. bootstrap_args.extend(['-DDARWIN_osx_ARCHS=arm64'])
  665. else:
  666. bootstrap_args.extend(['-DDARWIN_osx_ARCHS=x86_64'])
  667. elif args.pgo:
  668. # PGO needs libclang_rt.profile but none of the other compiler-rt stuff.
  669. bootstrap_args.extend([
  670. '-DCOMPILER_RT_BUILD_BUILTINS=OFF',
  671. '-DCOMPILER_RT_BUILD_CRT=OFF',
  672. '-DCOMPILER_RT_BUILD_LIBFUZZER=OFF',
  673. '-DCOMPILER_RT_BUILD_MEMPROF=OFF',
  674. '-DCOMPILER_RT_BUILD_ORC=OFF',
  675. '-DCOMPILER_RT_BUILD_PROFILE=ON',
  676. '-DCOMPILER_RT_BUILD_SANITIZERS=OFF',
  677. '-DCOMPILER_RT_BUILD_XRAY=OFF',
  678. ])
  679. if cc is not None: bootstrap_args.append('-DCMAKE_C_COMPILER=' + cc)
  680. if cxx is not None: bootstrap_args.append('-DCMAKE_CXX_COMPILER=' + cxx)
  681. if lld is not None: bootstrap_args.append('-DCMAKE_LINKER=' + lld)
  682. RunCommand(['cmake'] + bootstrap_args + [os.path.join(LLVM_DIR, 'llvm')],
  683. msvc_arch='x64')
  684. RunCommand(['ninja'], msvc_arch='x64')
  685. if args.run_tests:
  686. test_targets = ['check-all']
  687. if sys.platform == 'darwin' and platform.machine() == 'arm64':
  688. # TODO(llvm.org/PR49918): Run check-all on mac/arm too.
  689. test_targets = ['check-llvm', 'check-clang']
  690. RunCommand(['ninja'] + test_targets, msvc_arch='x64')
  691. RunCommand(['ninja', 'install'], msvc_arch='x64')
  692. if sys.platform == 'win32':
  693. cc = os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'bin', 'clang-cl.exe')
  694. cxx = os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'bin', 'clang-cl.exe')
  695. lld = os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'bin', 'lld-link.exe')
  696. # CMake has a hard time with backslashes in compiler paths:
  697. # https://stackoverflow.com/questions/13050827
  698. cc = cc.replace('\\', '/')
  699. cxx = cxx.replace('\\', '/')
  700. lld = lld.replace('\\', '/')
  701. else:
  702. cc = os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'bin', 'clang')
  703. cxx = os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'bin', 'clang++')
  704. print('Bootstrap compiler installed.')
  705. if args.pgo:
  706. print('Building instrumented compiler')
  707. if os.path.exists(LLVM_INSTRUMENTED_DIR):
  708. RmTree(LLVM_INSTRUMENTED_DIR)
  709. EnsureDirExists(LLVM_INSTRUMENTED_DIR)
  710. os.chdir(LLVM_INSTRUMENTED_DIR)
  711. projects = 'clang'
  712. if sys.platform == 'darwin':
  713. projects += ';libcxx;compiler-rt'
  714. instrument_args = base_cmake_args + [
  715. '-DLLVM_ENABLE_PROJECTS=' + projects,
  716. '-DCMAKE_C_FLAGS=' + ' '.join(cflags),
  717. '-DCMAKE_CXX_FLAGS=' + ' '.join(cxxflags),
  718. '-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(ldflags),
  719. '-DCMAKE_SHARED_LINKER_FLAGS=' + ' '.join(ldflags),
  720. '-DCMAKE_MODULE_LINKER_FLAGS=' + ' '.join(ldflags),
  721. # Build with instrumentation.
  722. '-DLLVM_BUILD_INSTRUMENTED=IR',
  723. ]
  724. # Build with the bootstrap compiler.
  725. if cc is not None: instrument_args.append('-DCMAKE_C_COMPILER=' + cc)
  726. if cxx is not None: instrument_args.append('-DCMAKE_CXX_COMPILER=' + cxx)
  727. if lld is not None: instrument_args.append('-DCMAKE_LINKER=' + lld)
  728. RunCommand(['cmake'] + instrument_args + [os.path.join(LLVM_DIR, 'llvm')],
  729. msvc_arch='x64')
  730. RunCommand(['ninja'], msvc_arch='x64')
  731. print('Instrumented compiler built.')
  732. # Train by building some C++ code.
  733. #
  734. # pgo_training-1.ii is a preprocessed (on Linux) version of
  735. # src/third_party/blink/renderer/core/layout/layout_object.cc, selected
  736. # because it's a large translation unit in Blink, which is normally the
  737. # slowest part of Chromium to compile. Using this, we get ~20% shorter
  738. # build times for Linux, Android, and Mac, which is also what we got when
  739. # training by actually building a target in Chromium. (For comparison, a
  740. # C++-y "Hello World" program only resulted in 14% faster builds.)
  741. # See https://crbug.com/966403#c16 for all numbers.
  742. #
  743. # Although the training currently only exercises Clang, it does involve LLVM
  744. # internals, and so LLD also benefits when used for ThinLTO links.
  745. #
  746. # NOTE: Tidy uses binaries built with this profile, but doesn't seem to
  747. # gain much from it. If tidy's execution time becomes a concern, it might
  748. # be good to investigate that.
  749. #
  750. # TODO(hans): Enhance the training, perhaps by including preprocessed code
  751. # from more platforms, and by doing some linking so that lld can benefit
  752. # from PGO as well. Perhaps the training could be done asynchronously by
  753. # dedicated buildbots that upload profiles to the cloud.
  754. training_source = 'pgo_training-1.ii'
  755. with open(training_source, 'wb') as f:
  756. DownloadUrl(CDS_URL + '/' + training_source, f)
  757. train_cmd = [os.path.join(LLVM_INSTRUMENTED_DIR, 'bin', 'clang++'),
  758. '-target', 'x86_64-unknown-unknown', '-O2', '-g', '-std=c++14',
  759. '-fno-exceptions', '-fno-rtti', '-w', '-c', training_source]
  760. if sys.platform == 'darwin':
  761. train_cmd.extend(['-stdlib=libc++', '-isysroot', isysroot])
  762. RunCommand(train_cmd, msvc_arch='x64')
  763. # Merge profiles.
  764. profdata = os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'bin', 'llvm-profdata')
  765. RunCommand([profdata, 'merge', '-output=' + LLVM_PROFDATA_FILE] +
  766. glob.glob(os.path.join(LLVM_INSTRUMENTED_DIR, 'profiles',
  767. '*.profraw')), msvc_arch='x64')
  768. print('Profile generated.')
  769. compiler_rt_args = [
  770. # Build crtbegin/crtend. It's just two tiny TUs, so just enable this
  771. # everywhere, even though we only need it on Linux.
  772. '-DCOMPILER_RT_BUILD_CRT=ON',
  773. '-DCOMPILER_RT_BUILD_LIBFUZZER=OFF',
  774. '-DCOMPILER_RT_BUILD_MEMPROF=OFF',
  775. '-DCOMPILER_RT_BUILD_ORC=OFF',
  776. '-DCOMPILER_RT_BUILD_PROFILE=ON',
  777. '-DCOMPILER_RT_BUILD_SANITIZERS=ON',
  778. '-DCOMPILER_RT_BUILD_XRAY=OFF',
  779. ]
  780. if sys.platform == 'darwin':
  781. compiler_rt_args.extend([
  782. '-DCOMPILER_RT_ENABLE_IOS=ON',
  783. '-DCOMPILER_RT_ENABLE_WATCHOS=OFF',
  784. '-DCOMPILER_RT_ENABLE_TVOS=OFF',
  785. # armv7 is A5 and earlier, armv7s is A6+ (2012 and later, before 64-bit
  786. # iPhones). armv7k is Apple Watch, which we don't need.
  787. '-DDARWIN_ios_ARCHS=armv7;armv7s;arm64',
  788. '-DDARWIN_iossim_ARCHS=i386;x86_64;arm64',
  789. # We don't need 32-bit intel support for macOS, we only ship 64-bit.
  790. '-DDARWIN_osx_ARCHS=arm64;x86_64',
  791. ])
  792. if sys.platform == 'win32':
  793. # https://crbug.com/1293778
  794. compiler_rt_args.append('-DCOMPILER_RT_BUILD_BUILTINS=OFF')
  795. else:
  796. compiler_rt_args.append('-DCOMPILER_RT_BUILD_BUILTINS=ON')
  797. # LLVM uses C++11 starting in llvm 3.5. On Linux, this means libstdc++4.7+ is
  798. # needed, on OS X it requires libc++. clang only automatically links to libc++
  799. # when targeting OS X 10.9+, so add stdlib=libc++ explicitly so clang can run
  800. # on OS X versions as old as 10.7.
  801. deployment_target = ''
  802. if sys.platform == 'darwin' and args.bootstrap:
  803. # When building on 10.9, /usr/include usually doesn't exist, and while
  804. # Xcode's clang automatically sets a sysroot, self-built clangs don't.
  805. cflags = ['-isysroot', isysroot]
  806. cxxflags = ['-stdlib=libc++'] + cflags
  807. ldflags += ['-stdlib=libc++']
  808. deployment_target = '10.7'
  809. # If building at head, define a macro that plugins can use for #ifdefing
  810. # out code that builds at head, but not at CLANG_REVISION or vice versa.
  811. if args.llvm_force_head_revision:
  812. cflags += ['-DLLVM_FORCE_HEAD_REVISION']
  813. cxxflags += ['-DLLVM_FORCE_HEAD_REVISION']
  814. # Build PDBs for archival on Windows. Don't use RelWithDebInfo since it
  815. # has different optimization defaults than Release.
  816. # Also disable stack cookies (/GS-) for performance.
  817. if sys.platform == 'win32':
  818. cflags += ['/Zi', '/GS-']
  819. cxxflags += ['/Zi', '/GS-']
  820. ldflags += ['/DEBUG', '/OPT:REF', '/OPT:ICF']
  821. deployment_env = None
  822. if deployment_target:
  823. deployment_env = os.environ.copy()
  824. deployment_env['MACOSX_DEPLOYMENT_TARGET'] = deployment_target
  825. print('Building final compiler.')
  826. default_tools = ['plugins', 'blink_gc_plugin', 'translation_unit']
  827. chrome_tools = list(set(default_tools + args.extra_tools))
  828. if cc is not None: base_cmake_args.append('-DCMAKE_C_COMPILER=' + cc)
  829. if cxx is not None: base_cmake_args.append('-DCMAKE_CXX_COMPILER=' + cxx)
  830. if lld is not None: base_cmake_args.append('-DCMAKE_LINKER=' + lld)
  831. cmake_args = base_cmake_args + compiler_rt_args + [
  832. '-DCMAKE_C_FLAGS=' + ' '.join(cflags),
  833. '-DCMAKE_CXX_FLAGS=' + ' '.join(cxxflags),
  834. '-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(ldflags),
  835. '-DCMAKE_SHARED_LINKER_FLAGS=' + ' '.join(ldflags),
  836. '-DCMAKE_MODULE_LINKER_FLAGS=' + ' '.join(ldflags),
  837. '-DCMAKE_INSTALL_PREFIX=' + LLVM_BUILD_DIR,
  838. '-DLLVM_EXTERNAL_PROJECTS=chrometools',
  839. '-DLLVM_EXTERNAL_CHROMETOOLS_SOURCE_DIR=' +
  840. os.path.join(CHROMIUM_DIR, 'tools', 'clang'),
  841. '-DCHROMIUM_TOOLS=%s' % ';'.join(chrome_tools)]
  842. if args.pgo:
  843. cmake_args.append('-DLLVM_PROFDATA_FILE=' + LLVM_PROFDATA_FILE)
  844. if args.thinlto:
  845. cmake_args.append('-DLLVM_ENABLE_LTO=Thin')
  846. if sys.platform == 'win32':
  847. cmake_args.append('-DLLVM_ENABLE_ZLIB=FORCE_ON')
  848. if sys.platform == 'darwin':
  849. cmake_args += ['-DCOMPILER_RT_ENABLE_IOS=ON',
  850. '-DSANITIZER_MIN_OSX_VERSION=10.7']
  851. if args.build_mac_arm:
  852. assert platform.machine() != 'arm64', 'build_mac_arm for cross build only'
  853. cmake_args += ['-DCMAKE_OSX_ARCHITECTURES=arm64',
  854. '-DLLVM_USE_HOST_TOOLS=ON']
  855. # The default LLVM_DEFAULT_TARGET_TRIPLE depends on the host machine.
  856. # Set it explicitly to make the build of clang more hermetic, and also to
  857. # set it to arm64 when cross-building clang for mac/arm.
  858. if sys.platform == 'darwin':
  859. if args.build_mac_arm or platform.machine() == 'arm64':
  860. cmake_args.append('-DLLVM_DEFAULT_TARGET_TRIPLE=arm64-apple-darwin')
  861. else:
  862. cmake_args.append('-DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-apple-darwin')
  863. elif sys.platform.startswith('linux'):
  864. if platform.machine() == 'aarch64':
  865. cmake_args.append(
  866. '-DLLVM_DEFAULT_TARGET_TRIPLE=aarch64-unknown-linux-gnu')
  867. elif platform.machine() == 'riscv64':
  868. cmake_args.append(
  869. '-DLLVM_DEFAULT_TARGET_TRIPLE=riscv64-linux-gnu')
  870. else:
  871. cmake_args.append('-DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-unknown-linux-gnu')
  872. cmake_args.append('-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON')
  873. elif sys.platform == 'win32':
  874. cmake_args.append('-DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-pc-windows-msvc')
  875. if os.path.exists(LLVM_BUILD_DIR):
  876. RmTree(LLVM_BUILD_DIR)
  877. EnsureDirExists(LLVM_BUILD_DIR)
  878. os.chdir(LLVM_BUILD_DIR)
  879. RunCommand(['cmake'] + cmake_args + [os.path.join(LLVM_DIR, 'llvm')],
  880. msvc_arch='x64', env=deployment_env)
  881. CopyLibstdcpp(args, LLVM_BUILD_DIR)
  882. RunCommand(['ninja'], msvc_arch='x64')
  883. if chrome_tools:
  884. # If any Chromium tools were built, install those now.
  885. RunCommand(['ninja', 'cr-install'], msvc_arch='x64')
  886. if not args.build_mac_arm:
  887. VerifyVersionOfBuiltClangMatchesVERSION()
  888. VerifyZlibSupport()
  889. if sys.platform == 'win32':
  890. rt_platform = 'windows'
  891. elif sys.platform == 'darwin':
  892. rt_platform = 'darwin'
  893. else:
  894. assert sys.platform.startswith('linux')
  895. rt_platform = 'linux'
  896. rt_lib_dst_dir = os.path.join(LLVM_BUILD_DIR, 'lib', 'clang', RELEASE_VERSION,
  897. 'lib', rt_platform)
  898. # Make sure the directory exists; this will not be implicilty created if
  899. # built with per-target runtime directories.
  900. if not os.path.exists(rt_lib_dst_dir):
  901. os.makedirs(rt_lib_dst_dir)
  902. # Do an out-of-tree build of compiler-rt for 32-bit Win clang_rt.profile.lib.
  903. if sys.platform == 'win32':
  904. compiler_rt_build_dir = os.path.join(LLVM_BUILD_DIR, 'compiler-rt')
  905. if os.path.isdir(compiler_rt_build_dir):
  906. RmTree(compiler_rt_build_dir)
  907. os.makedirs(compiler_rt_build_dir)
  908. os.chdir(compiler_rt_build_dir)
  909. if args.bootstrap:
  910. # The bootstrap compiler produces 64-bit binaries by default.
  911. cflags += ['-m32']
  912. cxxflags += ['-m32']
  913. compiler_rt_args = base_cmake_args + [
  914. '-DCMAKE_C_FLAGS=' + ' '.join(cflags),
  915. '-DCMAKE_CXX_FLAGS=' + ' '.join(cxxflags),
  916. '-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(ldflags),
  917. '-DCMAKE_SHARED_LINKER_FLAGS=' + ' '.join(ldflags),
  918. '-DCMAKE_MODULE_LINKER_FLAGS=' + ' '.join(ldflags),
  919. '-DCOMPILER_RT_BUILD_BUILTINS=OFF',
  920. '-DCOMPILER_RT_BUILD_CRT=OFF',
  921. '-DCOMPILER_RT_BUILD_LIBFUZZER=OFF',
  922. '-DCOMPILER_RT_BUILD_MEMPROF=OFF',
  923. '-DCOMPILER_RT_BUILD_ORC=OFF',
  924. '-DCOMPILER_RT_BUILD_PROFILE=ON',
  925. '-DCOMPILER_RT_BUILD_SANITIZERS=OFF',
  926. '-DCOMPILER_RT_BUILD_XRAY=OFF',
  927. # The libxml2 we built above is 64-bit. Since it's only needed by
  928. # lld-link and not compiler-rt, just turn it off down here.
  929. '-DLLVM_ENABLE_LIBXML2=OFF',
  930. ]
  931. RunCommand(['cmake'] + compiler_rt_args +
  932. [os.path.join(LLVM_DIR, 'llvm')],
  933. msvc_arch='x86', env=deployment_env)
  934. RunCommand(['ninja', 'compiler-rt'], msvc_arch='x86')
  935. # Copy select output to the main tree.
  936. rt_lib_src_dir = os.path.join(compiler_rt_build_dir, 'lib', 'clang',
  937. RELEASE_VERSION, 'lib', rt_platform)
  938. # Static and dynamic libraries:
  939. CopyDirectoryContents(rt_lib_src_dir, rt_lib_dst_dir)
  940. if args.with_android:
  941. # TODO(thakis): Now that the NDK uses clang, try to build all archs in
  942. # one LLVM build instead of building 3 times.
  943. toolchain_dir = ANDROID_NDK_DIR + '/toolchains/llvm/prebuilt/linux-x86_64'
  944. for target_arch in ['aarch64', 'arm', 'i686', 'x86_64']:
  945. # Build compiler-rt runtimes needed for Android in a separate build tree.
  946. build_dir = os.path.join(LLVM_BUILD_DIR, 'android-' + target_arch)
  947. if not os.path.exists(build_dir):
  948. os.mkdir(os.path.join(build_dir))
  949. os.chdir(build_dir)
  950. target_triple = target_arch
  951. if target_arch == 'arm':
  952. target_triple = 'armv7'
  953. api_level = '19'
  954. if target_arch == 'aarch64' or target_arch == 'x86_64':
  955. api_level = '21'
  956. target_triple += '-linux-android' + api_level
  957. cflags = [
  958. '--target=' + target_triple,
  959. '--sysroot=%s/sysroot' % toolchain_dir,
  960. # pylint: disable=line-too-long
  961. # android_ndk/toolchains/llvm/prebuilt/linux-x86_64/aarch64-linux-android/bin/ld
  962. # depends on a newer version of libxml2.so than what's available on
  963. # the bots. To make things work, use our just-built lld as linker.
  964. # pylint: enable=line-too-long
  965. '-fuse-ld=lld',
  966. # We don't have an unwinder ready, and don't need it either.
  967. '--unwindlib=none',
  968. ]
  969. if target_arch == 'aarch64':
  970. # Use PAC/BTI instructions for AArch64
  971. cflags += [ '-mbranch-protection=standard' ]
  972. android_args = base_cmake_args + [
  973. '-DCMAKE_C_COMPILER=' + os.path.join(LLVM_BUILD_DIR, 'bin/clang'),
  974. '-DCMAKE_CXX_COMPILER=' + os.path.join(LLVM_BUILD_DIR, 'bin/clang++'),
  975. '-DLLVM_CONFIG_PATH=' + os.path.join(LLVM_BUILD_DIR, 'bin/llvm-config'),
  976. '-DCMAKE_C_FLAGS=' + ' '.join(cflags),
  977. '-DCMAKE_CXX_FLAGS=' + ' '.join(cflags),
  978. '-DCMAKE_ASM_FLAGS=' + ' '.join(cflags),
  979. '-DCOMPILER_RT_BUILD_BUILTINS=ON',
  980. '-DCOMPILER_RT_BUILD_CRT=OFF',
  981. '-DCOMPILER_RT_BUILD_LIBFUZZER=OFF',
  982. '-DCOMPILER_RT_BUILD_MEMPROF=OFF',
  983. '-DCOMPILER_RT_BUILD_ORC=OFF',
  984. '-DCOMPILER_RT_BUILD_PROFILE=OFF',
  985. '-DCOMPILER_RT_BUILD_SANITIZERS=OFF',
  986. '-DCOMPILER_RT_BUILD_XRAY=OFF',
  987. '-DSANITIZER_CXX_ABI=libcxxabi',
  988. '-DCMAKE_SHARED_LINKER_FLAGS=-Wl,-u__cxa_demangle',
  989. '-DANDROID=1'
  990. # These are necessary because otherwise CMake tries to build an
  991. # executable to test to see if the compiler is working, but in doing so,
  992. # it links against the builtins.a that we're about to build.
  993. '-DCMAKE_CXX_COMPILER_WORKS=ON',
  994. '-DCMAKE_C_COMPILER_WORKS=ON',
  995. '-DCMAKE_ASM_COMPILER_WORKS=ON',
  996. ]
  997. # First build the builtins and copy to the main build tree.
  998. RunCommand(['cmake'] +
  999. android_args +
  1000. [os.path.join(COMPILER_RT_DIR, 'lib', 'builtins')])
  1001. builtins_a = 'lib/linux/libclang_rt.builtins-%s-android.a' % target_arch
  1002. RunCommand(['ninja', builtins_a])
  1003. shutil.copy(builtins_a, rt_lib_dst_dir)
  1004. # With the builtins in place, we can build the other runtimes.
  1005. build_dir_2 = build_dir + '-phase2'
  1006. if not os.path.exists(build_dir_2):
  1007. os.mkdir(os.path.join(build_dir_2))
  1008. os.chdir(build_dir_2)
  1009. android_args.extend([
  1010. '-DCOMPILER_RT_BUILD_BUILTINS=OFF',
  1011. '-DCOMPILER_RT_USE_BUILTINS_LIBRARY=ON',
  1012. '-DCOMPILER_RT_BUILD_PROFILE=ON',
  1013. '-DCOMPILER_RT_BUILD_SANITIZERS=ON',
  1014. ])
  1015. RunCommand(['cmake'] + android_args + [COMPILER_RT_DIR])
  1016. libs_want = [
  1017. 'lib/linux/libclang_rt.asan-{0}-android.so',
  1018. 'lib/linux/libclang_rt.asan_static-{0}-android.a',
  1019. 'lib/linux/libclang_rt.ubsan_standalone-{0}-android.so',
  1020. 'lib/linux/libclang_rt.profile-{0}-android.a',
  1021. ]
  1022. # Only build HWASan for AArch64.
  1023. if target_arch == 'aarch64':
  1024. libs_want += ['lib/linux/libclang_rt.hwasan-{0}-android.so']
  1025. libs_want = [lib.format(target_arch) for lib in libs_want]
  1026. RunCommand(['ninja'] + libs_want)
  1027. # And copy them into the main build tree.
  1028. for p in libs_want:
  1029. shutil.copy(p, rt_lib_dst_dir)
  1030. if args.with_fuchsia:
  1031. # Fuchsia links against libclang_rt.builtins-<arch>.a instead of libgcc.a.
  1032. for target_arch in ['aarch64', 'x86_64']:
  1033. fuchsia_arch_name = {'aarch64': 'arm64', 'x86_64': 'x64'}[target_arch]
  1034. toolchain_dir = os.path.join(
  1035. FUCHSIA_SDK_DIR, 'arch', fuchsia_arch_name, 'sysroot')
  1036. # Build clang_rt runtime for Fuchsia in a separate build tree.
  1037. build_dir = os.path.join(LLVM_BUILD_DIR, 'fuchsia-' + target_arch)
  1038. if not os.path.exists(build_dir):
  1039. os.mkdir(os.path.join(build_dir))
  1040. os.chdir(build_dir)
  1041. target_spec = target_arch + '-unknown-fuchsia'
  1042. if args.build_mac_arm:
  1043. # Just-built clang can't run (it's an arm binary on an intel host), so
  1044. # use the bootstrap compiler instead.
  1045. host_path = LLVM_BOOTSTRAP_INSTALL_DIR
  1046. else:
  1047. host_path = LLVM_BUILD_DIR
  1048. # TODO(thakis): Might have to pass -B here once sysroot contains
  1049. # binaries (e.g. gas for arm64?)
  1050. fuchsia_args = base_cmake_args + [
  1051. '-DCMAKE_C_COMPILER=' + os.path.join(host_path, 'bin/clang'),
  1052. '-DCMAKE_CXX_COMPILER=' + os.path.join(host_path, 'bin/clang++'),
  1053. '-DCMAKE_LINKER=' + os.path.join(host_path, 'bin/clang'),
  1054. '-DCMAKE_AR=' + os.path.join(host_path, 'bin/llvm-ar'),
  1055. '-DLLVM_CONFIG_PATH=' + os.path.join(host_path, 'bin/llvm-config'),
  1056. '-DCMAKE_SYSTEM_NAME=Fuchsia',
  1057. '-DCMAKE_CXX_COMPILER_TARGET=' + target_spec,
  1058. '-DCMAKE_C_COMPILER_TARGET=' + target_spec,
  1059. '-DCMAKE_ASM_COMPILER_TARGET=' + target_spec,
  1060. '-DCOMPILER_RT_BUILD_BUILTINS=ON',
  1061. '-DCOMPILER_RT_BUILD_CRT=OFF',
  1062. '-DCOMPILER_RT_BUILD_LIBFUZZER=OFF',
  1063. '-DCOMPILER_RT_BUILD_MEMPROF=OFF',
  1064. '-DCOMPILER_RT_BUILD_ORC=OFF',
  1065. '-DCOMPILER_RT_BUILD_PROFILE=OFF',
  1066. '-DCOMPILER_RT_BUILD_SANITIZERS=OFF',
  1067. '-DCOMPILER_RT_BUILD_XRAY=OFF',
  1068. '-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON',
  1069. '-DCMAKE_SYSROOT=%s' % toolchain_dir,
  1070. # TODO(thakis|scottmg): Use PER_TARGET_RUNTIME_DIR for all platforms.
  1071. # https://crbug.com/882485.
  1072. '-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON',
  1073. # These are necessary because otherwise CMake tries to build an
  1074. # executable to test to see if the compiler is working, but in doing so,
  1075. # it links against the builtins.a that we're about to build.
  1076. '-DCMAKE_CXX_COMPILER_WORKS=ON',
  1077. '-DCMAKE_C_COMPILER_WORKS=ON',
  1078. '-DCMAKE_ASM_COMPILER_WORKS=ON',
  1079. ]
  1080. RunCommand(['cmake'] +
  1081. fuchsia_args +
  1082. [os.path.join(COMPILER_RT_DIR, 'lib', 'builtins')])
  1083. builtins_a = 'libclang_rt.builtins.a'
  1084. RunCommand(['ninja', builtins_a])
  1085. # And copy it into the main build tree.
  1086. fuchsia_lib_dst_dir = os.path.join(LLVM_BUILD_DIR, 'lib', 'clang',
  1087. RELEASE_VERSION, 'lib', target_spec)
  1088. if not os.path.exists(fuchsia_lib_dst_dir):
  1089. os.makedirs(fuchsia_lib_dst_dir)
  1090. CopyFile(os.path.join(build_dir, 'lib', target_spec, builtins_a),
  1091. fuchsia_lib_dst_dir)
  1092. # Build the Fuchsia profile and asan runtimes. This is done after the rt
  1093. # builtins have been created because the CMake build runs link checks that
  1094. # require that the builtins already exist to succeed.
  1095. # TODO(thakis): Figure out why this doesn't build with the stage0
  1096. # compiler in arm cross builds.
  1097. if target_arch == 'x86_64' and not args.build_mac_arm:
  1098. fuchsia_args.extend([
  1099. '-DCOMPILER_RT_BUILD_BUILTINS=OFF',
  1100. '-DCOMPILER_RT_BUILD_PROFILE=ON',
  1101. ])
  1102. # Build the asan runtime only on non-Mac platforms. Macs are excluded
  1103. # because the asan install changes library RPATHs which CMake only
  1104. # supports on ELF platforms and MacOS uses Mach-O instead of ELF.
  1105. if sys.platform != 'darwin':
  1106. fuchsia_args.extend([
  1107. '-DCOMPILER_RT_BUILD_SANITIZERS=ON',
  1108. '-DSANITIZER_NO_UNDEFINED_SYMBOLS=OFF',
  1109. ])
  1110. build_phase2_dir = os.path.join(LLVM_BUILD_DIR,
  1111. 'fuchsia-phase2-' + target_arch)
  1112. if not os.path.exists(build_phase2_dir):
  1113. os.mkdir(os.path.join(build_phase2_dir))
  1114. os.chdir(build_phase2_dir)
  1115. RunCommand(['cmake'] +
  1116. fuchsia_args +
  1117. [COMPILER_RT_DIR])
  1118. profile_a = 'libclang_rt.profile.a'
  1119. asan_preinit_a = 'libclang_rt.asan-preinit.a'
  1120. asan_static_a = 'libclang_rt.asan_static.a'
  1121. asan_so = 'libclang_rt.asan.so'
  1122. ninja_command = ['ninja', profile_a]
  1123. if sys.platform != 'darwin':
  1124. ninja_command.append(asan_so)
  1125. ninja_command.append(asan_preinit_a)
  1126. ninja_command.append(asan_static_a)
  1127. RunCommand(ninja_command)
  1128. CopyFile(os.path.join(build_phase2_dir, 'lib', target_spec, profile_a),
  1129. fuchsia_lib_dst_dir)
  1130. if sys.platform != 'darwin':
  1131. CopyFile(os.path.join(build_phase2_dir, 'lib', target_spec, asan_so),
  1132. fuchsia_lib_dst_dir)
  1133. CopyFile(
  1134. os.path.join(build_phase2_dir, 'lib', target_spec,
  1135. asan_preinit_a), fuchsia_lib_dst_dir)
  1136. CopyFile(
  1137. os.path.join(build_phase2_dir, 'lib', target_spec, asan_static_a),
  1138. fuchsia_lib_dst_dir)
  1139. # Run tests.
  1140. if (not args.build_mac_arm and
  1141. (args.run_tests or args.llvm_force_head_revision)):
  1142. RunCommand(['ninja', '-C', LLVM_BUILD_DIR, 'cr-check-all'], msvc_arch='x64')
  1143. if not args.build_mac_arm and args.run_tests:
  1144. test_targets = [ 'check-all' ]
  1145. if sys.platform == 'darwin':
  1146. # TODO(thakis): Run check-all on Darwin too, https://crbug.com/959361
  1147. test_targets = [ 'check-llvm', 'check-clang', 'check-lld' ]
  1148. RunCommand(['ninja', '-C', LLVM_BUILD_DIR] + test_targets, msvc_arch='x64')
  1149. WriteStampFile(PACKAGE_VERSION, STAMP_FILE)
  1150. WriteStampFile(PACKAGE_VERSION, FORCE_HEAD_REVISION_FILE)
  1151. print('Clang build was successful.')
  1152. return 0
  1153. if __name__ == '__main__':
  1154. sys.exit(main())