xref: /aosp_15_r20/external/pigweed/pw_toolchain_bazel/build_external/llvm_clang_legacy.BUILD (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1# Copyright 2024 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
15load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
16load(
17    "@pw_toolchain//cc_toolchain:defs.bzl",
18    "pw_cc_action_config",
19    "pw_cc_tool",
20)
21
22package(default_visibility = ["//visibility:public"])
23
24licenses(["notice"])
25
26# This build file defines a complete set of tools for a LLVM-based toolchain.
27
28exports_files(glob(["**"]))
29
30filegroup(
31    name = "all",
32    srcs = glob(["**"]),
33    visibility = ["//visibility:public"],
34)
35
36filegroup(
37    name = "llvm-libc_arm-none-eabi_compile_files",
38    srcs = glob([
39        "include/armv*-unknown-none-eabi/**",
40    ]),
41    visibility = ["//visibility:public"],
42)
43
44filegroup(
45    name = "llvm-libc_arm-none-eabi_link_files",
46    srcs = glob([
47        "lib/armv*-unknown-none-eabi/**",
48        "lib/clang/*/lib/armv*-unknown-none-eabi/**",
49    ]),
50    visibility = ["//visibility:public"],
51)
52
53# TODO(amontanez): Add sysroot for macos to the `data` field selection once
54# Pigweed migrates to use rules_cc toolchains.
55native_binary(
56    name = "clang-tidy",
57    src = select({
58        "@platforms//os:windows": "//:bin/clang-tidy.exe",
59        "//conditions:default": "//:bin/clang-tidy",
60    }),
61    data = glob([
62        "include/**",
63        "lib/clang/**/include/**",
64    ]) + select({
65        "@platforms//os:linux": ["@linux_sysroot//:sysroot"],
66        "//conditions:default": [],
67    }),
68    out = select({
69        "@platforms//os:windows": "clang-tidy.exe",
70        "//conditions:default": "clang-tidy",
71    }),
72    visibility = ["//visibility:public"],
73)
74
75pw_cc_tool(
76    name = "ar_tool",
77    tool = select({
78        "@platforms//os:windows": "//:bin/llvm-ar.exe",
79        "//conditions:default": "//:bin/llvm-ar",
80    }),
81    additional_files = glob(["bin/llvm"]),
82)
83
84pw_cc_tool(
85    name = "llvm_libtool_darwin_tool",
86    tool = "//:bin/llvm-libtool-darwin",
87    additional_files = glob(["bin/llvm"]),
88)
89
90pw_cc_action_config(
91    name = "ar",
92    action_names = ["@pw_toolchain//actions:all_ar_actions"],
93    # Unlike most legacy features required to compile code, these features
94    # aren't enabled by default, and are instead only implied by the built-in
95    # action configs. We imply the features here to match the behavior of the
96    # built-in action configs so flags are actually passed to `ar`.
97    implies = [
98        "@pw_toolchain//features/legacy:archiver_flags",
99        "@pw_toolchain//features/legacy:linker_param_file",
100    ],
101    tools = select({
102        "@platforms//os:macos": [":llvm_libtool_darwin_tool"],
103        "//conditions:default": [":ar_tool"],
104    }),
105)
106
107pw_cc_tool(
108    name = "clang++_tool",
109    tool = select({
110        "@platforms//os:windows": "//:bin/clang++.exe",
111        "//conditions:default": "//:bin/clang++",
112    }),
113    additional_files = glob([
114        "bin/llvm",
115        "include/**",
116        "lib/clang/**/include/**",
117    ]),
118)
119
120pw_cc_action_config(
121    name = "clang++",
122    action_names = ["@pw_toolchain//actions:all_cpp_compiler_actions"],
123    tools = [":clang++_tool"],
124)
125
126pw_cc_tool(
127    name = "clang_tool",
128    tool = select({
129        "@platforms//os:windows": "//:bin/clang.exe",
130        "//conditions:default": "//:bin/clang",
131    }),
132    additional_files = glob([
133        "bin/llvm",
134        "include/**",
135        "lib/clang/**/include/**",
136    ]),
137)
138
139pw_cc_action_config(
140    name = "clang",
141    action_names = [
142        "@pw_toolchain//actions:all_asm_actions",
143        "@pw_toolchain//actions:all_c_compiler_actions",
144    ],
145    tools = [":clang_tool"],
146)
147
148# This tool is actually just clang++ under the hood, we just enumerate this
149# tool differently to specify a different set of additional files.
150pw_cc_tool(
151    name = "lld_tool",
152    tool = select({
153        "@platforms//os:windows": "//:bin/clang++.exe",
154        "//conditions:default": "//:bin/clang++",
155    }),
156    additional_files = glob([
157        "bin/llvm",
158        "bin/lld*",
159        "bin/ld*",
160        "lib/**/*.a",
161        "lib/**/*.so*",
162        "lib/**/*.o",
163    ]),
164)
165
166pw_cc_action_config(
167    name = "lld",
168    action_names = ["@pw_toolchain//actions:all_link_actions"],
169    tools = [":lld_tool"],
170)
171
172pw_cc_tool(
173    name = "llvm_cov_tool",
174    tool = select({
175        "@platforms//os:windows": "//:bin/llvm-cov.exe",
176        "//conditions:default": "//:bin/llvm-cov",
177    }),
178    additional_files = glob(["bin/llvm"]),
179)
180
181pw_cc_action_config(
182    name = "llvm-cov",
183    action_names = ["@pw_toolchain//actions:all_coverage_actions"],
184    tools = [":llvm_cov_tool"],
185)
186
187pw_cc_tool(
188    name = "llvm_objcopy_tool",
189    tool = select({
190        "@platforms//os:windows": "//:bin/llvm-objcopy.exe",
191        "//conditions:default": "//:bin/llvm-objcopy",
192    }),
193    additional_files = glob(["bin/llvm"]),
194)
195
196pw_cc_action_config(
197    name = "llvm-objcopy",
198    action_names = ["@pw_toolchain//actions:all_objcopy_actions"],
199    tools = [":llvm_objcopy_tool"],
200)
201
202pw_cc_tool(
203    name = "llvm_objdump_tool",
204    tool = select({
205        "@platforms//os:windows": "//:bin/llvm-objdump.exe",
206        "//conditions:default": "//:bin/llvm-objdump",
207    }),
208    additional_files = glob(["bin/llvm"]),
209)
210
211pw_cc_action_config(
212    name = "llvm-objdump",
213    action_names = ["@pw_toolchain//actions:all_objdump_actions"],
214    tools = [":llvm_objdump_tool"],
215)
216
217pw_cc_tool(
218    name = "llvm_strip_tool",
219    tool = select({
220        "@platforms//os:windows": "//:bin/llvm-strip.exe",
221        "//conditions:default": "//:bin/llvm-strip",
222    }),
223    additional_files = glob(["bin/llvm"]),
224)
225
226pw_cc_action_config(
227    name = "llvm-strip",
228    action_names = ["@pw_toolchain//actions:all_strip_actions"],
229    tools = [":llvm_strip_tool"],
230)
231