blob: db27b19ed598998ebba494977b8fb5e4e2421ca4 [file] [log] [blame]
hlopkobea9d252019-11-15 07:30:16 -08001# Copyright 2018 The Bazel Authors. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://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,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15package(default_visibility = ["//visibility:public"])
16
17licenses(["notice"]) # Apache 2.0
18
19load(":cc_toolchain_config.bzl", "cc_toolchain_config")
20load("@rules_cc//cc:defs.bzl", "cc_library", "cc_toolchain", "cc_toolchain_suite")
21
22# The toolchain type used to distinguish cc toolchains.
23toolchain_type(name = "toolchain_type")
24
25# It is frequently necessary to constrain platforms based on the cc compiler type.
26constraint_setting(name = "cc_compiler")
27
28constraint_value(
29 name = "clang",
30 constraint_setting = ":cc_compiler",
31)
32
33constraint_value(
34 name = "gcc",
35 constraint_setting = ":cc_compiler",
36)
37
38constraint_value(
39 name = "msvc",
40 constraint_setting = ":cc_compiler",
41)
42
43constraint_value(
44 name = "clang-cl",
45 constraint_setting = ":cc_compiler",
46)
47
48constraint_value(
49 name = "mingw",
50 constraint_setting = ":cc_compiler",
51)
52
53constraint_value(
54 name = "msys",
55 constraint_setting = ":cc_compiler",
56)
57
58cc_toolchain_alias(name = "current_cc_toolchain")
59
60cc_host_toolchain_alias(name = "current_cc_host_toolchain")
61
62cc_libc_top_alias(name = "current_libc_top")
63
64cc_library(
65 name = "malloc",
66)
67
68filegroup(
69 name = "grep-includes",
70 srcs = ["grep-includes.sh"],
71)
72
73filegroup(
74 name = "empty",
75 srcs = [],
76)
77
78config_setting(
79 name = "disable_static_cc_toolchains",
80 values = {
81 "incompatible_disable_static_cc_toolchains": "true",
82 },
83)
84
85# This is the entry point for --crosstool_top. Toolchains are found
86# by lopping off the name of --crosstool_top and searching for
87# "cc-compiler-${CPU}" in this BUILD file, where CPU is the target CPU
88# specified in --cpu.
89#
90# This file group should include
91# * all cc_toolchain targets supported
92# * all file groups that said cc_toolchain might refer to
93alias(
94 name = "toolchain",
lberki55c8e632020-04-08 07:15:07 -070095 actual = "@local_config_cc//:toolchain",
hlopkobea9d252019-11-15 07:30:16 -080096)
97
98# Hardcoded toolchain, legacy behaviour.
99cc_toolchain_suite(
100 name = "default-toolchain",
101 toolchains = {
102 "armeabi-v7a|compiler": ":cc-compiler-armeabi-v7a",
103 "darwin|compiler": ":cc-compiler-darwin",
104 "freebsd|compiler": ":cc-compiler-freebsd",
105 "local|compiler": ":cc-compiler-local",
106 "x64_windows|compiler": ":cc-compiler-x64_windows",
107 "x64_windows_msvc|compiler": ":cc-compiler-x64_windows_msvc",
108 "s390x|compiler": ":cc-compiler-s390x",
109 "ppc|compiler": ":cc-compiler-ppc",
110 "k8": ":cc-compiler-local",
111 "piii": ":cc-compiler-local",
112 "arm": ":cc-compiler-local",
113 "aarch64": ":cc-compiler-local",
114 "s390x": ":cc-compiler-local",
115 "ppc": ":cc-compiler-local",
116 "ppc64": ":cc-compiler-local",
117 "darwin": ":cc-compiler-darwin",
118 "freebsd": ":cc-compiler-freebsd",
119 "armeabi-v7a": ":cc-compiler-armeabi-v7a",
120 "x64_windows": ":cc-compiler-x64_windows",
121 "x64_windows_msvc": ":cc-compiler-x64_windows_msvc",
122 },
123)
124
125cc_toolchain(
126 name = "cc-compiler-local",
127 all_files = ":empty",
128 ar_files = ":empty",
129 as_files = ":empty",
130 compiler_files = ":empty",
131 dwp_files = ":empty",
132 linker_files = ":empty",
133 objcopy_files = ":empty",
134 strip_files = ":empty",
135 supports_param_files = 1,
136 toolchain_config = ":local_linux",
137 toolchain_identifier = "local_linux",
138)
139
140cc_toolchain_config(
141 name = "local_linux",
142 compiler = "compiler",
143 cpu = "local",
144 disable_static_cc_toolchains = select({
145 ":disable_static_cc_toolchains": True,
146 "//conditions:default": False,
147 }),
148)
149
150toolchain(
151 name = "cc-toolchain-local",
152 exec_compatible_with = [
153 ],
154 target_compatible_with = [
155 ],
156 toolchain = ":cc-compiler-local",
157 toolchain_type = ":toolchain_type",
158)
159
160cc_toolchain(
161 name = "cc-compiler-ppc",
162 all_files = ":empty",
163 ar_files = ":empty",
164 as_files = ":empty",
165 compiler_files = ":empty",
166 dwp_files = ":empty",
167 linker_files = ":empty",
168 objcopy_files = ":empty",
169 strip_files = ":empty",
170 supports_param_files = 1,
171 toolchain_config = ":local_linux",
172 toolchain_identifier = "local_linux",
173)
174
175toolchain(
176 name = "cc-toolchain-ppc",
177 exec_compatible_with = [
178 "@platforms//cpu:ppc",
179 ],
180 target_compatible_with = [
181 "@platforms//cpu:ppc",
182 ],
183 toolchain = ":cc-compiler-ppc",
184 toolchain_type = ":toolchain_type",
185)
186
187cc_toolchain(
188 name = "cc-compiler-s390x",
189 all_files = ":empty",
190 ar_files = ":empty",
191 as_files = ":empty",
192 compiler_files = ":empty",
193 dwp_files = ":empty",
194 linker_files = ":empty",
195 objcopy_files = ":empty",
196 strip_files = ":empty",
197 supports_param_files = 1,
198 toolchain_config = ":local_linux",
199 toolchain_identifier = "local_linux",
200)
201
202toolchain(
203 name = "cc-toolchain-s390x",
204 exec_compatible_with = [
205 "@platforms//cpu:s390x",
206 ],
207 target_compatible_with = [
208 "@platforms//cpu:s390x",
209 ],
210 toolchain = ":cc-compiler-s390x",
211 toolchain_type = ":toolchain_type",
212)
213
214cc_toolchain(
215 name = "cc-compiler-armeabi-v7a",
216 all_files = ":empty",
217 ar_files = ":empty",
218 as_files = ":empty",
219 compiler_files = ":empty",
220 dwp_files = ":empty",
221 linker_files = ":empty",
222 objcopy_files = ":empty",
223 strip_files = ":empty",
224 supports_param_files = 1,
225 toolchain_config = ":local_linux",
226 toolchain_identifier = "local_linux",
227)
228
229toolchain(
230 name = "cc-toolchain-armeabi-v7a",
231 exec_compatible_with = [
232 ],
233 target_compatible_with = [
234 "@platforms//cpu:arm",
235 "@platforms//os:android",
236 ],
237 toolchain = ":cc-compiler-armeabi-v7a",
238 toolchain_type = ":toolchain_type",
239)
240
241cc_toolchain(
242 name = "cc-compiler-k8",
243 all_files = ":empty",
244 ar_files = ":empty",
245 as_files = ":empty",
246 compiler_files = ":empty",
247 dwp_files = ":empty",
248 linker_files = ":empty",
249 objcopy_files = ":empty",
250 strip_files = ":empty",
251 supports_param_files = 1,
252 toolchain_config = ":local_linux",
253 toolchain_identifier = "local_linux",
254)
255
256toolchain(
257 name = "cc-toolchain-k8",
258 exec_compatible_with = [
259 "@platforms//cpu:x86_64",
260 "@platforms//os:linux",
261 ],
262 target_compatible_with = [
263 "@platforms//cpu:x86_64",
264 "@platforms//os:linux",
265 ],
266 toolchain = ":cc-compiler-k8",
267 toolchain_type = ":toolchain_type",
268)
269
270cc_toolchain(
271 name = "cc-compiler-darwin",
272 all_files = ":osx_wrapper",
273 ar_files = ":empty",
274 as_files = ":osx_wrapper",
275 compiler_files = ":osx_wrapper",
276 dwp_files = ":empty",
277 linker_files = ":osx_wrapper",
278 objcopy_files = ":empty",
279 strip_files = ":empty",
Keith Smileyf08819b2020-11-12 03:13:54 -0800280 supports_param_files = 1,
hlopkobea9d252019-11-15 07:30:16 -0800281 toolchain_config = ":local_darwin",
282 toolchain_identifier = "local_darwin",
283)
284
285cc_toolchain_config(
286 name = "local_darwin",
287 compiler = "compiler",
288 cpu = "darwin",
289 disable_static_cc_toolchains = select({
290 ":disable_static_cc_toolchains": True,
291 "//conditions:default": False,
292 }),
293)
294
295toolchain(
296 name = "cc-toolchain-darwin",
297 exec_compatible_with = [
298 "@platforms//cpu:x86_64",
299 "@platforms//os:osx",
300 ],
301 target_compatible_with = [
302 "@platforms//cpu:x86_64",
303 "@platforms//os:osx",
304 ],
305 toolchain = ":cc-compiler-darwin",
306 toolchain_type = ":toolchain_type",
307)
308
309cc_toolchain(
310 name = "cc-compiler-freebsd",
311 all_files = ":empty",
312 ar_files = ":empty",
313 as_files = ":empty",
314 compiler_files = ":empty",
315 dwp_files = ":empty",
316 linker_files = ":empty",
317 objcopy_files = ":empty",
318 strip_files = ":empty",
319 supports_param_files = 0,
320 toolchain_config = ":local_freebsd",
321 toolchain_identifier = "local_freebsd",
322)
323
324cc_toolchain_config(
325 name = "local_freebsd",
326 compiler = "compiler",
327 cpu = "freebsd",
328 disable_static_cc_toolchains = select({
329 ":disable_static_cc_toolchains": True,
330 "//conditions:default": False,
331 }),
332)
333
334toolchain(
335 name = "cc-toolchain-freebsd",
336 exec_compatible_with = [
337 "@platforms//cpu:x86_64",
338 "@platforms//os:freebsd",
339 ],
340 target_compatible_with = [
341 "@platforms//cpu:x86_64",
342 "@platforms//os:freebsd",
343 ],
344 toolchain = ":cc-compiler-freebsd",
345 toolchain_type = ":toolchain_type",
346)
347
348cc_toolchain(
349 name = "cc-compiler-x64_windows",
350 all_files = ":empty",
351 ar_files = ":empty",
352 as_files = ":empty",
353 compiler_files = ":empty",
354 dwp_files = ":empty",
355 linker_files = ":empty",
356 objcopy_files = ":empty",
357 strip_files = ":empty",
358 supports_param_files = 0,
359 toolchain_config = ":local_windows_msys64",
360 toolchain_identifier = "local_windows_msys64",
361)
362
363cc_toolchain_config(
364 name = "local_windows_msys64",
365 compiler = "windows_msys64",
366 cpu = "x64_windows",
367 disable_static_cc_toolchains = select({
368 ":disable_static_cc_toolchains": True,
369 "//conditions:default": False,
370 }),
371)
372
373toolchain(
374 name = "cc-toolchain-x64_windows",
375 exec_compatible_with = [
376 "@platforms//cpu:x86_64",
377 "@platforms//os:windows",
378 ],
379 target_compatible_with = [
380 "@platforms//cpu:x86_64",
381 "@platforms//os:windows",
382 ],
383 toolchain = ":cc-compiler-x64_windows",
384 toolchain_type = ":toolchain_type",
385)
386
387cc_toolchain(
388 name = "cc-compiler-x64_windows_msvc",
389 all_files = ":empty",
390 ar_files = ":empty",
391 as_files = ":empty",
392 compiler_files = ":empty",
393 dwp_files = ":empty",
394 linker_files = ":empty",
395 objcopy_files = ":empty",
396 strip_files = ":empty",
397 supports_param_files = 1,
398 toolchain_config = ":vc_14_0_x64",
399 toolchain_identifier = "vc_14_0_x64",
400)
401
402cc_toolchain_config(
403 name = "vc_14_0_x64",
404 compiler = "cl",
405 cpu = "x64_windows_msvc",
406 disable_static_cc_toolchains = select({
407 ":disable_static_cc_toolchains": True,
408 "//conditions:default": False,
409 }),
410)
411
412toolchain(
413 name = "cc-toolchain-x64_windows_msvc",
414 exec_compatible_with = [
415 "@platforms//cpu:x86_64",
416 "@platforms//os:windows",
417 ":msvc",
418 ],
419 target_compatible_with = [
420 "@platforms//cpu:x86_64",
421 "@platforms//os:windows",
422 ],
423 toolchain = ":cc-compiler-x64_windows_msvc",
424 toolchain_type = ":toolchain_type",
425)
426
427filegroup(
428 name = "srcs",
429 srcs = glob(["**"]) + [
430 "//tools/cpp/runfiles:srcs",
431 ],
432)
433
434filegroup(
435 name = "embedded_tools",
436 srcs = glob(["**"]) + [
437 "//tools/cpp/runfiles:embedded_tools",
438 ],
439)
440
441filegroup(
442 name = "interface_library_builder",
443 srcs = ["build_interface_so"],
444)
445
446filegroup(
447 name = "osx_wrapper",
448 srcs = ["osx_cc_wrapper.sh"],
449)
450
451filegroup(
452 name = "link_dynamic_library",
453 srcs = ["link_dynamic_library.sh"],
454)
455
456filegroup(
457 name = "lib_cc_configure",
458 srcs = ["lib_cc_configure.bzl"],
459)
460
461filegroup(
462 name = "bzl_srcs",
463 srcs = glob(["*.bzl"]),
464 visibility = ["//tools:__pkg__"],
465)
466
467load(":compiler_flag.bzl", "compiler_flag")
468
469compiler_flag(name = "compiler")
470
471# Target that can provide the CC_FLAGS variable based on the current
472# cc_toolchain.
473load("@bazel_tools//tools/cpp:cc_flags_supplier.bzl", "cc_flags_supplier")
474
475cc_flags_supplier(name = "cc_flags")