blob: 953e2bd38496f2721337033d8b52408507ae9241 [file] [log] [blame]
rosica71bc38f2019-02-04 02:39:30 -08001# Copyright 2019 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
15"""A Starlark cc_toolchain configuration rule"""
16
17load(
18 "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
19 "action_config",
rosica71bc38f2019-02-04 02:39:30 -080020 "feature",
rosica71bc38f2019-02-04 02:39:30 -080021 "flag_group",
22 "flag_set",
rosica71bc38f2019-02-04 02:39:30 -080023 "tool",
24 "tool_path",
rosica71bc38f2019-02-04 02:39:30 -080025 "with_feature_set",
26)
27load(
28 "@bazel_tools//tools/build_defs/cc:action_names.bzl",
29 _ASSEMBLE_ACTION_NAME = "ASSEMBLE_ACTION_NAME",
30 _CLIF_MATCH_ACTION_NAME = "CLIF_MATCH_ACTION_NAME",
31 _CPP_COMPILE_ACTION_NAME = "CPP_COMPILE_ACTION_NAME",
32 _CPP_HEADER_PARSING_ACTION_NAME = "CPP_HEADER_PARSING_ACTION_NAME",
33 _CPP_LINK_DYNAMIC_LIBRARY_ACTION_NAME = "CPP_LINK_DYNAMIC_LIBRARY_ACTION_NAME",
34 _CPP_LINK_EXECUTABLE_ACTION_NAME = "CPP_LINK_EXECUTABLE_ACTION_NAME",
35 _CPP_LINK_NODEPS_DYNAMIC_LIBRARY_ACTION_NAME = "CPP_LINK_NODEPS_DYNAMIC_LIBRARY_ACTION_NAME",
rosica71bc38f2019-02-04 02:39:30 -080036 _CPP_MODULE_CODEGEN_ACTION_NAME = "CPP_MODULE_CODEGEN_ACTION_NAME",
37 _CPP_MODULE_COMPILE_ACTION_NAME = "CPP_MODULE_COMPILE_ACTION_NAME",
38 _C_COMPILE_ACTION_NAME = "C_COMPILE_ACTION_NAME",
39 _LINKSTAMP_COMPILE_ACTION_NAME = "LINKSTAMP_COMPILE_ACTION_NAME",
40 _LTO_BACKEND_ACTION_NAME = "LTO_BACKEND_ACTION_NAME",
rosica71bc38f2019-02-04 02:39:30 -080041 _PREPROCESS_ASSEMBLE_ACTION_NAME = "PREPROCESS_ASSEMBLE_ACTION_NAME",
rosica71bc38f2019-02-04 02:39:30 -080042)
43
44all_compile_actions = [
45 _C_COMPILE_ACTION_NAME,
46 _CPP_COMPILE_ACTION_NAME,
47 _LINKSTAMP_COMPILE_ACTION_NAME,
48 _ASSEMBLE_ACTION_NAME,
49 _PREPROCESS_ASSEMBLE_ACTION_NAME,
50 _CPP_HEADER_PARSING_ACTION_NAME,
51 _CPP_MODULE_COMPILE_ACTION_NAME,
52 _CPP_MODULE_CODEGEN_ACTION_NAME,
53 _CLIF_MATCH_ACTION_NAME,
54 _LTO_BACKEND_ACTION_NAME,
55]
56
57all_cpp_compile_actions = [
58 _CPP_COMPILE_ACTION_NAME,
59 _LINKSTAMP_COMPILE_ACTION_NAME,
60 _CPP_HEADER_PARSING_ACTION_NAME,
61 _CPP_MODULE_COMPILE_ACTION_NAME,
62 _CPP_MODULE_CODEGEN_ACTION_NAME,
63 _CLIF_MATCH_ACTION_NAME,
64]
65
66preprocessor_compile_actions = [
67 _C_COMPILE_ACTION_NAME,
68 _CPP_COMPILE_ACTION_NAME,
69 _LINKSTAMP_COMPILE_ACTION_NAME,
70 _PREPROCESS_ASSEMBLE_ACTION_NAME,
71 _CPP_HEADER_PARSING_ACTION_NAME,
72 _CPP_MODULE_COMPILE_ACTION_NAME,
73 _CLIF_MATCH_ACTION_NAME,
74]
75
76codegen_compile_actions = [
77 _C_COMPILE_ACTION_NAME,
78 _CPP_COMPILE_ACTION_NAME,
79 _LINKSTAMP_COMPILE_ACTION_NAME,
80 _ASSEMBLE_ACTION_NAME,
81 _PREPROCESS_ASSEMBLE_ACTION_NAME,
82 _CPP_MODULE_CODEGEN_ACTION_NAME,
83 _LTO_BACKEND_ACTION_NAME,
84]
85
86all_link_actions = [
87 _CPP_LINK_EXECUTABLE_ACTION_NAME,
88 _CPP_LINK_DYNAMIC_LIBRARY_ACTION_NAME,
89 _CPP_LINK_NODEPS_DYNAMIC_LIBRARY_ACTION_NAME,
90]
91
92def _impl(ctx):
rosicac5ebfcf2019-06-04 01:47:17 -070093 if ctx.attr.disable_static_cc_toolchains:
94 fail("@bazel_tools//tools/cpp:default-toolchain, as well as the cc_toolchains it points " +
95 "to have been removed. See https://github.com/bazelbuild/bazel/issues/8546.")
96
rosica71bc38f2019-02-04 02:39:30 -080097 if (ctx.attr.cpu == "darwin"):
98 toolchain_identifier = "local_darwin"
99 elif (ctx.attr.cpu == "freebsd"):
100 toolchain_identifier = "local_freebsd"
aldersondrive644b7d412020-01-10 07:48:15 -0800101 elif (ctx.attr.cpu == "openbsd"):
102 toolchain_identifier = "local_openbsd"
rosica71bc38f2019-02-04 02:39:30 -0800103 elif (ctx.attr.cpu == "local"):
104 toolchain_identifier = "local_linux"
105 elif (ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_clang"):
106 toolchain_identifier = "local_windows_clang"
107 elif (ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_mingw"):
108 toolchain_identifier = "local_windows_mingw"
109 elif (ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_msys64"):
110 toolchain_identifier = "local_windows_msys64"
111 elif (ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_msys64_mingw64"):
112 toolchain_identifier = "local_windows_msys64_mingw64"
113 elif (ctx.attr.cpu == "armeabi-v7a"):
114 toolchain_identifier = "stub_armeabi-v7a"
115 elif (ctx.attr.cpu == "x64_windows_msvc"):
116 toolchain_identifier = "vc_14_0_x64"
117 else:
118 fail("Unreachable")
119
120 if (ctx.attr.cpu == "armeabi-v7a"):
121 host_system_name = "armeabi-v7a"
122 elif (ctx.attr.cpu == "darwin" or
123 ctx.attr.cpu == "freebsd" or
aldersondrive644b7d412020-01-10 07:48:15 -0800124 ctx.attr.cpu == "openbsd" or
rosica71bc38f2019-02-04 02:39:30 -0800125 ctx.attr.cpu == "local" or
126 ctx.attr.cpu == "x64_windows" or
127 ctx.attr.cpu == "x64_windows_msvc"):
128 host_system_name = "local"
129 else:
130 fail("Unreachable")
131
132 if (ctx.attr.cpu == "armeabi-v7a"):
133 target_system_name = "armeabi-v7a"
134 elif (ctx.attr.cpu == "darwin" or
135 ctx.attr.cpu == "freebsd" or
aldersondrive644b7d412020-01-10 07:48:15 -0800136 ctx.attr.cpu == "openbsd" or
rosica71bc38f2019-02-04 02:39:30 -0800137 ctx.attr.cpu == "local" or
138 ctx.attr.cpu == "x64_windows" or
139 ctx.attr.cpu == "x64_windows_msvc"):
140 target_system_name = "local"
141 else:
142 fail("Unreachable")
143
144 if (ctx.attr.cpu == "armeabi-v7a"):
145 target_cpu = "armeabi-v7a"
146 elif (ctx.attr.cpu == "darwin"):
147 target_cpu = "darwin"
148 elif (ctx.attr.cpu == "freebsd"):
149 target_cpu = "freebsd"
aldersondrive644b7d412020-01-10 07:48:15 -0800150 elif (ctx.attr.cpu == "openbsd"):
151 target_cpu = "openbsd"
rosica71bc38f2019-02-04 02:39:30 -0800152 elif (ctx.attr.cpu == "local"):
153 target_cpu = "local"
154 elif (ctx.attr.cpu == "x64_windows"):
155 target_cpu = "x64_windows"
156 elif (ctx.attr.cpu == "x64_windows_msvc"):
157 target_cpu = "x64_windows_msvc"
158 else:
159 fail("Unreachable")
160
161 if (ctx.attr.cpu == "armeabi-v7a"):
162 target_libc = "armeabi-v7a"
163 elif (ctx.attr.cpu == "freebsd" or
aldersondrive644b7d412020-01-10 07:48:15 -0800164 ctx.attr.cpu == "openbsd" or
rosica71bc38f2019-02-04 02:39:30 -0800165 ctx.attr.cpu == "local" or
166 ctx.attr.cpu == "x64_windows"):
167 target_libc = "local"
168 elif (ctx.attr.cpu == "darwin"):
169 target_libc = "macosx"
170 elif (ctx.attr.cpu == "x64_windows_msvc"):
171 target_libc = "msvcrt140"
172 else:
173 fail("Unreachable")
174
175 if (ctx.attr.cpu == "x64_windows_msvc"):
176 compiler = "cl"
177 elif (ctx.attr.cpu == "armeabi-v7a" or
178 ctx.attr.cpu == "darwin" or
179 ctx.attr.cpu == "freebsd" or
aldersondrive644b7d412020-01-10 07:48:15 -0800180 ctx.attr.cpu == "openbsd" or
rosica71bc38f2019-02-04 02:39:30 -0800181 ctx.attr.cpu == "local"):
182 compiler = "compiler"
183 elif (ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_clang"):
184 compiler = "windows_clang"
185 elif (ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_mingw"):
186 compiler = "windows_mingw"
187 elif (ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_msys64"):
188 compiler = "windows_msys64"
189 elif (ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_msys64_mingw64"):
190 compiler = "windows_msys64_mingw64"
191 else:
192 fail("Unreachable")
193
194 if (ctx.attr.cpu == "armeabi-v7a"):
195 abi_version = "armeabi-v7a"
196 elif (ctx.attr.cpu == "darwin" or
197 ctx.attr.cpu == "freebsd" or
aldersondrive644b7d412020-01-10 07:48:15 -0800198 ctx.attr.cpu == "openbsd" or
rosica71bc38f2019-02-04 02:39:30 -0800199 ctx.attr.cpu == "local" or
200 ctx.attr.cpu == "x64_windows" or
201 ctx.attr.cpu == "x64_windows_msvc"):
202 abi_version = "local"
203 else:
204 fail("Unreachable")
205
206 if (ctx.attr.cpu == "armeabi-v7a"):
207 abi_libc_version = "armeabi-v7a"
208 elif (ctx.attr.cpu == "darwin" or
209 ctx.attr.cpu == "freebsd" or
aldersondrive644b7d412020-01-10 07:48:15 -0800210 ctx.attr.cpu == "openbsd" or
rosica71bc38f2019-02-04 02:39:30 -0800211 ctx.attr.cpu == "local" or
212 ctx.attr.cpu == "x64_windows" or
213 ctx.attr.cpu == "x64_windows_msvc"):
214 abi_libc_version = "local"
215 else:
216 fail("Unreachable")
217
218 cc_target_os = None
219
220 builtin_sysroot = None
221
222 if (ctx.attr.cpu == "darwin" or
223 ctx.attr.cpu == "freebsd" or
aldersondrive644b7d412020-01-10 07:48:15 -0800224 ctx.attr.cpu == "openbsd" or
rosica71bc38f2019-02-04 02:39:30 -0800225 ctx.attr.cpu == "local"):
226 objcopy_embed_data_action = action_config(
227 action_name = "objcopy_embed_data",
228 enabled = True,
229 tools = [tool(path = "/usr/bin/objcopy")],
230 )
231 elif (ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_clang"):
232 objcopy_embed_data_action = action_config(
233 action_name = "objcopy_embed_data",
234 enabled = True,
235 tools = [tool(path = "C:/Program Files (x86)/LLVM/bin/objcopy")],
236 )
237 elif (ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_mingw"):
238 objcopy_embed_data_action = action_config(
239 action_name = "objcopy_embed_data",
240 enabled = True,
241 tools = [tool(path = "C:/mingw/bin/objcopy")],
242 )
243 elif (ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_msys64_mingw64"):
244 objcopy_embed_data_action = action_config(
245 action_name = "objcopy_embed_data",
246 enabled = True,
247 tools = [tool(path = "C:/tools/msys64/mingw64/bin/objcopy")],
248 )
249 elif (ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_msys64"):
250 objcopy_embed_data_action = action_config(
251 action_name = "objcopy_embed_data",
252 enabled = True,
253 tools = [tool(path = "C:/tools/msys64/usr/bin/objcopy")],
254 )
255
256 c_compile_action = action_config(
257 action_name = _C_COMPILE_ACTION_NAME,
258 implies = [
259 "compiler_input_flags",
260 "compiler_output_flags",
261 "default_compile_flags",
262 "user_compile_flags",
263 "sysroot",
264 "unfiltered_compile_flags",
265 ],
266 tools = [tool(path = "wrapper/bin/msvc_cl.bat")],
267 )
268
269 cpp_compile_action = action_config(
270 action_name = _CPP_COMPILE_ACTION_NAME,
271 implies = [
272 "compiler_input_flags",
273 "compiler_output_flags",
274 "default_compile_flags",
275 "user_compile_flags",
276 "sysroot",
277 "unfiltered_compile_flags",
278 ],
279 tools = [tool(path = "wrapper/bin/msvc_cl.bat")],
280 )
281
282 if (ctx.attr.cpu == "armeabi-v7a"):
283 action_configs = []
284 elif (ctx.attr.cpu == "x64_windows_msvc"):
285 action_configs = [c_compile_action, cpp_compile_action]
286 elif (ctx.attr.cpu == "darwin" or
287 ctx.attr.cpu == "freebsd" or
aldersondrive644b7d412020-01-10 07:48:15 -0800288 ctx.attr.cpu == "openbsd" or
rosica71bc38f2019-02-04 02:39:30 -0800289 ctx.attr.cpu == "local" or
290 ctx.attr.cpu == "x64_windows"):
291 action_configs = [objcopy_embed_data_action]
292 else:
293 fail("Unreachable")
294
hlopko2f17a862019-02-26 07:56:03 -0800295 random_seed_feature = feature(name = "random_seed", enabled = True)
rosica71bc38f2019-02-04 02:39:30 -0800296
297 compiler_output_flags_feature = feature(
298 name = "compiler_output_flags",
299 flag_sets = [
300 flag_set(
301 actions = [_ASSEMBLE_ACTION_NAME],
302 flag_groups = [
303 flag_group(
304 flags = ["/Fo%{output_file}", "/Zi"],
305 expand_if_available = "output_file",
306 expand_if_not_available = "output_assembly_file",
307 ),
308 ],
309 ),
310 flag_set(
311 actions = [
312 _PREPROCESS_ASSEMBLE_ACTION_NAME,
313 _C_COMPILE_ACTION_NAME,
314 _CPP_COMPILE_ACTION_NAME,
315 _CPP_HEADER_PARSING_ACTION_NAME,
316 _CPP_MODULE_COMPILE_ACTION_NAME,
317 _CPP_MODULE_CODEGEN_ACTION_NAME,
318 ],
319 flag_groups = [
320 flag_group(
321 flags = ["/Fo%{output_file}"],
322 expand_if_available = "output_file",
323 expand_if_not_available = "output_assembly_file",
324 ),
325 flag_group(
326 flags = ["/Fa%{output_file}"],
327 expand_if_available = "output_file",
328 ),
329 flag_group(
330 flags = ["/P", "/Fi%{output_file}"],
331 expand_if_available = "output_file",
332 ),
333 ],
334 ),
335 ],
336 )
337
338 if (ctx.attr.cpu == "local"):
339 default_link_flags_feature = feature(
340 name = "default_link_flags",
341 enabled = True,
342 flag_sets = [
343 flag_set(
344 actions = all_link_actions,
345 flag_groups = [
346 flag_group(
347 flags = [
348 "-lstdc++",
349 "-Wl,-z,relro,-z,now",
350 "-no-canonical-prefixes",
351 "-pass-exit-codes",
352 ],
353 ),
354 ],
355 ),
356 flag_set(
357 actions = all_link_actions,
358 flag_groups = [flag_group(flags = ["-Wl,--gc-sections"])],
359 with_features = [with_feature_set(features = ["opt"])],
360 ),
361 ],
362 )
aldersondrive644b7d412020-01-10 07:48:15 -0800363 elif (ctx.attr.cpu == "freebsd" or
Dmitri G1f7d2ff2020-03-25 05:51:13 -0700364 ctx.attr.cpu == "openbsd"):
rosica71bc38f2019-02-04 02:39:30 -0800365 default_link_flags_feature = feature(
366 name = "default_link_flags",
367 enabled = True,
368 flag_sets = [
369 flag_set(
370 actions = all_link_actions,
371 flag_groups = [
372 flag_group(
373 flags = [
Keith Smileya987b982022-02-17 11:07:44 -0800374 "-lc++",
rosica71bc38f2019-02-04 02:39:30 -0800375 "-Wl,-z,relro,-z,now",
376 "-no-canonical-prefixes",
377 ],
378 ),
379 ],
380 ),
381 flag_set(
382 actions = all_link_actions,
383 flag_groups = [flag_group(flags = ["-Wl,--gc-sections"])],
384 with_features = [with_feature_set(features = ["opt"])],
385 ),
386 ],
387 )
388 elif (ctx.attr.cpu == "darwin"):
389 default_link_flags_feature = feature(
390 name = "default_link_flags",
391 enabled = True,
392 flag_sets = [
393 flag_set(
394 actions = all_link_actions,
395 flag_groups = [
396 flag_group(
397 flags = [
Keith Smiley8b60c902022-01-27 05:47:58 -0800398 "-lc++",
rosica71bc38f2019-02-04 02:39:30 -0800399 "-undefined",
400 "dynamic_lookup",
401 "-headerpad_max_install_names",
402 "-no-canonical-prefixes",
403 ],
404 ),
405 ],
406 ),
407 ],
408 )
409 elif (ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_msys64"):
410 default_link_flags_feature = feature(
411 name = "default_link_flags",
412 enabled = True,
413 flag_sets = [
414 flag_set(
415 actions = all_link_actions,
416 flag_groups = [flag_group(flags = ["-lstdc++"])],
417 ),
418 ],
419 )
420 elif (ctx.attr.cpu == "x64_windows_msvc"):
421 default_link_flags_feature = feature(
422 name = "default_link_flags",
423 enabled = True,
424 flag_sets = [
425 flag_set(
426 actions = all_link_actions,
427 flag_groups = [flag_group(flags = ["-m64"])],
428 ),
429 ],
430 )
431
432 if (ctx.attr.cpu == "darwin" or
aldersondrive644b7d412020-01-10 07:48:15 -0800433 ctx.attr.cpu == "freebsd" or
434 ctx.attr.cpu == "openbsd"):
rosica71bc38f2019-02-04 02:39:30 -0800435 unfiltered_compile_flags_feature = feature(
436 name = "unfiltered_compile_flags",
437 enabled = True,
438 flag_sets = [
439 flag_set(
440 actions = [
441 _ASSEMBLE_ACTION_NAME,
442 _PREPROCESS_ASSEMBLE_ACTION_NAME,
443 _LINKSTAMP_COMPILE_ACTION_NAME,
444 _C_COMPILE_ACTION_NAME,
445 _CPP_COMPILE_ACTION_NAME,
446 _CPP_HEADER_PARSING_ACTION_NAME,
447 _CPP_MODULE_COMPILE_ACTION_NAME,
448 _CPP_MODULE_CODEGEN_ACTION_NAME,
449 _LTO_BACKEND_ACTION_NAME,
450 _CLIF_MATCH_ACTION_NAME,
451 ],
452 flag_groups = [
453 flag_group(
454 flags = [
455 "-no-canonical-prefixes",
456 "-Wno-builtin-macro-redefined",
457 "-D__DATE__=\"redacted\"",
458 "-D__TIMESTAMP__=\"redacted\"",
459 "-D__TIME__=\"redacted\"",
460 ],
461 ),
462 ],
463 ),
464 ],
465 )
466 elif (ctx.attr.cpu == "local"):
467 unfiltered_compile_flags_feature = feature(
468 name = "unfiltered_compile_flags",
469 enabled = True,
470 flag_sets = [
471 flag_set(
472 actions = [
473 _ASSEMBLE_ACTION_NAME,
474 _PREPROCESS_ASSEMBLE_ACTION_NAME,
475 _LINKSTAMP_COMPILE_ACTION_NAME,
476 _C_COMPILE_ACTION_NAME,
477 _CPP_COMPILE_ACTION_NAME,
478 _CPP_HEADER_PARSING_ACTION_NAME,
479 _CPP_MODULE_COMPILE_ACTION_NAME,
480 _CPP_MODULE_CODEGEN_ACTION_NAME,
481 _LTO_BACKEND_ACTION_NAME,
482 _CLIF_MATCH_ACTION_NAME,
483 ],
484 flag_groups = [
485 flag_group(
486 flags = [
487 "-no-canonical-prefixes",
488 "-fno-canonical-system-headers",
489 "-Wno-builtin-macro-redefined",
490 "-D__DATE__=\"redacted\"",
491 "-D__TIMESTAMP__=\"redacted\"",
492 "-D__TIME__=\"redacted\"",
493 ],
494 ),
495 ],
496 ),
497 ],
498 )
499 elif (ctx.attr.cpu == "x64_windows_msvc"):
500 unfiltered_compile_flags_feature = feature(
501 name = "unfiltered_compile_flags",
502 flag_sets = [
503 flag_set(
504 actions = [
505 _ASSEMBLE_ACTION_NAME,
506 _PREPROCESS_ASSEMBLE_ACTION_NAME,
507 _C_COMPILE_ACTION_NAME,
508 _CPP_COMPILE_ACTION_NAME,
509 _CPP_HEADER_PARSING_ACTION_NAME,
510 _CPP_MODULE_COMPILE_ACTION_NAME,
511 _CPP_MODULE_CODEGEN_ACTION_NAME,
512 ],
513 flag_groups = [
514 flag_group(
515 flags = ["%{unfiltered_compile_flags}"],
516 iterate_over = "unfiltered_compile_flags",
517 expand_if_available = "unfiltered_compile_flags",
518 ),
519 ],
520 ),
521 ],
522 )
523
524 supports_pic_feature = feature(name = "supports_pic", enabled = True)
525
526 if (ctx.attr.cpu == "darwin"):
527 default_compile_flags_feature = feature(
528 name = "default_compile_flags",
529 enabled = True,
530 flag_sets = [
531 flag_set(
532 actions = [
533 _ASSEMBLE_ACTION_NAME,
534 _PREPROCESS_ASSEMBLE_ACTION_NAME,
535 _LINKSTAMP_COMPILE_ACTION_NAME,
536 _C_COMPILE_ACTION_NAME,
537 _CPP_COMPILE_ACTION_NAME,
538 _CPP_HEADER_PARSING_ACTION_NAME,
539 _CPP_MODULE_COMPILE_ACTION_NAME,
540 _CPP_MODULE_CODEGEN_ACTION_NAME,
541 _LTO_BACKEND_ACTION_NAME,
542 _CLIF_MATCH_ACTION_NAME,
543 ],
544 flag_groups = [
545 flag_group(
546 flags = [
547 "-D_FORTIFY_SOURCE=1",
548 "-fstack-protector",
549 "-fcolor-diagnostics",
550 "-Wall",
551 "-Wthread-safety",
552 "-Wself-assign",
553 "-fno-omit-frame-pointer",
554 ],
555 ),
556 ],
557 ),
558 flag_set(
559 actions = [
560 _ASSEMBLE_ACTION_NAME,
561 _PREPROCESS_ASSEMBLE_ACTION_NAME,
562 _LINKSTAMP_COMPILE_ACTION_NAME,
563 _C_COMPILE_ACTION_NAME,
564 _CPP_COMPILE_ACTION_NAME,
565 _CPP_HEADER_PARSING_ACTION_NAME,
566 _CPP_MODULE_COMPILE_ACTION_NAME,
567 _CPP_MODULE_CODEGEN_ACTION_NAME,
568 _LTO_BACKEND_ACTION_NAME,
569 _CLIF_MATCH_ACTION_NAME,
570 ],
571 flag_groups = [flag_group(flags = ["-g"])],
572 with_features = [with_feature_set(features = ["dbg"])],
573 ),
574 flag_set(
575 actions = [
576 _ASSEMBLE_ACTION_NAME,
577 _PREPROCESS_ASSEMBLE_ACTION_NAME,
578 _LINKSTAMP_COMPILE_ACTION_NAME,
579 _C_COMPILE_ACTION_NAME,
580 _CPP_COMPILE_ACTION_NAME,
581 _CPP_HEADER_PARSING_ACTION_NAME,
582 _CPP_MODULE_COMPILE_ACTION_NAME,
583 _CPP_MODULE_CODEGEN_ACTION_NAME,
584 _LTO_BACKEND_ACTION_NAME,
585 _CLIF_MATCH_ACTION_NAME,
586 ],
587 flag_groups = [
588 flag_group(
589 flags = [
590 "-g0",
591 "-O2",
592 "-DNDEBUG",
593 "-ffunction-sections",
594 "-fdata-sections",
595 ],
596 ),
597 ],
598 with_features = [with_feature_set(features = ["opt"])],
599 ),
600 flag_set(
601 actions = [
602 _LINKSTAMP_COMPILE_ACTION_NAME,
603 _CPP_COMPILE_ACTION_NAME,
604 _CPP_HEADER_PARSING_ACTION_NAME,
605 _CPP_MODULE_COMPILE_ACTION_NAME,
606 _CPP_MODULE_CODEGEN_ACTION_NAME,
607 _LTO_BACKEND_ACTION_NAME,
608 _CLIF_MATCH_ACTION_NAME,
609 ],
610 flag_groups = [flag_group(flags = ["-std=c++0x"])],
611 ),
612 ],
613 )
614 elif (ctx.attr.cpu == "local"):
615 default_compile_flags_feature = feature(
616 name = "default_compile_flags",
617 enabled = True,
618 flag_sets = [
619 flag_set(
620 actions = [
621 _ASSEMBLE_ACTION_NAME,
622 _PREPROCESS_ASSEMBLE_ACTION_NAME,
623 _LINKSTAMP_COMPILE_ACTION_NAME,
624 _C_COMPILE_ACTION_NAME,
625 _CPP_COMPILE_ACTION_NAME,
626 _CPP_HEADER_PARSING_ACTION_NAME,
627 _CPP_MODULE_COMPILE_ACTION_NAME,
628 _CPP_MODULE_CODEGEN_ACTION_NAME,
629 _LTO_BACKEND_ACTION_NAME,
630 _CLIF_MATCH_ACTION_NAME,
631 ],
632 flag_groups = [
633 flag_group(
634 flags = [
635 "-U_FORTIFY_SOURCE",
636 "-D_FORTIFY_SOURCE=1",
637 "-fstack-protector",
638 "-Wall",
639 "-Wunused-but-set-parameter",
640 "-Wno-free-nonheap-object",
641 "-fno-omit-frame-pointer",
642 ],
643 ),
644 ],
645 ),
646 flag_set(
647 actions = [
648 _ASSEMBLE_ACTION_NAME,
649 _PREPROCESS_ASSEMBLE_ACTION_NAME,
650 _LINKSTAMP_COMPILE_ACTION_NAME,
651 _C_COMPILE_ACTION_NAME,
652 _CPP_COMPILE_ACTION_NAME,
653 _CPP_HEADER_PARSING_ACTION_NAME,
654 _CPP_MODULE_COMPILE_ACTION_NAME,
655 _CPP_MODULE_CODEGEN_ACTION_NAME,
656 _LTO_BACKEND_ACTION_NAME,
657 _CLIF_MATCH_ACTION_NAME,
658 ],
659 flag_groups = [flag_group(flags = ["-g"])],
660 with_features = [with_feature_set(features = ["dbg"])],
661 ),
662 flag_set(
663 actions = [
664 _ASSEMBLE_ACTION_NAME,
665 _PREPROCESS_ASSEMBLE_ACTION_NAME,
666 _LINKSTAMP_COMPILE_ACTION_NAME,
667 _C_COMPILE_ACTION_NAME,
668 _CPP_COMPILE_ACTION_NAME,
669 _CPP_HEADER_PARSING_ACTION_NAME,
670 _CPP_MODULE_COMPILE_ACTION_NAME,
671 _CPP_MODULE_CODEGEN_ACTION_NAME,
672 _LTO_BACKEND_ACTION_NAME,
673 _CLIF_MATCH_ACTION_NAME,
674 ],
675 flag_groups = [
676 flag_group(
677 flags = [
678 "-g0",
679 "-O2",
680 "-DNDEBUG",
681 "-ffunction-sections",
682 "-fdata-sections",
683 ],
684 ),
685 ],
686 with_features = [with_feature_set(features = ["opt"])],
687 ),
688 flag_set(
689 actions = [
690 _LINKSTAMP_COMPILE_ACTION_NAME,
691 _CPP_COMPILE_ACTION_NAME,
692 _CPP_HEADER_PARSING_ACTION_NAME,
693 _CPP_MODULE_COMPILE_ACTION_NAME,
694 _CPP_MODULE_CODEGEN_ACTION_NAME,
695 _LTO_BACKEND_ACTION_NAME,
696 _CLIF_MATCH_ACTION_NAME,
697 ],
698 flag_groups = [flag_group(flags = ["-std=c++0x"])],
699 ),
700 ],
701 )
aldersondrive644b7d412020-01-10 07:48:15 -0800702 elif (ctx.attr.cpu == "freebsd" or
703 ctx.attr.cpu == "openbsd"):
rosica71bc38f2019-02-04 02:39:30 -0800704 default_compile_flags_feature = feature(
705 name = "default_compile_flags",
706 enabled = True,
707 flag_sets = [
708 flag_set(
709 actions = [
710 _ASSEMBLE_ACTION_NAME,
711 _PREPROCESS_ASSEMBLE_ACTION_NAME,
712 _LINKSTAMP_COMPILE_ACTION_NAME,
713 _C_COMPILE_ACTION_NAME,
714 _CPP_COMPILE_ACTION_NAME,
715 _CPP_HEADER_PARSING_ACTION_NAME,
716 _CPP_MODULE_COMPILE_ACTION_NAME,
717 _CPP_MODULE_CODEGEN_ACTION_NAME,
718 _LTO_BACKEND_ACTION_NAME,
719 _CLIF_MATCH_ACTION_NAME,
720 ],
721 flag_groups = [
722 flag_group(
723 flags = [
724 "-U_FORTIFY_SOURCE",
725 "-D_FORTIFY_SOURCE=1",
726 "-fstack-protector",
727 "-Wall",
728 "-fno-omit-frame-pointer",
729 ],
730 ),
731 ],
732 ),
733 flag_set(
734 actions = [
735 _ASSEMBLE_ACTION_NAME,
736 _PREPROCESS_ASSEMBLE_ACTION_NAME,
737 _LINKSTAMP_COMPILE_ACTION_NAME,
738 _C_COMPILE_ACTION_NAME,
739 _CPP_COMPILE_ACTION_NAME,
740 _CPP_HEADER_PARSING_ACTION_NAME,
741 _CPP_MODULE_COMPILE_ACTION_NAME,
742 _CPP_MODULE_CODEGEN_ACTION_NAME,
743 _LTO_BACKEND_ACTION_NAME,
744 _CLIF_MATCH_ACTION_NAME,
745 ],
746 flag_groups = [flag_group(flags = ["-g"])],
747 with_features = [with_feature_set(features = ["dbg"])],
748 ),
749 flag_set(
750 actions = [
751 _ASSEMBLE_ACTION_NAME,
752 _PREPROCESS_ASSEMBLE_ACTION_NAME,
753 _LINKSTAMP_COMPILE_ACTION_NAME,
754 _C_COMPILE_ACTION_NAME,
755 _CPP_COMPILE_ACTION_NAME,
756 _CPP_HEADER_PARSING_ACTION_NAME,
757 _CPP_MODULE_COMPILE_ACTION_NAME,
758 _CPP_MODULE_CODEGEN_ACTION_NAME,
759 _LTO_BACKEND_ACTION_NAME,
760 _CLIF_MATCH_ACTION_NAME,
761 ],
762 flag_groups = [
763 flag_group(
764 flags = [
765 "-g0",
766 "-O2",
767 "-DNDEBUG",
768 "-ffunction-sections",
769 "-fdata-sections",
770 ],
771 ),
772 ],
773 with_features = [with_feature_set(features = ["opt"])],
774 ),
775 flag_set(
776 actions = [
777 _LINKSTAMP_COMPILE_ACTION_NAME,
778 _CPP_COMPILE_ACTION_NAME,
779 _CPP_HEADER_PARSING_ACTION_NAME,
780 _CPP_MODULE_COMPILE_ACTION_NAME,
781 _CPP_MODULE_CODEGEN_ACTION_NAME,
782 _LTO_BACKEND_ACTION_NAME,
783 _CLIF_MATCH_ACTION_NAME,
784 ],
785 flag_groups = [flag_group(flags = ["-std=c++0x"])],
786 ),
787 ],
788 )
789 elif (ctx.attr.cpu == "x64_windows_msvc"):
790 default_compile_flags_feature = feature(
791 name = "default_compile_flags",
792 enabled = True,
793 flag_sets = [
794 flag_set(
795 actions = [
796 _ASSEMBLE_ACTION_NAME,
797 _PREPROCESS_ASSEMBLE_ACTION_NAME,
798 _LINKSTAMP_COMPILE_ACTION_NAME,
799 _C_COMPILE_ACTION_NAME,
800 _CPP_COMPILE_ACTION_NAME,
801 _CPP_HEADER_PARSING_ACTION_NAME,
802 _CPP_MODULE_COMPILE_ACTION_NAME,
803 _CPP_MODULE_CODEGEN_ACTION_NAME,
804 _LTO_BACKEND_ACTION_NAME,
805 _CLIF_MATCH_ACTION_NAME,
806 ],
807 flag_groups = [
808 flag_group(
809 flags = [
810 "-m64",
811 "/D__inline__=__inline",
812 "/DCOMPILER_MSVC",
813 "/DNOGDI",
814 "/DNOMINMAX",
815 "/DPRAGMA_SUPPORTED",
816 "/D_WIN32_WINNT=0x0601",
817 "/D_CRT_SECURE_NO_DEPRECATE",
818 "/D_CRT_SECURE_NO_WARNINGS",
819 "/D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS",
820 "/D_USE_MATH_DEFINES",
821 "/nologo",
822 "/bigobj",
823 "/Zm500",
824 "/J",
825 "/Gy",
826 "/GF",
827 "/W3",
828 "/EHsc",
829 "/wd4351",
830 "/wd4291",
831 "/wd4250",
832 "/wd4996",
833 ],
834 ),
835 ],
836 ),
837 flag_set(
838 actions = [
839 _ASSEMBLE_ACTION_NAME,
840 _PREPROCESS_ASSEMBLE_ACTION_NAME,
841 _LINKSTAMP_COMPILE_ACTION_NAME,
842 _C_COMPILE_ACTION_NAME,
843 _CPP_COMPILE_ACTION_NAME,
844 _CPP_HEADER_PARSING_ACTION_NAME,
845 _CPP_MODULE_COMPILE_ACTION_NAME,
846 _CPP_MODULE_CODEGEN_ACTION_NAME,
847 _LTO_BACKEND_ACTION_NAME,
848 _CLIF_MATCH_ACTION_NAME,
849 ],
850 flag_groups = [
851 flag_group(
852 flags = ["/DDEBUG=1", "-g", "/Od", "-Xcompilation-mode=dbg"],
853 ),
854 ],
855 with_features = [with_feature_set(features = ["dbg"])],
856 ),
857 flag_set(
858 actions = [
859 _ASSEMBLE_ACTION_NAME,
860 _PREPROCESS_ASSEMBLE_ACTION_NAME,
861 _LINKSTAMP_COMPILE_ACTION_NAME,
862 _C_COMPILE_ACTION_NAME,
863 _CPP_COMPILE_ACTION_NAME,
864 _CPP_HEADER_PARSING_ACTION_NAME,
865 _CPP_MODULE_COMPILE_ACTION_NAME,
866 _CPP_MODULE_CODEGEN_ACTION_NAME,
867 _LTO_BACKEND_ACTION_NAME,
868 _CLIF_MATCH_ACTION_NAME,
869 ],
870 flag_groups = [
871 flag_group(
872 flags = ["/DNDEBUG", "/Od", "-Xcompilation-mode=fastbuild"],
873 ),
874 ],
875 with_features = [with_feature_set(features = ["fastbuild"])],
876 ),
877 flag_set(
878 actions = [
879 _ASSEMBLE_ACTION_NAME,
880 _PREPROCESS_ASSEMBLE_ACTION_NAME,
881 _LINKSTAMP_COMPILE_ACTION_NAME,
882 _C_COMPILE_ACTION_NAME,
883 _CPP_COMPILE_ACTION_NAME,
884 _CPP_HEADER_PARSING_ACTION_NAME,
885 _CPP_MODULE_COMPILE_ACTION_NAME,
886 _CPP_MODULE_CODEGEN_ACTION_NAME,
887 _LTO_BACKEND_ACTION_NAME,
888 _CLIF_MATCH_ACTION_NAME,
889 ],
890 flag_groups = [
891 flag_group(
892 flags = ["/DNDEBUG", "/O2", "-Xcompilation-mode=opt"],
893 ),
894 ],
895 with_features = [with_feature_set(features = ["opt"])],
896 ),
897 ],
898 )
899 elif (ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_clang" or
900 ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_mingw" or
901 ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_msys64_mingw64"):
902 default_compile_flags_feature = feature(
903 name = "default_compile_flags",
904 enabled = True,
905 flag_sets = [
906 flag_set(
907 actions = [
908 _LINKSTAMP_COMPILE_ACTION_NAME,
909 _CPP_COMPILE_ACTION_NAME,
910 _CPP_HEADER_PARSING_ACTION_NAME,
911 _CPP_MODULE_COMPILE_ACTION_NAME,
912 _CPP_MODULE_CODEGEN_ACTION_NAME,
913 _LTO_BACKEND_ACTION_NAME,
914 _CLIF_MATCH_ACTION_NAME,
915 ],
916 flag_groups = [flag_group(flags = ["-std=c++0x"])],
917 ),
918 ],
919 )
920 elif (ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_msys64"):
921 default_compile_flags_feature = feature(
922 name = "default_compile_flags",
923 enabled = True,
924 flag_sets = [
925 flag_set(
926 actions = [
927 _LINKSTAMP_COMPILE_ACTION_NAME,
928 _CPP_COMPILE_ACTION_NAME,
929 _CPP_HEADER_PARSING_ACTION_NAME,
930 _CPP_MODULE_COMPILE_ACTION_NAME,
931 _CPP_MODULE_CODEGEN_ACTION_NAME,
932 _LTO_BACKEND_ACTION_NAME,
933 _CLIF_MATCH_ACTION_NAME,
934 ],
935 flag_groups = [flag_group(flags = ["-std=gnu++0x"])],
936 ),
937 ],
938 )
939
940 opt_feature = feature(name = "opt")
941
942 supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True)
943
944 objcopy_embed_flags_feature = feature(
945 name = "objcopy_embed_flags",
946 enabled = True,
947 flag_sets = [
948 flag_set(
949 actions = ["objcopy_embed_data"],
950 flag_groups = [flag_group(flags = ["-I", "binary"])],
951 ),
952 ],
953 )
954
955 dbg_feature = feature(name = "dbg")
956
957 if (ctx.attr.cpu == "darwin" or
958 ctx.attr.cpu == "freebsd" or
aldersondrive644b7d412020-01-10 07:48:15 -0800959 ctx.attr.cpu == "openbsd" or
rosica71bc38f2019-02-04 02:39:30 -0800960 ctx.attr.cpu == "local"):
961 user_compile_flags_feature = feature(
962 name = "user_compile_flags",
963 enabled = True,
964 flag_sets = [
965 flag_set(
966 actions = [
967 _ASSEMBLE_ACTION_NAME,
968 _PREPROCESS_ASSEMBLE_ACTION_NAME,
969 _LINKSTAMP_COMPILE_ACTION_NAME,
970 _C_COMPILE_ACTION_NAME,
971 _CPP_COMPILE_ACTION_NAME,
972 _CPP_HEADER_PARSING_ACTION_NAME,
973 _CPP_MODULE_COMPILE_ACTION_NAME,
974 _CPP_MODULE_CODEGEN_ACTION_NAME,
975 _LTO_BACKEND_ACTION_NAME,
976 _CLIF_MATCH_ACTION_NAME,
977 ],
978 flag_groups = [
979 flag_group(
980 flags = ["%{user_compile_flags}"],
981 iterate_over = "user_compile_flags",
982 expand_if_available = "user_compile_flags",
983 ),
984 ],
985 ),
986 ],
987 )
988 elif (ctx.attr.cpu == "x64_windows_msvc"):
989 user_compile_flags_feature = feature(
990 name = "user_compile_flags",
991 flag_sets = [
992 flag_set(
993 actions = [
994 _ASSEMBLE_ACTION_NAME,
995 _PREPROCESS_ASSEMBLE_ACTION_NAME,
996 _C_COMPILE_ACTION_NAME,
997 _CPP_COMPILE_ACTION_NAME,
998 _CPP_HEADER_PARSING_ACTION_NAME,
999 _CPP_MODULE_COMPILE_ACTION_NAME,
1000 _CPP_MODULE_CODEGEN_ACTION_NAME,
1001 ],
1002 flag_groups = [
1003 flag_group(
1004 flags = ["%{user_compile_flags}"],
1005 iterate_over = "user_compile_flags",
1006 expand_if_available = "user_compile_flags",
1007 ),
1008 ],
1009 ),
1010 ],
1011 )
1012
1013 if (ctx.attr.cpu == "darwin" or
1014 ctx.attr.cpu == "freebsd" or
aldersondrive644b7d412020-01-10 07:48:15 -08001015 ctx.attr.cpu == "openbsd" or
rosica71bc38f2019-02-04 02:39:30 -08001016 ctx.attr.cpu == "local"):
1017 sysroot_feature = feature(
1018 name = "sysroot",
1019 enabled = True,
1020 flag_sets = [
1021 flag_set(
1022 actions = [
1023 _PREPROCESS_ASSEMBLE_ACTION_NAME,
1024 _LINKSTAMP_COMPILE_ACTION_NAME,
1025 _C_COMPILE_ACTION_NAME,
1026 _CPP_COMPILE_ACTION_NAME,
1027 _CPP_HEADER_PARSING_ACTION_NAME,
1028 _CPP_MODULE_COMPILE_ACTION_NAME,
1029 _CPP_MODULE_CODEGEN_ACTION_NAME,
1030 _LTO_BACKEND_ACTION_NAME,
1031 _CLIF_MATCH_ACTION_NAME,
1032 _CPP_LINK_EXECUTABLE_ACTION_NAME,
1033 _CPP_LINK_DYNAMIC_LIBRARY_ACTION_NAME,
1034 _CPP_LINK_NODEPS_DYNAMIC_LIBRARY_ACTION_NAME,
1035 ],
1036 flag_groups = [
1037 flag_group(
1038 flags = ["--sysroot=%{sysroot}"],
1039 expand_if_available = "sysroot",
1040 ),
1041 ],
1042 ),
1043 ],
1044 )
1045 elif (ctx.attr.cpu == "x64_windows_msvc"):
1046 sysroot_feature = feature(
1047 name = "sysroot",
1048 flag_sets = [
1049 flag_set(
1050 actions = [
1051 _ASSEMBLE_ACTION_NAME,
1052 _PREPROCESS_ASSEMBLE_ACTION_NAME,
1053 _C_COMPILE_ACTION_NAME,
1054 _CPP_COMPILE_ACTION_NAME,
1055 _CPP_HEADER_PARSING_ACTION_NAME,
1056 _CPP_MODULE_COMPILE_ACTION_NAME,
1057 _CPP_MODULE_CODEGEN_ACTION_NAME,
1058 _CPP_LINK_EXECUTABLE_ACTION_NAME,
1059 _CPP_LINK_DYNAMIC_LIBRARY_ACTION_NAME,
1060 _CPP_LINK_NODEPS_DYNAMIC_LIBRARY_ACTION_NAME,
1061 ],
1062 flag_groups = [
1063 flag_group(
1064 flags = ["--sysroot=%{sysroot}"],
1065 iterate_over = "sysroot",
1066 expand_if_available = "sysroot",
1067 ),
1068 ],
1069 ),
1070 ],
1071 )
1072
1073 include_paths_feature = feature(
1074 name = "include_paths",
hlopko2f17a862019-02-26 07:56:03 -08001075 enabled = True,
rosica71bc38f2019-02-04 02:39:30 -08001076 flag_sets = [
1077 flag_set(
1078 actions = [
1079 _PREPROCESS_ASSEMBLE_ACTION_NAME,
1080 _C_COMPILE_ACTION_NAME,
1081 _CPP_COMPILE_ACTION_NAME,
1082 _CPP_HEADER_PARSING_ACTION_NAME,
1083 _CPP_MODULE_COMPILE_ACTION_NAME,
1084 ],
1085 flag_groups = [
1086 flag_group(
1087 flags = ["/I%{quote_include_paths}"],
1088 iterate_over = "quote_include_paths",
1089 ),
1090 flag_group(
1091 flags = ["/I%{include_paths}"],
1092 iterate_over = "include_paths",
1093 ),
1094 flag_group(
1095 flags = ["/I%{system_include_paths}"],
1096 iterate_over = "system_include_paths",
1097 ),
1098 ],
1099 ),
1100 ],
1101 )
1102
1103 dependency_file_feature = feature(
1104 name = "dependency_file",
hlopko2f17a862019-02-26 07:56:03 -08001105 enabled = True,
rosica71bc38f2019-02-04 02:39:30 -08001106 flag_sets = [
1107 flag_set(
1108 actions = [
1109 _ASSEMBLE_ACTION_NAME,
1110 _PREPROCESS_ASSEMBLE_ACTION_NAME,
1111 _C_COMPILE_ACTION_NAME,
1112 _CPP_COMPILE_ACTION_NAME,
1113 _CPP_MODULE_COMPILE_ACTION_NAME,
1114 _CPP_HEADER_PARSING_ACTION_NAME,
1115 ],
1116 flag_groups = [
1117 flag_group(
1118 flags = ["/DEPENDENCY_FILE", "%{dependency_file}"],
1119 expand_if_available = "dependency_file",
1120 ),
1121 ],
1122 ),
1123 ],
1124 )
1125
1126 compiler_input_flags_feature = feature(
1127 name = "compiler_input_flags",
1128 flag_sets = [
1129 flag_set(
1130 actions = [
1131 _ASSEMBLE_ACTION_NAME,
1132 _PREPROCESS_ASSEMBLE_ACTION_NAME,
1133 _C_COMPILE_ACTION_NAME,
1134 _CPP_COMPILE_ACTION_NAME,
1135 _CPP_HEADER_PARSING_ACTION_NAME,
1136 _CPP_MODULE_COMPILE_ACTION_NAME,
1137 _CPP_MODULE_CODEGEN_ACTION_NAME,
1138 ],
1139 flag_groups = [
1140 flag_group(
1141 flags = ["/c", "%{source_file}"],
1142 expand_if_available = "source_file",
1143 ),
1144 ],
1145 ),
1146 ],
1147 )
1148
1149 fastbuild_feature = feature(name = "fastbuild")
1150
1151 if (ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_msys64"):
1152 features = [
1153 default_compile_flags_feature,
1154 default_link_flags_feature,
1155 supports_dynamic_linker_feature,
1156 objcopy_embed_flags_feature,
1157 ]
1158 elif (ctx.attr.cpu == "darwin"):
1159 features = [
1160 default_compile_flags_feature,
1161 default_link_flags_feature,
rosica71bc38f2019-02-04 02:39:30 -08001162 supports_pic_feature,
1163 objcopy_embed_flags_feature,
1164 dbg_feature,
1165 opt_feature,
1166 user_compile_flags_feature,
1167 sysroot_feature,
1168 unfiltered_compile_flags_feature,
1169 ]
1170 elif (ctx.attr.cpu == "freebsd" or
aldersondrive644b7d412020-01-10 07:48:15 -08001171 ctx.attr.cpu == "openbsd" or
rosica71bc38f2019-02-04 02:39:30 -08001172 ctx.attr.cpu == "local"):
1173 features = [
1174 default_compile_flags_feature,
1175 default_link_flags_feature,
1176 supports_dynamic_linker_feature,
1177 supports_pic_feature,
1178 objcopy_embed_flags_feature,
1179 opt_feature,
1180 dbg_feature,
1181 user_compile_flags_feature,
1182 sysroot_feature,
1183 unfiltered_compile_flags_feature,
1184 ]
1185 elif (ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_clang" or
1186 ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_mingw" or
1187 ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_msys64_mingw64"):
1188 features = [
1189 default_compile_flags_feature,
1190 supports_dynamic_linker_feature,
1191 objcopy_embed_flags_feature,
1192 ]
1193 elif (ctx.attr.cpu == "x64_windows_msvc"):
1194 features = [
1195 default_link_flags_feature,
1196 random_seed_feature,
1197 default_compile_flags_feature,
1198 include_paths_feature,
1199 dependency_file_feature,
1200 user_compile_flags_feature,
1201 sysroot_feature,
1202 unfiltered_compile_flags_feature,
1203 compiler_output_flags_feature,
1204 compiler_input_flags_feature,
1205 dbg_feature,
1206 fastbuild_feature,
1207 opt_feature,
1208 ]
1209 elif (ctx.attr.cpu == "armeabi-v7a"):
1210 features = [supports_dynamic_linker_feature, supports_pic_feature]
1211
1212 if (ctx.attr.cpu == "armeabi-v7a"):
1213 cxx_builtin_include_directories = []
1214 elif (ctx.attr.cpu == "darwin"):
1215 cxx_builtin_include_directories = ["/"]
aldersondrive644b7d412020-01-10 07:48:15 -08001216 elif (ctx.attr.cpu == "freebsd" or
1217 ctx.attr.cpu == "openbsd"):
rosica71bc38f2019-02-04 02:39:30 -08001218 cxx_builtin_include_directories = ["/usr/lib/clang", "/usr/local/include", "/usr/include"]
1219 elif (ctx.attr.cpu == "local" or
1220 ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_clang"):
1221 cxx_builtin_include_directories = ["/usr/lib/gcc/", "/usr/local/include", "/usr/include"]
1222 elif (ctx.attr.cpu == "x64_windows_msvc"):
1223 cxx_builtin_include_directories = [
1224 "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/INCLUDE",
1225 "C:/Program Files (x86)/Windows Kits/10/include/",
1226 "C:/Program Files (x86)/Windows Kits/8.1/include/",
1227 "C:/Program Files (x86)/GnuWin32/include/",
1228 "C:/python_27_amd64/files/include",
1229 ]
1230 elif (ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_mingw"):
1231 cxx_builtin_include_directories = ["C:/mingw/include", "C:/mingw/lib/gcc"]
1232 elif (ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_msys64_mingw64"):
1233 cxx_builtin_include_directories = ["C:/tools/msys64/mingw64/x86_64-w64-mingw32/include"]
1234 elif (ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_msys64"):
1235 cxx_builtin_include_directories = ["C:/tools/msys64/", "/usr/"]
1236 else:
1237 fail("Unreachable")
1238
1239 artifact_name_patterns = []
1240
1241 make_variables = []
1242
1243 if (ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_msys64_mingw64"):
1244 tool_paths = [
1245 tool_path(
1246 name = "ar",
1247 path = "C:/tools/msys64/mingw64/bin/ar",
1248 ),
1249 tool_path(
1250 name = "compat-ld",
1251 path = "C:/tools/msys64/mingw64/bin/ld",
1252 ),
1253 tool_path(
1254 name = "cpp",
1255 path = "C:/tools/msys64/mingw64/bin/cpp",
1256 ),
1257 tool_path(
1258 name = "dwp",
1259 path = "C:/tools/msys64/mingw64/bin/dwp",
1260 ),
1261 tool_path(
1262 name = "gcc",
1263 path = "C:/tools/msys64/mingw64/bin/gcc",
1264 ),
1265 tool_path(
1266 name = "gcov",
1267 path = "C:/tools/msys64/mingw64/bin/gcov",
1268 ),
1269 tool_path(
1270 name = "ld",
1271 path = "C:/tools/msys64/mingw64/bin/ld",
1272 ),
1273 tool_path(
1274 name = "nm",
1275 path = "C:/tools/msys64/mingw64/bin/nm",
1276 ),
1277 tool_path(
1278 name = "objcopy",
1279 path = "C:/tools/msys64/mingw64/bin/objcopy",
1280 ),
1281 tool_path(
1282 name = "objdump",
1283 path = "C:/tools/msys64/mingw64/bin/objdump",
1284 ),
1285 tool_path(
1286 name = "strip",
1287 path = "C:/tools/msys64/mingw64/bin/strip",
1288 ),
1289 ]
1290 elif (ctx.attr.cpu == "armeabi-v7a"):
1291 tool_paths = [
1292 tool_path(name = "ar", path = "/bin/false"),
1293 tool_path(name = "compat-ld", path = "/bin/false"),
1294 tool_path(name = "cpp", path = "/bin/false"),
1295 tool_path(name = "dwp", path = "/bin/false"),
1296 tool_path(name = "gcc", path = "/bin/false"),
1297 tool_path(name = "gcov", path = "/bin/false"),
1298 tool_path(name = "ld", path = "/bin/false"),
1299 tool_path(name = "nm", path = "/bin/false"),
1300 tool_path(name = "objcopy", path = "/bin/false"),
1301 tool_path(name = "objdump", path = "/bin/false"),
1302 tool_path(name = "strip", path = "/bin/false"),
1303 ]
1304 elif (ctx.attr.cpu == "freebsd"):
1305 tool_paths = [
1306 tool_path(name = "ar", path = "/usr/bin/ar"),
1307 tool_path(name = "compat-ld", path = "/usr/bin/ld"),
1308 tool_path(name = "cpp", path = "/usr/bin/cpp"),
1309 tool_path(name = "dwp", path = "/usr/bin/dwp"),
1310 tool_path(name = "gcc", path = "/usr/bin/clang"),
1311 tool_path(name = "gcov", path = "/usr/bin/gcov"),
1312 tool_path(name = "ld", path = "/usr/bin/ld"),
1313 tool_path(name = "nm", path = "/usr/bin/nm"),
1314 tool_path(name = "objcopy", path = "/usr/bin/objcopy"),
1315 tool_path(name = "objdump", path = "/usr/bin/objdump"),
1316 tool_path(name = "strip", path = "/usr/bin/strip"),
1317 ]
aldersondrive644b7d412020-01-10 07:48:15 -08001318 elif (ctx.attr.cpu == "openbsd"):
1319 tool_paths = [
1320 tool_path(name = "ar", path = "/usr/bin/ar"),
1321 tool_path(name = "compat-ld", path = "/usr/bin/ld"),
1322 tool_path(name = "cpp", path = "/usr/bin/cpp"),
1323 tool_path(name = "dwp", path = "/usr/bin/false"),
1324 tool_path(name = "gcc", path = "/usr/bin/clang"),
1325 tool_path(name = "gcov", path = "/usr/bin/gcov"),
1326 tool_path(name = "ld", path = "/usr/bin/ld"),
1327 tool_path(name = "nm", path = "/usr/bin/nm"),
1328 tool_path(name = "objcopy", path = "/usr/bin/objcopy"),
1329 tool_path(name = "objdump", path = "/usr/bin/objdump"),
1330 tool_path(name = "strip", path = "/usr/bin/strip"),
1331 ]
rosica71bc38f2019-02-04 02:39:30 -08001332 elif (ctx.attr.cpu == "local"):
1333 tool_paths = [
1334 tool_path(name = "ar", path = "/usr/bin/ar"),
1335 tool_path(name = "compat-ld", path = "/usr/bin/ld"),
1336 tool_path(name = "cpp", path = "/usr/bin/cpp"),
1337 tool_path(name = "dwp", path = "/usr/bin/dwp"),
1338 tool_path(name = "gcc", path = "/usr/bin/gcc"),
1339 tool_path(name = "gcov", path = "/usr/bin/gcov"),
1340 tool_path(name = "ld", path = "/usr/bin/ld"),
1341 tool_path(name = "nm", path = "/usr/bin/nm"),
1342 tool_path(name = "objcopy", path = "/usr/bin/objcopy"),
1343 tool_path(name = "objdump", path = "/usr/bin/objdump"),
1344 tool_path(name = "strip", path = "/usr/bin/strip"),
1345 ]
1346 elif (ctx.attr.cpu == "darwin"):
1347 tool_paths = [
1348 tool_path(name = "ar", path = "/usr/bin/libtool"),
1349 tool_path(name = "compat-ld", path = "/usr/bin/ld"),
1350 tool_path(name = "cpp", path = "/usr/bin/cpp"),
1351 tool_path(name = "dwp", path = "/usr/bin/dwp"),
1352 tool_path(name = "gcc", path = "osx_cc_wrapper.sh"),
1353 tool_path(name = "gcov", path = "/usr/bin/gcov"),
1354 tool_path(name = "ld", path = "/usr/bin/ld"),
1355 tool_path(name = "nm", path = "/usr/bin/nm"),
1356 tool_path(name = "objcopy", path = "/usr/bin/objcopy"),
1357 tool_path(name = "objdump", path = "/usr/bin/objdump"),
1358 tool_path(name = "strip", path = "/usr/bin/strip"),
1359 ]
1360 elif (ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_clang"):
1361 tool_paths = [
1362 tool_path(name = "ar", path = "C:/mingw/bin/ar"),
1363 tool_path(
1364 name = "compat-ld",
1365 path = "C:/Program Files (x86)/LLVM/bin/ld",
1366 ),
1367 tool_path(
1368 name = "cpp",
1369 path = "C:/Program Files (x86)/LLVM/bin/cpp",
1370 ),
1371 tool_path(
1372 name = "dwp",
1373 path = "C:/Program Files (x86)/LLVM/bin/dwp",
1374 ),
1375 tool_path(
1376 name = "gcc",
1377 path = "C:/Program Files (x86)/LLVM/bin/clang",
1378 ),
1379 tool_path(
1380 name = "gcov",
1381 path = "C:/Program Files (x86)/LLVM/bin/gcov",
1382 ),
1383 tool_path(
1384 name = "ld",
1385 path = "C:/Program Files (x86)/LLVM/bin/ld",
1386 ),
1387 tool_path(
1388 name = "nm",
1389 path = "C:/Program Files (x86)/LLVM/bin/nm",
1390 ),
1391 tool_path(
1392 name = "objcopy",
1393 path = "C:/Program Files (x86)/LLVM/bin/objcopy",
1394 ),
1395 tool_path(
1396 name = "objdump",
1397 path = "C:/Program Files (x86)/LLVM/bin/objdump",
1398 ),
1399 tool_path(
1400 name = "strip",
1401 path = "C:/Program Files (x86)/LLVM/bin/strip",
1402 ),
1403 ]
1404 elif (ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_mingw"):
1405 tool_paths = [
1406 tool_path(name = "ar", path = "C:/mingw/bin/ar"),
1407 tool_path(name = "compat-ld", path = "C:/mingw/bin/ld"),
1408 tool_path(name = "cpp", path = "C:/mingw/bin/cpp"),
1409 tool_path(name = "dwp", path = "C:/mingw/bin/dwp"),
1410 tool_path(name = "gcc", path = "C:/mingw/bin/gcc"),
1411 tool_path(name = "gcov", path = "C:/mingw/bin/gcov"),
1412 tool_path(name = "ld", path = "C:/mingw/bin/ld"),
1413 tool_path(name = "nm", path = "C:/mingw/bin/nm"),
1414 tool_path(name = "objcopy", path = "C:/mingw/bin/objcopy"),
1415 tool_path(name = "objdump", path = "C:/mingw/bin/objdump"),
1416 tool_path(name = "strip", path = "C:/mingw/bin/strip"),
1417 ]
1418 elif (ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_msys64"):
1419 tool_paths = [
1420 tool_path(name = "ar", path = "C:/tools/msys64/usr/bin/ar"),
1421 tool_path(
1422 name = "compat-ld",
1423 path = "C:/tools/msys64/usr/bin/ld",
1424 ),
1425 tool_path(
1426 name = "cpp",
1427 path = "C:/tools/msys64/usr/bin/cpp",
1428 ),
1429 tool_path(
1430 name = "dwp",
1431 path = "C:/tools/msys64/usr/bin/dwp",
1432 ),
1433 tool_path(
1434 name = "gcc",
1435 path = "C:/tools/msys64/usr/bin/gcc",
1436 ),
1437 tool_path(
1438 name = "gcov",
1439 path = "C:/tools/msys64/usr/bin/gcov",
1440 ),
1441 tool_path(name = "ld", path = "C:/tools/msys64/usr/bin/ld"),
1442 tool_path(name = "nm", path = "C:/tools/msys64/usr/bin/nm"),
1443 tool_path(
1444 name = "objcopy",
1445 path = "C:/tools/msys64/usr/bin/objcopy",
1446 ),
1447 tool_path(
1448 name = "objdump",
1449 path = "C:/tools/msys64/usr/bin/objdump",
1450 ),
1451 tool_path(
1452 name = "strip",
1453 path = "C:/tools/msys64/usr/bin/strip",
1454 ),
1455 ]
1456 elif (ctx.attr.cpu == "x64_windows_msvc"):
1457 tool_paths = [
1458 tool_path(name = "ar", path = "wrapper/bin/msvc_link.bat"),
1459 tool_path(name = "cpp", path = "wrapper/bin/msvc_cl.bat"),
1460 tool_path(name = "gcc", path = "wrapper/bin/msvc_cl.bat"),
1461 tool_path(name = "gcov", path = "wrapper/bin/msvc_nop.bat"),
1462 tool_path(name = "ld", path = "wrapper/bin/msvc_link.bat"),
1463 tool_path(name = "nm", path = "wrapper/bin/msvc_nop.bat"),
1464 tool_path(
1465 name = "objcopy",
1466 path = "wrapper/bin/msvc_nop.bat",
1467 ),
1468 tool_path(
1469 name = "objdump",
1470 path = "wrapper/bin/msvc_nop.bat",
1471 ),
1472 tool_path(
1473 name = "strip",
1474 path = "wrapper/bin/msvc_nop.bat",
1475 ),
1476 ]
1477 else:
1478 fail("Unreachable")
1479
1480 out = ctx.actions.declare_file(ctx.label.name)
1481 ctx.actions.write(out, "Fake executable")
1482 return [
1483 cc_common.create_cc_toolchain_config_info(
1484 ctx = ctx,
1485 features = features,
1486 action_configs = action_configs,
1487 artifact_name_patterns = artifact_name_patterns,
1488 cxx_builtin_include_directories = cxx_builtin_include_directories,
1489 toolchain_identifier = toolchain_identifier,
1490 host_system_name = host_system_name,
1491 target_system_name = target_system_name,
1492 target_cpu = target_cpu,
1493 target_libc = target_libc,
1494 compiler = compiler,
1495 abi_version = abi_version,
1496 abi_libc_version = abi_libc_version,
1497 tool_paths = tool_paths,
1498 make_variables = make_variables,
1499 builtin_sysroot = builtin_sysroot,
1500 cc_target_os = cc_target_os,
1501 ),
1502 DefaultInfo(
1503 executable = out,
1504 ),
1505 ]
1506
1507cc_toolchain_config = rule(
1508 implementation = _impl,
1509 attrs = {
1510 "cpu": attr.string(mandatory = True),
1511 "compiler": attr.string(),
rosicac5ebfcf2019-06-04 01:47:17 -07001512 "disable_static_cc_toolchains": attr.bool(),
rosica71bc38f2019-02-04 02:39:30 -08001513 },
1514 provides = [CcToolchainConfigInfo],
1515 executable = True,
1516)