• 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
17REPO = "https://llvm.googlesource.com/"
18BRANCH = "release_90"
19
20def create_asset(target_dir):
21  # CMake will sometimes barf if we pass it a relative path.
22  target_dir = os.path.abspath(target_dir)
23
24  # Build Clang, lld, compiler-rt (sanitizer support) and libc++.
25  os.chdir(tempfile.mkdtemp())
26  subprocess.check_call(["git", "clone", "--depth", "1", "-b",
27                         BRANCH, REPO + "llvm"])
28  os.chdir("llvm/tools")
29  subprocess.check_call(["git", "clone", "--depth", "1", "-b",
30                         BRANCH, REPO + "clang"])
31  subprocess.check_call(["git", "clone", "--depth", "1", "-b",
32                         BRANCH, REPO + "lld"])
33  os.chdir("clang/tools")
34  subprocess.check_call(["git", "clone", "--depth", "1", "-b",
35                         BRANCH, REPO + "clang-tools-extra", "extra"])
36
37  os.chdir("../../../projects")
38  subprocess.check_call(["git", "clone", "--depth", "1", "-b",
39                         BRANCH, REPO + "compiler-rt"])
40  subprocess.check_call(["git", "clone", "--depth", "1", "-b",
41                         BRANCH, REPO + "libcxx"])
42  subprocess.check_call(["git", "clone", "--depth", "1", "-b",
43                         BRANCH, REPO + "libcxxabi"])
44  os.chdir("..")
45  os.mkdir("out")
46  os.chdir("out")
47  subprocess.check_call(["cmake", "..", "-G", "Ninja",
48                         "-DCMAKE_BUILD_TYPE=MinSizeRel",
49                         "-DCMAKE_INSTALL_PREFIX=" + target_dir,
50                         "-DLLVM_INSTALL_TOOLCHAIN_ONLY=ON",
51                         "-DLLVM_ENABLE_TERMINFO=OFF"])
52  subprocess.check_call(["ninja", "install"])
53
54  # Copy a couple extra files we need.
55  subprocess.check_call(["cp", "bin/llvm-symbolizer", target_dir + "/bin"])
56  subprocess.check_call(["cp", "bin/llvm-profdata", target_dir + "/bin"])
57  subprocess.check_call(["cp", "bin/llvm-cov", target_dir + "/bin"])
58  libstdcpp = subprocess.check_output(["c++",
59                                       "-print-file-name=libstdc++.so.6"])
60  subprocess.check_call(["cp", libstdcpp.strip(), target_dir + "/lib"])
61
62  # Finally, build libc++ for TSAN and MSAN bots using the Clang we just built.
63  for (short,full) in [('tsan','Thread'), ('msan','MemoryWithOrigins')]:
64    os.mkdir("../{}_out".format(short))
65    os.chdir("../{}_out".format(short))
66    subprocess.check_call(
67        ["cmake", "..", "-G", "Ninja",
68         "-DCMAKE_BUILD_TYPE=MinSizeRel",
69         "-DCMAKE_C_COMPILER="   + target_dir + "/bin/clang",
70         "-DCMAKE_CXX_COMPILER=" + target_dir + "/bin/clang++",
71         "-DLLVM_USE_SANITIZER={}".format(full)])
72    subprocess.check_call(["ninja", "cxx"])
73    subprocess.check_call(["cp", "-r", "lib",  target_dir + "/" + short])
74
75
76def main():
77  parser = argparse.ArgumentParser()
78  parser.add_argument('--target_dir', '-t', required=True)
79  args = parser.parse_args()
80  create_asset(args.target_dir)
81
82
83if __name__ == '__main__':
84  main()
85