xref: /aosp_15_r20/external/cronet/build/config/siso/clang_linux.star (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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/linux."""
6
7load("@builtin//path.star", "path")
8load("@builtin//struct.star", "module")
9load("./android.star", "android")
10load("./clang_all.star", "clang_all")
11load("./clang_code_coverage_wrapper.star", "clang_code_coverage_wrapper")
12load("./config.star", "config")
13load("./cros.star", "cros")
14
15# TODO: b/323091468 - Propagate target android ABI and android SDK version
16# from GN, and remove the hardcoded filegroups.
17android_archs = [
18    "aarch64-linux-android",
19    "arm-linux-androideabi",
20    "i686-linux-android",
21    "riscv64-linux-android",
22    "x86_64-linux-android",
23]
24
25android_versions = list(range(21, 35))
26
27def __filegroups(ctx):
28    fg = {
29        # for precomputed subtrees
30        "build/linux/debian_bullseye_amd64-sysroot/usr/include:include": {
31            "type": "glob",
32            "includes": ["*"],
33            # need bits/stab.def, c++/*
34        },
35        "build/linux/debian_bullseye_amd64-sysroot/usr/lib:headers": {
36            "type": "glob",
37            "includes": ["*.h", "crtbegin.o"],
38        },
39        "build/linux/debian_bullseye_i386-sysroot/usr/include:include": {
40            "type": "glob",
41            "includes": ["*"],
42            # need bits/stab.def, c++/*
43        },
44        "build/linux/debian_bullseye_i386-sysroot/usr/lib:headers": {
45            "type": "glob",
46            "includes": ["*.h", "crtbegin.o"],
47        },
48        "third_party/android_toolchain/ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include:include": {
49            "type": "glob",
50            "includes": ["*"],
51            # can't use "*.h", because c++ headers have no extension.
52        },
53        "third_party/android_toolchain/ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/local/include:include": {
54            "type": "glob",
55            "includes": ["*"],
56        },
57        "third_party/llvm-build/Release+Asserts/lib/clang:libs": {
58            "type": "glob",
59            "includes": ["*/lib/*/*", "*/lib/*", "*/share/*"],
60        },
61        "build/linux/debian_bullseye_amd64-sysroot/lib/x86_64-linux-gnu:libso": {
62            "type": "glob",
63            "includes": ["*.so*"],
64        },
65        "build/linux/debian_bullseye_amd64-sysroot/usr/lib/x86_64-linux-gnu:libs": {
66            "type": "glob",
67            "includes": ["*.o", "*.so*", "lib*.a"],
68        },
69        "build/linux/debian_bullseye_amd64-sysroot/usr/lib/gcc/x86_64-linux-gnu:libgcc": {
70            "type": "glob",
71            "includes": ["*.o", "*.a", "*.so"],
72        },
73    }
74    if android.enabled(ctx):
75        for arch in android_archs:
76            for ver in android_versions:
77                group = "third_party/android_toolchain/ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/%s/%d:link" % (arch, ver)
78                fg[group] = {
79                    "type": "glob",
80                    "includes": ["*"],
81                }
82
83    fg.update(clang_all.filegroups(ctx))
84    return fg
85
86def __clang_compile_coverage(ctx, cmd):
87    clang_command = clang_code_coverage_wrapper.run(ctx, list(cmd.args))
88    ctx.actions.fix(args = clang_command)
89
90__handlers = {
91    "clang_compile_coverage": __clang_compile_coverage,
92}
93
94def __step_config(ctx, step_config):
95    step_config["input_deps"].update({
96        # sysroot headers for precomputed subtrees
97        "build/linux/debian_bullseye_amd64-sysroot:headers": [
98            "build/linux/debian_bullseye_amd64-sysroot/usr/include:include",
99            "build/linux/debian_bullseye_amd64-sysroot/usr/lib:headers",
100        ],
101        "build/linux/debian_bullseye_i386-sysroot:headers": [
102            "build/linux/debian_bullseye_i386-sysroot/usr/include:include",
103            "build/linux/debian_bullseye_i386-sysroot/usr/lib:headers",
104        ],
105        "build/linux/debian_bullseye_amd64-sysroot:link": [
106            "build/linux/debian_bullseye_amd64-sysroot/lib/x86_64-linux-gnu:libso",
107            "build/linux/debian_bullseye_amd64-sysroot/lib64/ld-linux-x86-64.so.2",
108            "build/linux/debian_bullseye_amd64-sysroot/usr/lib/gcc/x86_64-linux-gnu:libgcc",
109            "build/linux/debian_bullseye_amd64-sysroot/usr/lib/x86_64-linux-gnu:libs",
110            "third_party/llvm-build/Release+Asserts/bin/clang",
111            "third_party/llvm-build/Release+Asserts/bin/clang++",
112            "third_party/llvm-build/Release+Asserts/bin/ld.lld",
113            "third_party/llvm-build/Release+Asserts/bin/lld",
114            "third_party/llvm-build/Release+Asserts/bin/llvm-nm",
115            "third_party/llvm-build/Release+Asserts/bin/llvm-readelf",
116            "third_party/llvm-build/Release+Asserts/bin/llvm-readobj",
117            # The following inputs are used for sanitizer builds.
118            # It might be better to add them only for sanitizer builds if there is a performance issue.
119            "third_party/llvm-build/Release+Asserts/lib/clang:libs",
120        ],
121        "third_party/android_toolchain/ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot:headers": [
122            "third_party/android_toolchain/ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include:include",
123            "third_party/android_toolchain/ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/local/include:include",
124        ],
125    })
126    step_config["input_deps"].update(clang_all.input_deps)
127    step_config["rules"].extend([
128        {
129            "name": "clang/cxx",
130            "action": "(.*_)?cxx",
131            "command_prefix": "../../third_party/llvm-build/Release+Asserts/bin/clang++ ",
132            "inputs": [
133                "third_party/llvm-build/Release+Asserts/bin/clang++",
134            ],
135            "exclude_input_patterns": ["*.stamp"],
136            "remote": True,
137            "canonicalize_dir": True,
138            "timeout": "2m",
139        },
140        {
141            "name": "clang/cc",
142            "action": "(.*_)?cc",
143            "command_prefix": "../../third_party/llvm-build/Release+Asserts/bin/clang ",
144            "inputs": [
145                "third_party/llvm-build/Release+Asserts/bin/clang",
146            ],
147            "exclude_input_patterns": ["*.stamp"],
148            "remote": True,
149            "canonicalize_dir": True,
150            "timeout": "2m",
151        },
152        {
153            "name": "clang/asm",
154            "action": "(.*_)?asm",
155            "command_prefix": "../../third_party/llvm-build/Release+Asserts/bin/clang",
156            "inputs": [
157                "third_party/llvm-build/Release+Asserts/bin/clang",
158            ],
159            "remote": config.get(ctx, "cog"),
160            "canonicalize_dir": True,
161            "timeout": "2m",
162        },
163        {
164            "name": "clang-coverage/cxx",
165            "action": "(.*_)?cxx",
166            "command_prefix": "\"python3\" ../../build/toolchain/clang_code_coverage_wrapper.py",
167            "inputs": [
168                "third_party/llvm-build/Release+Asserts/bin/clang++",
169            ],
170            "exclude_input_patterns": ["*.stamp"],
171            "handler": "clang_compile_coverage",
172            "remote": True,
173            "canonicalize_dir": True,
174            "timeout": "2m",
175        },
176        {
177            "name": "clang-coverage/cc",
178            "action": "(.*_)?cc",
179            "command_prefix": "\"python3\" ../../build/toolchain/clang_code_coverage_wrapper.py",
180            "inputs": [
181                "third_party/llvm-build/Release+Asserts/bin/clang",
182            ],
183            "exclude_input_patterns": ["*.stamp"],
184            "handler": "clang_compile_coverage",
185            "remote": True,
186            "canonicalize_dir": True,
187            "timeout": "2m",
188        },
189    ])
190
191    # TODO: b/316267242 - Enable remote links for Android and CrOS toolchain builds.
192    if not android.enabled(ctx) and not (cros.custom_toolchain(ctx) or cros.custom_sysroot(ctx)):
193        step_config["rules"].extend([
194            {
195                "name": "clang/alink/llvm-ar",
196                "action": "(.*_)?alink",
197                "inputs": [
198                    # TODO: b/316267242 - Add inputs to GN config.
199                    "third_party/llvm-build/Release+Asserts/bin/llvm-ar",
200                ],
201                "exclude_input_patterns": [
202                    "*.cc",
203                    "*.h",
204                    "*.js",
205                    "*.pak",
206                    "*.py",
207                    "*.stamp",
208                ],
209                "remote": config.get(ctx, "remote-library-link"),
210                "canonicalize_dir": True,
211                "platform_ref": "large",
212                "accumulate": True,
213            },
214            {
215                "name": "clang/solink/gcc_solink_wrapper",
216                "action": "(.*_)?solink",
217                "command_prefix": "\"python3\" \"../../build/toolchain/gcc_solink_wrapper.py\"",
218                "inputs": [
219                    # TODO: b/316267242 - Add inputs to GN config.
220                    "build/toolchain/gcc_solink_wrapper.py",
221                    "build/toolchain/whole_archive.py",
222                    "build/toolchain/wrapper_utils.py",
223                    "build/linux/debian_bullseye_amd64-sysroot:link",
224                ],
225                "exclude_input_patterns": [
226                    "*.cc",
227                    "*.h",
228                    "*.js",
229                    "*.pak",
230                    "*.py",
231                    "*.stamp",
232                ],
233                "remote": config.get(ctx, "remote-library-link"),
234                "canonicalize_dir": True,
235                "platform_ref": "large",
236            },
237            {
238                "name": "clang/link/gcc_link_wrapper",
239                "action": "(.*_)?link",
240                "command_prefix": "\"python3\" \"../../build/toolchain/gcc_link_wrapper.py\"",
241                "inputs": [
242                    # TODO: b/316267242 - Add inputs to GN config.
243                    "build/toolchain/gcc_link_wrapper.py",
244                    "build/toolchain/whole_archive.py",
245                    "build/toolchain/wrapper_utils.py",
246                    "build/linux/debian_bullseye_amd64-sysroot:link",
247                ],
248                "exclude_input_patterns": [
249                    "*.cc",
250                    "*.h",
251                    "*.js",
252                    "*.pak",
253                    "*.py",
254                    "*.stamp",
255                ],
256                "remote": config.get(ctx, "remote-exec-link"),
257                "canonicalize_dir": True,
258                "platform_ref": "large",
259                "timeout": "10m",
260            },
261        ])
262    return step_config
263
264clang = module(
265    "clang",
266    step_config = __step_config,
267    filegroups = __filegroups,
268    handlers = __handlers,
269)
270