clang_all.star (8008B)
1 # -*- bazel-starlark -*- 2 # Copyright 2023 The Chromium Authors 3 # Use of this source code is governed by a BSD-style license that can be 4 # found in the LICENSE file. 5 """Siso configuration for clang.""" 6 7 load("@builtin//path.star", "path") 8 load("@builtin//struct.star", "module") 9 load("./ar.star", "ar") 10 load("./config.star", "config") 11 load("./mac_sdk.star", "mac_sdk") 12 load("./win_sdk.star", "win_sdk") 13 14 def __filegroups(ctx): 15 fg = { 16 "third_party/libc++/src/include:headers": { 17 "type": "glob", 18 "includes": ["*"], 19 # can't use "*.h", because c++ headers have no extension. 20 }, 21 "third_party/libc++abi/src/include:headers": { 22 "type": "glob", 23 "includes": ["*.h"], 24 }, 25 # vendor provided headers for libc++. 26 "buildtools/third_party/libc++:headers": { 27 "type": "glob", 28 "includes": [ 29 "__*", 30 ], 31 }, 32 33 # toolchain root 34 # :headers for compiling 35 "third_party/llvm-build/Release+Asserts:headers": { 36 "type": "glob", 37 "includes": [ 38 "*.h", 39 "*.modulemap", 40 "bin/clang", 41 "bin/clang++", 42 "bin/clang-*", # clang-cl, clang-<ver> 43 "*_ignorelist.txt", 44 # https://crbug.com/335997052 45 "clang_rt.profile*.lib", 46 ], 47 }, 48 "third_party/cronet_android_mainline_clang/linux-amd64:headers": { 49 "type": "glob", 50 "includes": [ 51 "*.h", 52 "*.modulemap", 53 "bin/clang*", 54 ], 55 }, 56 "third_party/cronet_android_mainline_clang/linux-amd64:link": { 57 "type": "glob", 58 "includes": [ 59 "bin/clang*", 60 "bin/ld.lld", 61 "bin/lld", 62 "bin/llvm-nm", 63 "bin/llvm-objcopy", 64 "bin/llvm-readelf", 65 "bin/llvm-readobj", 66 "bin/llvm-strip", 67 "*.so", 68 "*.so.*", 69 "*.a", 70 ], 71 }, 72 } 73 if win_sdk.enabled(ctx): 74 fg.update(win_sdk.filegroups(ctx)) 75 if mac_sdk.enabled(ctx): 76 fg.update(mac_sdk.filegroups(ctx)) 77 return fg 78 79 __input_deps = { 80 # need this because we use 81 # third_party/libc++/src/include:headers, 82 # but scandeps doesn't scan `__config` file, which uses 83 # `#include <__config_site>` 84 # also need `__assertion_handler`. b/321171148 85 "third_party/libc++/src/include": [ 86 "buildtools/third_party/libc++:headers", 87 ], 88 "third_party/llvm-build/Release+Asserts/bin/clang": [ 89 "build/config/unsafe_buffers_paths.txt", 90 "build/config/warning_suppression.txt", 91 ], 92 "third_party/llvm-build/Release+Asserts/bin/clang++": [ 93 "build/config/unsafe_buffers_paths.txt", 94 "build/config/warning_suppression.txt", 95 ], 96 "third_party/llvm-build/Release+Asserts/bin/clang-cl": [ 97 "build/config/unsafe_buffers_paths.txt", 98 "build/config/warning_suppression.txt", 99 ], 100 "third_party/llvm-build/Release+Asserts/bin/clang-cl.exe": [ 101 "build/config/unsafe_buffers_paths.txt", 102 "build/config/warning_suppression.txt", 103 ], 104 "third_party/llvm-build/Release+Asserts/bin/lld-link": [ 105 "build/config/c++/libc++.natvis", 106 "build/win/as_invoker.manifest", 107 "build/win/common_controls.manifest", 108 "build/win/compatibility.manifest", 109 "build/win/require_administrator.manifest", 110 "build/win/segment_heap.manifest", 111 "remoting/host/win/dpi_aware.manifest", 112 "third_party/llvm-build/Release+Asserts/bin/lld", 113 "tools/win/DebugVisualizers/blink.natvis", 114 "tools/win/DebugVisualizers/chrome.natvis", 115 ], 116 "third_party/llvm-build/Release+Asserts/bin/lld-link.exe": [ 117 "build/config/c++/libc++.natvis", 118 "build/win/as_invoker.manifest", 119 "build/win/common_controls.manifest", 120 "build/win/compatibility.manifest", 121 "build/win/require_administrator.manifest", 122 "build/win/segment_heap.manifest", 123 "remoting/host/win/dpi_aware.manifest", 124 "third_party/llvm-build/Release+Asserts/bin/lld.exe", 125 "tools/win/DebugVisualizers/blink.natvis", 126 "tools/win/DebugVisualizers/chrome.natvis", 127 ], 128 "build/toolchain/gcc_solink_wrapper.py": [ 129 "build/toolchain/whole_archive.py", 130 "build/toolchain/wrapper_utils.py", 131 ], 132 "build/toolchain/gcc_solink_wrapper.py:link": [ 133 "build/toolchain/gcc_solink_wrapper.py", 134 "build/toolchain/whole_archive.py", 135 "build/toolchain/wrapper_utils.py", 136 ], 137 "build/toolchain/gcc_link_wrapper.py": [ 138 "build/toolchain/whole_archive.py", 139 "build/toolchain/wrapper_utils.py", 140 ], 141 "build/toolchain/gcc_link_wrapper.py:link": [ 142 "build/toolchain/gcc_link_wrapper.py", 143 "build/toolchain/whole_archive.py", 144 "build/toolchain/wrapper_utils.py", 145 ], 146 "build/toolchain/apple/linker_driver.py:link": [ 147 "build/toolchain/apple/linker_driver.py", 148 "build/toolchain/whole_archive.py", 149 ], 150 "build/toolchain/apple/solink_driver.py:link": [ 151 "build/toolchain/apple/linker_driver.py", 152 "build/toolchain/apple/solink_driver.py", 153 "build/toolchain/whole_archive.py", 154 ], 155 } 156 157 def __lld_link(ctx, cmd): 158 # Replace thin archives with /start-lib ... /end-lib in rsp file. 159 new_lines = [] 160 for line in str(cmd.rspfile_content).split("\n"): 161 new_elems = [] 162 for elem in line.split(" "): 163 # Parse only .lib files. 164 if not elem.endswith(".lib"): 165 new_elems.append(elem) 166 continue 167 168 # Parse files under the out dir. 169 fname = ctx.fs.canonpath(elem) 170 if not ctx.fs.exists(fname): 171 new_elems.append(elem) 172 continue 173 174 # Check if the library is generated or not. 175 # The source libs are not under the build dir. 176 build_dir = ctx.fs.canonpath("./") 177 if path.rel(build_dir, fname).startswith("../../"): 178 new_elems.append(elem) 179 continue 180 181 ents = ar.entries(ctx, fname, build_dir) 182 if not ents: 183 new_elems.append(elem) 184 continue 185 186 new_elems.append("-start-lib") 187 new_elems.extend(ents) 188 new_elems.append("-end-lib") 189 new_lines.append(" ".join(new_elems)) 190 191 ctx.actions.fix(rspfile_content = "\n".join(new_lines)) 192 193 def __thin_archive(ctx, cmd): 194 # TODO: This handler can be used despite remote linking? 195 if not config.get(ctx, "remote-link"): 196 return 197 if "lld-link" in cmd.args[0]: 198 if not "/llvmlibthin" in cmd.args: 199 print("not thin archive") 200 return 201 else: 202 # check command line to see "-T" and "-S". 203 # rm -f obj/third_party/angle/libangle_common.a && "../../third_party/llvm-build/Release+Asserts/bin/llvm-ar" -T -S -r -c -D obj/third_party/angle/libangle_common.a @"obj/third_party/angle/libangle_common.a.rsp" 204 if not ("-T" in cmd.args[-1] and "-S" in cmd.args[-1]): 205 print("not thin archive without symbol table") 206 return 207 208 # create thin archive without symbol table by handler. 209 rspfile_content = str(cmd.rspfile_content) 210 inputs = [] 211 for line in rspfile_content.split("\n"): 212 for fname in line.split(" "): 213 inputs.append(ctx.fs.canonpath(fname)) 214 data = ar.create(ctx, path.dir(cmd.outputs[0]), inputs) 215 ctx.actions.write(cmd.outputs[0], data) 216 ctx.actions.exit(exit_status = 0) 217 218 __handlers = { 219 "lld_link": __lld_link, 220 "lld_thin_archive": __thin_archive, 221 } 222 223 clang_all = module( 224 "clang_all", 225 filegroups = __filegroups, 226 input_deps = __input_deps, 227 handlers = __handlers, 228 )