• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2#
3# Copyright 2016 Google Inc.
4#
5# Use of this source code is governed by a BSD-style license that can be
6# found in the LICENSE file.
7
8
9"""Create a Clang toolchain for Linux hosts."""
10
11
12import argparse
13import os
14import subprocess
15import tempfile
16
17BRANCH = "release/10.x"
18
19def create_asset(target_dir):
20  # CMake will sometimes barf if we pass it a relative path.
21  target_dir = os.path.abspath(target_dir)
22
23  # Build Clang, lld, compiler-rt (sanitizer support) and libc++.
24  os.chdir(tempfile.mkdtemp())
25  subprocess.check_call(["git", "clone", "--depth", "1", "-b", BRANCH,
26                         "https://llvm.googlesource.com/llvm-project"])
27  os.chdir("llvm-project")
28  os.mkdir("out")
29  os.chdir("out")
30  subprocess.check_call(["cmake", "../llvm", "-G", "Ninja",
31                         "-DCMAKE_BUILD_TYPE=MinSizeRel",
32                         "-DCMAKE_INSTALL_PREFIX=" + target_dir,
33                         "-DLLVM_ENABLE_PROJECTS=clang;clang-tools-extra;" +
34                             "compiler-rt;libcxx;libcxxabi;lld",
35                         "-DLLVM_INSTALL_TOOLCHAIN_ONLY=ON",
36                         "-DLLVM_ENABLE_TERMINFO=OFF"])
37  subprocess.check_call(["ninja", "install"])
38
39  # Copy a couple extra files we need.
40  subprocess.check_call(["cp", "bin/llvm-symbolizer", target_dir + "/bin"])
41  subprocess.check_call(["cp", "bin/llvm-profdata", target_dir + "/bin"])
42  subprocess.check_call(["cp", "bin/llvm-cov", target_dir + "/bin"])
43  libstdcpp = subprocess.check_output(["c++",
44                                       "-print-file-name=libstdc++.so.6"])
45  subprocess.check_call(["cp", libstdcpp.strip(), target_dir + "/lib"])
46
47  # Finally, build libc++ for TSAN and MSAN bots using the Clang we just built.
48  for (short,full) in [('tsan','Thread'), ('msan','MemoryWithOrigins')]:
49    os.mkdir("../{}_out".format(short))
50    os.chdir("../{}_out".format(short))
51    subprocess.check_call(
52        ["cmake", "../llvm", "-G", "Ninja",
53         "-DCMAKE_BUILD_TYPE=MinSizeRel",
54         "-DCMAKE_C_COMPILER="   + target_dir + "/bin/clang",
55         "-DCMAKE_CXX_COMPILER=" + target_dir + "/bin/clang++",
56         "-DLLVM_ENABLE_PROJECTS=libcxx;libcxxabi",
57         "-DLLVM_USE_SANITIZER={}".format(full)])
58    subprocess.check_call(["ninja", "cxx"])
59    subprocess.check_call(["cp", "-r", "lib",  target_dir + "/" + short])
60
61
62def main():
63  parser = argparse.ArgumentParser()
64  parser.add_argument('--target_dir', '-t', required=True)
65  args = parser.parse_args()
66  create_asset(args.target_dir)
67
68
69if __name__ == '__main__':
70  main()
71