blob: 6a306b682a505dff77b2d499069df56c484ed044 [file] [log] [blame]
Austin Schuha2503a72020-12-15 20:57:57 -08001load(
2 "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
Austin Schuhda9d0602019-09-15 17:29:38 -07003 "action_config",
Austin Schuhda9d0602019-09-15 17:29:38 -07004 "feature",
Austin Schuhda9d0602019-09-15 17:29:38 -07005 "flag_group",
6 "flag_set",
Austin Schuhda9d0602019-09-15 17:29:38 -07007 "tool",
8 "tool_path",
Austin Schuhda9d0602019-09-15 17:29:38 -07009 "with_feature_set",
10)
11load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
12
13def _impl(ctx):
14 if (ctx.attr.cpu == "armhf-debian"):
15 toolchain_identifier = "clang_linux_armhf"
Austin Schuh0a96ea32022-01-01 22:29:30 -080016 elif (ctx.attr.cpu == "rp2040"):
17 toolchain_identifier = "rp2040"
Austin Schuhda9d0602019-09-15 17:29:38 -070018 elif (ctx.attr.cpu == "cortex-m4f"):
19 toolchain_identifier = "cortex-m4f"
20 elif (ctx.attr.cpu == "cortex-m4f-k22"):
21 toolchain_identifier = "cortex-m4f-k22"
22 elif (ctx.attr.cpu == "k8"):
23 toolchain_identifier = "k8_linux"
24 elif (ctx.attr.cpu == "roborio"):
25 toolchain_identifier = "roborio_linux"
26 elif (ctx.attr.cpu == "armeabi-v7a"):
27 toolchain_identifier = "stub_armeabi-v7a"
28 else:
29 fail("Unreachable")
30
31 if (ctx.attr.cpu == "armeabi-v7a"):
32 host_system_name = "armeabi-v7a"
33 elif (ctx.attr.cpu == "armhf-debian"):
34 host_system_name = "linux"
Austin Schuh0a96ea32022-01-01 22:29:30 -080035 elif (ctx.attr.cpu == "rp2040" or
36 ctx.attr.cpu == "cortex-m4f" or
Austin Schuha2503a72020-12-15 20:57:57 -080037 ctx.attr.cpu == "cortex-m4f-k22" or
38 ctx.attr.cpu == "k8"):
Austin Schuhda9d0602019-09-15 17:29:38 -070039 host_system_name = "local"
40 elif (ctx.attr.cpu == "roborio"):
41 host_system_name = "roborio"
42 else:
43 fail("Unreachable")
44
45 if (ctx.attr.cpu == "armhf-debian"):
46 target_system_name = "arm_a15"
47 elif (ctx.attr.cpu == "armeabi-v7a"):
48 target_system_name = "armeabi-v7a"
Austin Schuh0a96ea32022-01-01 22:29:30 -080049 elif (ctx.attr.cpu == "rp2040"):
50 target_system_name = "rp2040"
Austin Schuhda9d0602019-09-15 17:29:38 -070051 elif (ctx.attr.cpu == "cortex-m4f"):
52 target_system_name = "cortex-m4f"
53 elif (ctx.attr.cpu == "cortex-m4f-k22"):
54 target_system_name = "cortex-m4f-k22"
55 elif (ctx.attr.cpu == "k8"):
56 target_system_name = "k8"
57 elif (ctx.attr.cpu == "roborio"):
58 target_system_name = "roborio"
59 else:
60 fail("Unreachable")
61
62 if (ctx.attr.cpu == "armeabi-v7a"):
63 target_cpu = "armeabi-v7a"
64 elif (ctx.attr.cpu == "armhf-debian"):
65 target_cpu = "armhf-debian"
Austin Schuh0a96ea32022-01-01 22:29:30 -080066 elif (ctx.attr.cpu == "rp2040"):
67 target_cpu = "rp2040"
Austin Schuhda9d0602019-09-15 17:29:38 -070068 elif (ctx.attr.cpu == "cortex-m4f"):
69 target_cpu = "cortex-m4f"
70 elif (ctx.attr.cpu == "cortex-m4f-k22"):
71 target_cpu = "cortex-m4f-k22"
72 elif (ctx.attr.cpu == "k8"):
73 target_cpu = "k8"
74 elif (ctx.attr.cpu == "roborio"):
75 target_cpu = "roborio"
76 else:
77 fail("Unreachable")
78
79 if (ctx.attr.cpu == "armeabi-v7a"):
80 target_libc = "armeabi-v7a"
Austin Schuh0a96ea32022-01-01 22:29:30 -080081 elif (ctx.attr.cpu == "rp2040"):
82 target_libc = "rp2040"
Austin Schuhda9d0602019-09-15 17:29:38 -070083 elif (ctx.attr.cpu == "cortex-m4f"):
84 target_libc = "cortex-m4f"
85 elif (ctx.attr.cpu == "cortex-m4f-k22"):
86 target_libc = "cortex-m4f-k22"
87 elif (ctx.attr.cpu == "armhf-debian"):
88 target_libc = "glibc_2.19"
89 elif (ctx.attr.cpu == "k8"):
90 target_libc = "local"
91 elif (ctx.attr.cpu == "roborio"):
92 target_libc = "roborio"
93 else:
94 fail("Unreachable")
95
Austin Schuha2503a72020-12-15 20:57:57 -080096 if (ctx.attr.cpu == "armhf-debian" or
97 ctx.attr.cpu == "k8"):
Austin Schuhda9d0602019-09-15 17:29:38 -070098 compiler = "clang"
99 elif (ctx.attr.cpu == "armeabi-v7a"):
100 compiler = "compiler"
Austin Schuh0a96ea32022-01-01 22:29:30 -0800101 elif (ctx.attr.cpu == "rp2040" or
102 ctx.attr.cpu == "cortex-m4f" or
Austin Schuha2503a72020-12-15 20:57:57 -0800103 ctx.attr.cpu == "cortex-m4f-k22" or
104 ctx.attr.cpu == "roborio"):
Austin Schuhda9d0602019-09-15 17:29:38 -0700105 compiler = "gcc"
106 else:
107 fail("Unreachable")
108
109 if (ctx.attr.cpu == "armeabi-v7a"):
110 abi_version = "armeabi-v7a"
111 elif (ctx.attr.cpu == "armhf-debian"):
112 abi_version = "clang_6.0"
Austin Schuh0a96ea32022-01-01 22:29:30 -0800113 elif (ctx.attr.cpu == "rp2040"):
114 abi_version = "rp2040"
Austin Schuhda9d0602019-09-15 17:29:38 -0700115 elif (ctx.attr.cpu == "cortex-m4f"):
116 abi_version = "cortex-m4f"
117 elif (ctx.attr.cpu == "cortex-m4f-k22"):
118 abi_version = "cortex-m4f-k22"
119 elif (ctx.attr.cpu == "k8"):
120 abi_version = "local"
121 elif (ctx.attr.cpu == "roborio"):
122 abi_version = "roborio"
123 else:
124 fail("Unreachable")
125
126 if (ctx.attr.cpu == "armeabi-v7a"):
127 abi_libc_version = "armeabi-v7a"
Austin Schuh0a96ea32022-01-01 22:29:30 -0800128 elif (ctx.attr.cpu == "rp2040"):
129 abi_libc_version = "rp2040"
Austin Schuhda9d0602019-09-15 17:29:38 -0700130 elif (ctx.attr.cpu == "cortex-m4f"):
131 abi_libc_version = "cortex-m4f"
132 elif (ctx.attr.cpu == "cortex-m4f-k22"):
133 abi_libc_version = "cortex-m4f-k22"
134 elif (ctx.attr.cpu == "armhf-debian"):
135 abi_libc_version = "glibc_2.19"
136 elif (ctx.attr.cpu == "k8"):
137 abi_libc_version = "local"
138 elif (ctx.attr.cpu == "roborio"):
139 abi_libc_version = "roborio"
140 else:
141 fail("Unreachable")
142
143 cc_target_os = None
144
145 builtin_sysroot = None
146
147 all_compile_actions = [
148 ACTION_NAMES.c_compile,
149 ACTION_NAMES.cpp_compile,
150 ACTION_NAMES.linkstamp_compile,
151 ACTION_NAMES.assemble,
152 ACTION_NAMES.preprocess_assemble,
153 ACTION_NAMES.cpp_header_parsing,
154 ACTION_NAMES.cpp_module_compile,
155 ACTION_NAMES.cpp_module_codegen,
156 ACTION_NAMES.clif_match,
157 ACTION_NAMES.lto_backend,
158 ]
159
160 all_cpp_compile_actions = [
161 ACTION_NAMES.cpp_compile,
162 ACTION_NAMES.linkstamp_compile,
163 ACTION_NAMES.cpp_header_parsing,
164 ACTION_NAMES.cpp_module_compile,
165 ACTION_NAMES.cpp_module_codegen,
166 ACTION_NAMES.clif_match,
167 ]
168
169 preprocessor_compile_actions = [
170 ACTION_NAMES.c_compile,
171 ACTION_NAMES.cpp_compile,
172 ACTION_NAMES.linkstamp_compile,
173 ACTION_NAMES.preprocess_assemble,
174 ACTION_NAMES.cpp_header_parsing,
175 ACTION_NAMES.cpp_module_compile,
176 ACTION_NAMES.clif_match,
177 ]
178
179 codegen_compile_actions = [
180 ACTION_NAMES.c_compile,
181 ACTION_NAMES.cpp_compile,
182 ACTION_NAMES.linkstamp_compile,
183 ACTION_NAMES.assemble,
184 ACTION_NAMES.preprocess_assemble,
185 ACTION_NAMES.cpp_module_codegen,
186 ACTION_NAMES.lto_backend,
187 ]
188
189 all_link_actions = [
190 ACTION_NAMES.cpp_link_executable,
191 ACTION_NAMES.cpp_link_dynamic_library,
192 ACTION_NAMES.cpp_link_nodeps_dynamic_library,
193 ]
194
195 if (ctx.attr.cpu == "roborio"):
196 objcopy_embed_data_action = action_config(
197 action_name = "objcopy_embed_data",
198 enabled = True,
199 tools = [
200 tool(
201 path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-objcopy",
202 ),
203 ],
204 )
205 elif (ctx.attr.cpu == "armhf-debian"):
206 objcopy_embed_data_action = action_config(
207 action_name = "objcopy_embed_data",
208 enabled = True,
209 tools = [
210 tool(path = "linaro_linux_gcc/arm-linux-gnueabihf-objcopy"),
211 ],
212 )
213 elif (ctx.attr.cpu == "k8"):
214 objcopy_embed_data_action = action_config(
215 action_name = "objcopy_embed_data",
216 enabled = True,
217 tools = [tool(path = "clang_6p0/x86_64-linux-gnu-objcopy")],
218 )
Austin Schuh0a96ea32022-01-01 22:29:30 -0800219 elif (ctx.attr.cpu == "rp2040" or
220 ctx.attr.cpu == "cortex-m4f" or
Austin Schuha2503a72020-12-15 20:57:57 -0800221 ctx.attr.cpu == "cortex-m4f-k22"):
Austin Schuhda9d0602019-09-15 17:29:38 -0700222 objcopy_embed_data_action = action_config(
223 action_name = "objcopy_embed_data",
224 enabled = True,
225 tools = [tool(path = "gcc_arm_none_eabi/arm-none-eabi-objcopy")],
226 )
227 else:
228 objcopy_embed_data_action = None
229
230 if (ctx.attr.cpu == "armeabi-v7a"):
231 action_configs = []
Austin Schuha2503a72020-12-15 20:57:57 -0800232 elif (ctx.attr.cpu == "armhf-debian" or
Austin Schuh0a96ea32022-01-01 22:29:30 -0800233 ctx.attr.cpu == "rp2040" or
Austin Schuha2503a72020-12-15 20:57:57 -0800234 ctx.attr.cpu == "cortex-m4f" or
235 ctx.attr.cpu == "cortex-m4f-k22" or
236 ctx.attr.cpu == "k8" or
237 ctx.attr.cpu == "roborio"):
Austin Schuhda9d0602019-09-15 17:29:38 -0700238 action_configs = [objcopy_embed_data_action]
239 else:
240 fail("Unreachable")
241
242 opt_post_feature = feature(
243 name = "opt_post",
244 flag_sets = [
245 flag_set(
246 actions = [
247 ACTION_NAMES.preprocess_assemble,
248 ACTION_NAMES.c_compile,
249 ACTION_NAMES.cpp_compile,
250 ACTION_NAMES.cpp_header_parsing,
251 "c++-header-preprocessing",
252 ACTION_NAMES.cpp_module_compile,
253 ],
254 flag_groups = [flag_group(flags = ["-DAOS_DEBUG=0"])],
255 ),
256 ],
257 )
258
259 supports_pic_feature = feature(name = "supports_pic", enabled = True)
260
261 if (ctx.attr.cpu == "k8"):
262 default_compile_flags_feature = feature(
263 name = "default_compile_flags",
264 enabled = True,
265 flag_sets = [
266 flag_set(
267 actions = [
268 ACTION_NAMES.assemble,
269 ACTION_NAMES.preprocess_assemble,
270 ACTION_NAMES.linkstamp_compile,
271 ACTION_NAMES.c_compile,
272 ACTION_NAMES.cpp_compile,
273 ACTION_NAMES.cpp_header_parsing,
274 ACTION_NAMES.cpp_module_compile,
275 ACTION_NAMES.cpp_module_codegen,
276 ACTION_NAMES.lto_backend,
277 ACTION_NAMES.clif_match,
278 ],
279 flag_groups = [
280 flag_group(
281 flags = [
282 "--sysroot=external/amd64_debian_sysroot",
283 "-nostdinc",
284 "-isystem",
285 "external/amd64_debian_sysroot/usr/include/c++/7",
286 "-isystem",
287 "external/amd64_debian_sysroot/usr/include/x86_64-linux-gnu/c++/7",
288 "-isystem",
289 "external/amd64_debian_sysroot/usr/include/c++/8/backward",
290 "-isystem",
291 "external/amd64_debian_sysroot/usr/lib/gcc/x86_64-linux-gnu/8/include",
292 "-isystem",
293 "external/clang_6p0_repo/usr/lib/llvm-6.0/lib/clang/6.0.0/include",
294 "-isystem",
295 "external/amd64_debian_sysroot/usr/include/x86_64-linux-gnu",
296 "-isystem",
297 "external/amd64_debian_sysroot/usr/include",
298 "-D__STDC_FORMAT_MACROS",
299 "-D__STDC_CONSTANT_MACROS",
300 "-D__STDC_LIMIT_MACROS",
301 "-D_FILE_OFFSET_BITS=64",
Austin Schuhda9d0602019-09-15 17:29:38 -0700302 "-U_FORTIFY_SOURCE",
303 "-D_FORTIFY_SOURCE=1",
304 "-fstack-protector",
305 "-fPIE",
306 "-fcolor-diagnostics",
307 "-fmessage-length=80",
308 "-fmacro-backtrace-limit=0",
309 "-Wall",
310 "-Wextra",
311 "-Wpointer-arith",
312 "-Wstrict-aliasing",
313 "-Wcast-qual",
314 "-Wcast-align",
315 "-Wwrite-strings",
316 "-Wtype-limits",
317 "-Wsign-compare",
318 "-Wformat=2",
319 "-Werror",
320 "-fno-omit-frame-pointer",
321 "-pipe",
322 "-ggdb3",
323 ],
324 ),
325 ],
326 ),
327 flag_set(
328 actions = [
329 ACTION_NAMES.assemble,
330 ACTION_NAMES.preprocess_assemble,
331 ACTION_NAMES.linkstamp_compile,
332 ACTION_NAMES.c_compile,
333 ACTION_NAMES.cpp_compile,
334 ACTION_NAMES.cpp_header_parsing,
335 ACTION_NAMES.cpp_module_compile,
336 ACTION_NAMES.cpp_module_codegen,
337 ACTION_NAMES.lto_backend,
338 ACTION_NAMES.clif_match,
339 ],
340 flag_groups = [
341 flag_group(
342 flags = [
343 "-O2",
344 "-DNDEBUG",
345 "-ffunction-sections",
346 "-fdata-sections",
347 ],
348 ),
349 ],
350 with_features = [with_feature_set(features = ["opt"])],
351 ),
352 ],
353 )
354 elif (ctx.attr.cpu == "cortex-m4f-k22"):
355 default_compile_flags_feature = feature(
356 name = "default_compile_flags",
357 enabled = True,
358 flag_sets = [
359 flag_set(
360 actions = [
361 ACTION_NAMES.assemble,
362 ACTION_NAMES.preprocess_assemble,
363 ACTION_NAMES.linkstamp_compile,
364 ACTION_NAMES.c_compile,
365 ACTION_NAMES.cpp_compile,
366 ACTION_NAMES.cpp_header_parsing,
367 ACTION_NAMES.cpp_module_compile,
368 ACTION_NAMES.cpp_module_codegen,
369 ACTION_NAMES.lto_backend,
370 ACTION_NAMES.clif_match,
371 ],
372 flag_groups = [
373 flag_group(
374 flags = [
375 "-D__STDC_FORMAT_MACROS",
376 "-D__STDC_CONSTANT_MACROS",
377 "-D__STDC_LIMIT_MACROS",
378 "-D__MK22FX512__",
379 "-DF_CPU=120000000",
380 "-Wl,--gc-sections",
381 "-D__have_long32",
382 "-fstack-protector",
383 "-mcpu=cortex-m4",
384 "-mfpu=fpv4-sp-d16",
385 "-mthumb",
386 "-mfloat-abi=hard",
387 "-fno-strict-aliasing",
388 "-fmessage-length=80",
389 "-fmax-errors=20",
390 "-Wall",
391 "-Wextra",
392 "-Wpointer-arith",
393 "-Wcast-qual",
394 "-Wwrite-strings",
395 "-Wtype-limits",
396 "-Wsign-compare",
397 "-Wformat=2",
398 "-Werror",
399 "-Wstrict-aliasing=2",
400 "-Wno-misleading-indentation",
401 "-Wno-int-in-bool-context",
402 "-Wdouble-promotion",
403 "-pipe",
404 "-g",
405 "-fno-common",
406 "-ffreestanding",
407 "-fbuiltin",
408 ],
409 ),
410 ],
411 ),
412 flag_set(
413 actions = [
414 ACTION_NAMES.assemble,
415 ACTION_NAMES.preprocess_assemble,
416 ACTION_NAMES.linkstamp_compile,
417 ACTION_NAMES.c_compile,
418 ACTION_NAMES.cpp_compile,
419 ACTION_NAMES.cpp_header_parsing,
420 ACTION_NAMES.cpp_module_compile,
421 ACTION_NAMES.cpp_module_codegen,
422 ACTION_NAMES.lto_backend,
423 ACTION_NAMES.clif_match,
424 ],
425 flag_groups = [
426 flag_group(
427 flags = [
428 "-O2",
429 "-finline-functions",
430 "-ffast-math",
431 "-funroll-loops",
432 "-DNDEBUG",
433 "-ffunction-sections",
434 ],
435 ),
436 ],
437 with_features = [with_feature_set(features = ["opt"])],
438 ),
439 ],
440 )
441 elif (ctx.attr.cpu == "cortex-m4f"):
442 default_compile_flags_feature = feature(
443 name = "default_compile_flags",
444 enabled = True,
445 flag_sets = [
446 flag_set(
447 actions = [
448 ACTION_NAMES.assemble,
449 ACTION_NAMES.preprocess_assemble,
450 ACTION_NAMES.linkstamp_compile,
451 ACTION_NAMES.c_compile,
452 ACTION_NAMES.cpp_compile,
453 ACTION_NAMES.cpp_header_parsing,
454 ACTION_NAMES.cpp_module_compile,
455 ACTION_NAMES.cpp_module_codegen,
456 ACTION_NAMES.lto_backend,
457 ACTION_NAMES.clif_match,
458 ],
459 flag_groups = [
460 flag_group(
461 flags = [
462 "-D__STDC_FORMAT_MACROS",
463 "-D__STDC_CONSTANT_MACROS",
464 "-D__STDC_LIMIT_MACROS",
465 "-D__MK64FX512__",
466 "-DF_CPU=120000000",
467 "-Wl,--gc-sections",
468 "-D__have_long32",
469 "-fstack-protector",
470 "-mcpu=cortex-m4",
471 "-mfpu=fpv4-sp-d16",
472 "-mthumb",
473 "-mfloat-abi=hard",
474 "-fno-strict-aliasing",
475 "-fmessage-length=80",
476 "-fmax-errors=20",
477 "-Wall",
478 "-Wextra",
479 "-Wpointer-arith",
480 "-Wcast-qual",
481 "-Wwrite-strings",
482 "-Wtype-limits",
483 "-Wsign-compare",
484 "-Wformat=2",
485 "-Werror",
486 "-Wstrict-aliasing=2",
487 "-Wno-misleading-indentation",
488 "-Wno-int-in-bool-context",
489 "-Wdouble-promotion",
490 "-pipe",
491 "-g",
492 "-fno-common",
493 "-ffreestanding",
494 "-fbuiltin",
495 ],
496 ),
497 ],
498 ),
499 flag_set(
500 actions = [
501 ACTION_NAMES.assemble,
502 ACTION_NAMES.preprocess_assemble,
503 ACTION_NAMES.linkstamp_compile,
504 ACTION_NAMES.c_compile,
505 ACTION_NAMES.cpp_compile,
506 ACTION_NAMES.cpp_header_parsing,
507 ACTION_NAMES.cpp_module_compile,
508 ACTION_NAMES.cpp_module_codegen,
509 ACTION_NAMES.lto_backend,
510 ACTION_NAMES.clif_match,
511 ],
512 flag_groups = [
513 flag_group(
514 flags = [
515 "-O2",
516 "-finline-functions",
517 "-ffast-math",
518 "-funroll-loops",
519 "-DNDEBUG",
520 "-ffunction-sections",
521 ],
522 ),
523 ],
524 with_features = [with_feature_set(features = ["opt"])],
525 ),
526 ],
527 )
Austin Schuh0a96ea32022-01-01 22:29:30 -0800528 elif (ctx.attr.cpu == "rp2040"):
529 default_compile_flags_feature = feature(
530 name = "default_compile_flags",
531 enabled = True,
532 flag_sets = [
533 flag_set(
534 actions = [
535 ACTION_NAMES.assemble,
536 ACTION_NAMES.preprocess_assemble,
537 ACTION_NAMES.linkstamp_compile,
538 ACTION_NAMES.c_compile,
539 ACTION_NAMES.cpp_compile,
540 ACTION_NAMES.cpp_header_parsing,
541 ACTION_NAMES.cpp_module_compile,
542 ACTION_NAMES.cpp_module_codegen,
543 ACTION_NAMES.lto_backend,
544 ACTION_NAMES.clif_match,
545 ],
546 flag_groups = [
547 flag_group(
548 flags = [
549 "-DPICO_BOARD=\"pico\"",
550 "-DPICO_BUILD=1",
551 "-DPICO_NO_HARDWARE=0",
552 "-DPICO_ON_DEVICE=1",
553 "-D__STDC_FORMAT_MACROS",
554 "-D__STDC_CONSTANT_MACROS",
555 "-D__STDC_LIMIT_MACROS",
556 "-Wl,--gc-sections",
557 "-fstack-protector",
558 "-mcpu=cortex-m0plus",
559 "-mthumb",
560 "-fno-strict-aliasing",
561 "-fmessage-length=80",
562 "-fmax-errors=20",
563 "-Wall",
564 "-Wextra",
565 "-Wpointer-arith",
566 "-Wcast-qual",
567 "-Wwrite-strings",
568 "-Wtype-limits",
569 "-Wsign-compare",
570 "-Wformat=2",
571 "-Werror",
572 "-Wstrict-aliasing=2",
573 "-Wno-misleading-indentation",
574 "-Wno-int-in-bool-context",
575 "-Wdouble-promotion",
576 "-pipe",
577 "-g",
578 ],
579 ),
580 ],
581 ),
582 flag_set(
583 actions = [
584 ACTION_NAMES.assemble,
585 ACTION_NAMES.preprocess_assemble,
586 ACTION_NAMES.linkstamp_compile,
587 ACTION_NAMES.c_compile,
588 ACTION_NAMES.cpp_compile,
589 ACTION_NAMES.cpp_header_parsing,
590 ACTION_NAMES.cpp_module_compile,
591 ACTION_NAMES.cpp_module_codegen,
592 ACTION_NAMES.lto_backend,
593 ACTION_NAMES.clif_match,
594 ],
595 flag_groups = [
596 flag_group(
597 flags = [
598 "-O3",
599 "-finline-functions",
600 "-funroll-loops",
601 "-DNDEBUG",
602 "-ffunction-sections",
603 ],
604 ),
605 ],
606 with_features = [with_feature_set(features = ["opt"])],
607 ),
608 ],
609 )
Austin Schuhda9d0602019-09-15 17:29:38 -0700610 elif (ctx.attr.cpu == "armhf-debian"):
611 default_compile_flags_feature = feature(
612 name = "default_compile_flags",
613 enabled = True,
614 flag_sets = [
615 flag_set(
616 actions = [
617 ACTION_NAMES.assemble,
618 ACTION_NAMES.preprocess_assemble,
619 ACTION_NAMES.linkstamp_compile,
620 ACTION_NAMES.c_compile,
621 ACTION_NAMES.cpp_compile,
622 ACTION_NAMES.cpp_header_parsing,
623 ACTION_NAMES.cpp_module_compile,
624 ACTION_NAMES.cpp_module_codegen,
625 ACTION_NAMES.lto_backend,
626 ACTION_NAMES.clif_match,
627 ],
628 flag_groups = [
629 flag_group(
630 flags = [
631 "-target",
632 "armv7a-arm-linux-gnueabif",
633 "--sysroot=external/armhf_debian_rootfs",
634 "-mfloat-abi=hard",
635 "-mfpu=vfpv3-d16",
636 "-nostdinc",
637 "-isystem",
638 "external/linaro_linux_gcc_repo/lib/gcc/arm-linux-gnueabihf/7.4.1/include",
639 "-isystem",
640 "external/linaro_linux_gcc_repo/lib/gcc/arm-linux-gnueabihf/7.4.1/include-fixed",
641 "-isystem",
642 "external/linaro_linux_gcc_repo/arm-linux-gnueabihf/include/c++/7.4.1/arm-linux-gnueabihf",
643 "-isystem",
644 "external/linaro_linux_gcc_repo/arm-linux-gnueabihf/include/c++/7.4.1",
645 "-isystem",
646 "external/linaro_linux_gcc_repo/include/c++/7.4.1/arm-linux-gnueabihf",
647 "-isystem",
648 "external/linaro_linux_gcc_repo/include/c++/7.4.1",
649 "-isystem",
650 "external/armhf_debian_rootfs/usr/include",
651 "-isystem",
652 "external/armhf_debian_rootfs/usr/include/arm-linux-gnueabihf",
653 "-isystem",
654 "external/org_frc971/third_party",
655 "-D__STDC_FORMAT_MACROS",
656 "-D__STDC_CONSTANT_MACROS",
657 "-D__STDC_LIMIT_MACROS",
658 "-D_FILE_OFFSET_BITS=64",
659 "-DAOS_ARCHITECTURE_armhf",
660 "-U_FORTIFY_SOURCE",
661 "-fstack-protector",
662 "-fPIE",
663 "-fdiagnostics-color=always",
664 "-Wall",
665 "-Wextra",
666 "-Wpointer-arith",
667 "-Wstrict-aliasing",
668 "-Wcast-qual",
669 "-Wcast-align",
670 "-Wwrite-strings",
671 "-Wtype-limits",
672 "-Wsign-compare",
673 "-Wformat=2",
674 "-Werror",
675 "-Wunused-local-typedefs",
676 "-fno-omit-frame-pointer",
677 "-pipe",
678 "-ggdb3",
679 ],
680 ),
681 ],
682 ),
683 flag_set(
684 actions = [
685 ACTION_NAMES.assemble,
686 ACTION_NAMES.preprocess_assemble,
687 ACTION_NAMES.linkstamp_compile,
688 ACTION_NAMES.c_compile,
689 ACTION_NAMES.cpp_compile,
690 ACTION_NAMES.cpp_header_parsing,
691 ACTION_NAMES.cpp_module_compile,
692 ACTION_NAMES.cpp_module_codegen,
693 ACTION_NAMES.lto_backend,
694 ACTION_NAMES.clif_match,
695 ],
696 flag_groups = [
697 flag_group(
698 flags = [
699 "-O2",
700 "-DNDEBUG",
701 "-D_FORTIFY_SOURCE=1",
702 "-ffunction-sections",
703 "-fdata-sections",
704 ],
705 ),
706 ],
707 with_features = [with_feature_set(features = ["opt"])],
708 ),
709 ],
710 )
711 else:
712 default_compile_flags_feature = None
713
Austin Schuha2503a72020-12-15 20:57:57 -0800714 if (ctx.attr.cpu == "armhf-debian" or
715 ctx.attr.cpu == "k8"):
Austin Schuhda9d0602019-09-15 17:29:38 -0700716 dbg_feature = feature(
717 name = "dbg",
718 flag_sets = [
719 flag_set(
720 actions = [
721 ACTION_NAMES.preprocess_assemble,
722 ACTION_NAMES.c_compile,
723 ACTION_NAMES.cpp_compile,
724 ACTION_NAMES.cpp_header_parsing,
725 "c++-header-preprocessing",
726 ACTION_NAMES.cpp_module_compile,
727 ],
728 flag_groups = [
729 flag_group(flags = ["-DAOS_DEBUG=1"]),
730 flag_group(flags = ["-fno-omit-frame-pointer"]),
731 ],
732 ),
733 ],
734 implies = ["all_modes"],
735 )
736 elif (ctx.attr.cpu == "roborio"):
737 dbg_feature = feature(
738 name = "dbg",
739 flag_sets = [
740 flag_set(
741 actions = [
742 ACTION_NAMES.preprocess_assemble,
743 ACTION_NAMES.c_compile,
744 ACTION_NAMES.cpp_compile,
745 ACTION_NAMES.cpp_header_parsing,
746 "c++-header-preprocessing",
747 ACTION_NAMES.cpp_module_compile,
748 ],
749 flag_groups = [
750 flag_group(flags = ["-DAOS_DEBUG=1"]),
751 flag_group(flags = ["-fno-omit-frame-pointer"]),
752 ],
753 ),
754 ],
755 )
Austin Schuh0a96ea32022-01-01 22:29:30 -0800756 elif (ctx.attr.cpu == "rp2040" or
757 ctx.attr.cpu == "cortex-m4f" or
Austin Schuha2503a72020-12-15 20:57:57 -0800758 ctx.attr.cpu == "cortex-m4f-k22"):
Austin Schuhda9d0602019-09-15 17:29:38 -0700759 dbg_feature = feature(
760 name = "dbg",
761 flag_sets = [
762 flag_set(
763 actions = [
764 ACTION_NAMES.preprocess_assemble,
765 ACTION_NAMES.c_compile,
766 ACTION_NAMES.cpp_compile,
767 ACTION_NAMES.cpp_header_parsing,
768 "c++-header-preprocessing",
769 ACTION_NAMES.cpp_module_compile,
770 ],
771 flag_groups = [flag_group(flags = ["-fno-omit-frame-pointer"])],
772 ),
773 ],
774 implies = ["all_modes"],
775 )
776 else:
777 dbg_feature = None
778
Austin Schuha2503a72020-12-15 20:57:57 -0800779 if (ctx.attr.cpu == "armhf-debian" or
780 ctx.attr.cpu == "k8"):
Austin Schuhda9d0602019-09-15 17:29:38 -0700781 fastbuild_feature = feature(
782 name = "fastbuild",
783 flag_sets = [
784 flag_set(
785 actions = [
786 ACTION_NAMES.preprocess_assemble,
787 ACTION_NAMES.c_compile,
788 ACTION_NAMES.cpp_compile,
789 ACTION_NAMES.cpp_header_parsing,
790 "c++-header-preprocessing",
791 ACTION_NAMES.cpp_module_compile,
792 ],
793 flag_groups = [flag_group(flags = ["-DAOS_DEBUG=0"])],
794 ),
795 ],
796 implies = ["all_modes"],
797 )
798 elif (ctx.attr.cpu == "roborio"):
799 fastbuild_feature = feature(
800 name = "fastbuild",
801 flag_sets = [
802 flag_set(
803 actions = [
804 ACTION_NAMES.preprocess_assemble,
805 ACTION_NAMES.c_compile,
806 ACTION_NAMES.cpp_compile,
807 ACTION_NAMES.cpp_header_parsing,
808 "c++-header-preprocessing",
809 ACTION_NAMES.cpp_module_compile,
810 ],
811 flag_groups = [flag_group(flags = ["-DAOS_DEBUG=0"])],
812 ),
813 ],
814 )
Austin Schuh0a96ea32022-01-01 22:29:30 -0800815 elif (ctx.attr.cpu == "rp2040" or
816 ctx.attr.cpu == "cortex-m4f" or
Austin Schuha2503a72020-12-15 20:57:57 -0800817 ctx.attr.cpu == "cortex-m4f-k22"):
Austin Schuhda9d0602019-09-15 17:29:38 -0700818 fastbuild_feature = feature(name = "fastbuild", implies = ["all_modes"])
819 else:
820 fastbuild_feature = None
821
822 pie_for_linking_feature = feature(
823 name = "pie_for_linking",
824 enabled = True,
825 flag_sets = [
826 flag_set(
827 actions = [ACTION_NAMES.cpp_link_executable],
828 flag_groups = [flag_group(flags = ["-pie"])],
829 ),
830 ],
831 )
832
833 if (ctx.attr.cpu == "roborio"):
834 opt_feature = feature(
835 name = "opt",
836 flag_sets = [
837 flag_set(
838 actions = [
839 ACTION_NAMES.assemble,
840 ACTION_NAMES.preprocess_assemble,
841 ACTION_NAMES.c_compile,
842 ACTION_NAMES.cpp_compile,
843 ACTION_NAMES.cpp_module_compile,
844 ACTION_NAMES.objc_compile,
845 ACTION_NAMES.objcpp_compile,
846 ACTION_NAMES.cpp_header_parsing,
847 ACTION_NAMES.linkstamp_compile,
848 ],
849 flag_groups = [
850 flag_group(
851 flags = [
852 "-O2",
853 "-DNDEBUG",
854 "-D_FORTIFY_SOURCE=1",
855 "-ffunction-sections",
856 "-fdata-sections",
857 ],
858 ),
859 ],
860 ),
861 flag_set(
862 actions = [
863 ACTION_NAMES.cpp_link_executable,
864 ACTION_NAMES.cpp_link_nodeps_dynamic_library,
865 ACTION_NAMES.cpp_link_dynamic_library,
866 ],
867 flag_groups = [flag_group(flags = ["-Wl,--gc-sections"])],
868 ),
869 ],
870 implies = ["opt_post"],
871 )
Austin Schuha2503a72020-12-15 20:57:57 -0800872 elif (ctx.attr.cpu == "armhf-debian" or
873 ctx.attr.cpu == "k8"):
Austin Schuhda9d0602019-09-15 17:29:38 -0700874 opt_feature = feature(
875 name = "opt",
876 flag_sets = [
877 flag_set(
878 actions = [
879 ACTION_NAMES.preprocess_assemble,
880 ACTION_NAMES.c_compile,
881 ACTION_NAMES.cpp_compile,
882 ACTION_NAMES.cpp_header_parsing,
883 "c++-header-preprocessing",
884 ACTION_NAMES.cpp_module_compile,
885 ],
886 flag_groups = [flag_group(flags = ["-DAOS_DEBUG=0"])],
887 ),
888 ],
889 implies = ["all_modes"],
890 )
Austin Schuh0a96ea32022-01-01 22:29:30 -0800891 elif (ctx.attr.cpu == "rp2040" or
892 ctx.attr.cpu == "cortex-m4f" or
Austin Schuha2503a72020-12-15 20:57:57 -0800893 ctx.attr.cpu == "cortex-m4f-k22"):
Austin Schuhda9d0602019-09-15 17:29:38 -0700894 opt_feature = feature(name = "opt", implies = ["all_modes"])
895 else:
896 opt_feature = None
897
898 pic_feature = feature(
899 name = "pic",
900 enabled = True,
901 flag_sets = [
902 flag_set(
903 actions = [
904 ACTION_NAMES.assemble,
905 ACTION_NAMES.preprocess_assemble,
906 ACTION_NAMES.linkstamp_compile,
907 ACTION_NAMES.c_compile,
908 ACTION_NAMES.cpp_compile,
909 ACTION_NAMES.cpp_module_codegen,
910 ACTION_NAMES.cpp_module_compile,
911 ],
912 flag_groups = [
913 flag_group(flags = ["-fPIC"], expand_if_available = "pic"),
914 ],
915 ),
916 ],
917 )
918
Austin Schuh0a96ea32022-01-01 22:29:30 -0800919 if (ctx.attr.cpu == "rp2040" or
920 ctx.attr.cpu == "cortex-m4f" or
Austin Schuha2503a72020-12-15 20:57:57 -0800921 ctx.attr.cpu == "cortex-m4f-k22"):
Austin Schuhda9d0602019-09-15 17:29:38 -0700922 include_paths_feature = feature(
923 name = "include_paths",
924 enabled = True,
925 flag_sets = [
926 flag_set(
927 actions = [
928 ACTION_NAMES.preprocess_assemble,
929 ACTION_NAMES.c_compile,
930 ACTION_NAMES.cpp_compile,
931 ACTION_NAMES.cpp_header_parsing,
932 "c++-header-preprocessing",
933 ACTION_NAMES.cpp_module_compile,
934 ],
935 flag_groups = [
936 flag_group(
937 flags = ["-iquote", "%{quote_include_paths}"],
938 iterate_over = "quote_include_paths",
939 ),
940 flag_group(
941 flags = ["-I%{include_paths}"],
942 iterate_over = "include_paths",
943 ),
944 flag_group(
945 flags = ["-I", "%{system_include_paths}"],
946 iterate_over = "system_include_paths",
947 ),
948 ],
949 ),
950 ],
951 )
952 elif (ctx.attr.cpu == "roborio"):
953 include_paths_feature = feature(
954 name = "include_paths",
955 enabled = True,
956 flag_sets = [
957 flag_set(
958 actions = [
959 ACTION_NAMES.preprocess_assemble,
960 ACTION_NAMES.c_compile,
961 ACTION_NAMES.cpp_compile,
962 ACTION_NAMES.cpp_header_parsing,
963 "c++-header-preprocessing",
964 ACTION_NAMES.cpp_module_compile,
965 ],
966 flag_groups = [
967 flag_group(
968 flags = ["-iquote", "%{quote_include_paths}"],
969 iterate_over = "quote_include_paths",
970 ),
971 flag_group(
972 flags = ["-I%{include_paths}"],
973 iterate_over = "include_paths",
974 ),
975 flag_group(
976 flags = ["-isystem", "%{system_include_paths}"],
977 iterate_over = "system_include_paths",
978 ),
979 ],
980 ),
981 ],
982 )
983 else:
984 include_paths_feature = None
985
986 random_seed_feature = feature(
987 name = "random_seed",
988 enabled = True,
989 flag_sets = [
990 flag_set(
991 actions = [
992 ACTION_NAMES.cpp_compile,
993 ACTION_NAMES.cpp_module_codegen,
994 ACTION_NAMES.cpp_module_compile,
995 ],
996 flag_groups = [
997 flag_group(
998 flags = ["-frandom-seed=%{output_file}"],
999 expand_if_available = "output_file",
1000 ),
1001 ],
1002 ),
1003 ],
1004 )
1005
1006 if (ctx.attr.cpu == "roborio"):
1007 default_link_flags_feature = feature(
1008 name = "default_link_flags",
1009 enabled = True,
1010 flag_sets = [
1011 flag_set(
1012 actions = all_link_actions,
1013 flag_groups = [
1014 flag_group(
1015 flags = [
1016 "-lstdc++",
1017 "-Ltools/cpp/arm-frc-linux-gnueabi/libs",
1018 "-no-canonical-prefixes",
1019 "-Wl,-z,relro,-z,now",
1020 "-lm",
1021 "-pass-exit-codes",
1022 "-Wl,--build-id=md5",
1023 "-Wl,--hash-style=gnu",
1024 ],
1025 ),
1026 ],
1027 ),
1028 ],
1029 )
1030 elif (ctx.attr.cpu == "cortex-m4f-k22"):
1031 default_link_flags_feature = feature(
1032 name = "default_link_flags",
1033 enabled = True,
1034 flag_sets = [
1035 flag_set(
1036 actions = all_link_actions,
1037 flag_groups = [
1038 flag_group(
1039 flags = [
1040 "-no-canonical-prefixes",
1041 "-mcpu=cortex-m4",
1042 "-mfpu=fpv4-sp-d16",
1043 "-mthumb",
1044 "-mfloat-abi=hard",
1045 "-fno-strict-aliasing",
1046 "--specs=nano.specs",
1047 "-lgcc",
1048 "-lstdc++_nano",
1049 "-lm",
1050 "-lc_nano",
1051 "-Tmotors/core/kinetis_512_128.ld",
1052 "-Tmotors/core/kinetis_sections.ld",
1053 ],
1054 ),
1055 ],
1056 ),
1057 flag_set(
1058 actions = all_link_actions,
1059 flag_groups = [flag_group(flags = ["-Wl,--gc-sections"])],
1060 with_features = [with_feature_set(features = ["opt"])],
1061 ),
1062 ],
1063 )
1064 elif (ctx.attr.cpu == "cortex-m4f"):
1065 default_link_flags_feature = feature(
1066 name = "default_link_flags",
1067 enabled = True,
1068 flag_sets = [
1069 flag_set(
1070 actions = all_link_actions,
1071 flag_groups = [
1072 flag_group(
1073 flags = [
1074 "-no-canonical-prefixes",
1075 "-mcpu=cortex-m4",
1076 "-mfpu=fpv4-sp-d16",
1077 "-mthumb",
1078 "-mfloat-abi=hard",
1079 "-fno-strict-aliasing",
1080 "--specs=nano.specs",
1081 "-lgcc",
1082 "-lstdc++_nano",
1083 "-lm",
1084 "-lc_nano",
1085 "-Tmotors/core/kinetis_512_256.ld",
1086 "-Tmotors/core/kinetis_sections.ld",
1087 ],
1088 ),
1089 ],
1090 ),
1091 flag_set(
1092 actions = all_link_actions,
1093 flag_groups = [flag_group(flags = ["-Wl,--gc-sections"])],
1094 with_features = [with_feature_set(features = ["opt"])],
1095 ),
1096 ],
1097 )
Austin Schuh0a96ea32022-01-01 22:29:30 -08001098 elif (ctx.attr.cpu == "rp2040"):
1099 default_link_flags_feature = feature(
1100 name = "default_link_flags",
1101 enabled = True,
1102 flag_sets = [
1103 flag_set(
1104 actions = all_link_actions,
1105 flag_groups = [
1106 flag_group(
1107 flags = [
1108 "-no-canonical-prefixes",
1109 "-mcpu=cortex-m0plus",
1110 "-mthumb",
1111 "-fno-strict-aliasing",
1112 "-Wl,--build-id=none",
1113 "--specs=nosys.specs",
1114 "-nostartfiles",
1115 ],
1116 ),
1117 ],
1118 ),
1119 # TODO(austin): I'd love to turn --gc-sections on, but that breaks things.
1120 ],
1121 )
Austin Schuhda9d0602019-09-15 17:29:38 -07001122 elif (ctx.attr.cpu == "k8"):
1123 default_link_flags_feature = feature(
1124 name = "default_link_flags",
1125 enabled = True,
1126 flag_sets = [
1127 flag_set(
1128 actions = all_link_actions,
1129 flag_groups = [
1130 flag_group(
1131 flags = [
1132 "-nodefaultlibs",
1133 "--sysroot=external/amd64_debian_sysroot",
1134 "-lstdc++",
1135 "-lc",
1136 "-lgcc",
1137 "-lgcc_s",
1138 "-Bexternal/clang_6p0_repo/usr/bin/",
1139 "-Ltools/cpp/clang_6p0/clang_more_libs",
1140 "-Lexternal/amd64_debian_sysroot/usr/lib/gcc/x86_64-linux-gnu/7/",
1141 "-Lexternal/amd64_debian_sysroot/usr/lib/x86_64-linux-gnu/",
1142 "-Lexternal/amd64_debian_sysroot/usr/lib/",
1143 "-Lexternal/amd64_debian_sysroot/lib/x86_64-linux-gnu/",
1144 "-Lexternal/amd64_debian_sysroot/lib/",
1145 "-no-canonical-prefixes",
1146 "-fuse-ld=gold",
1147 "-Wl,-z,relro,-z,now",
1148 "-lm",
1149 "-Wl,--build-id=md5",
1150 "-Wl,--hash-style=gnu",
1151 "-Wl,--warn-execstack",
1152 "-Wl,--detect-odr-violations",
1153 ],
1154 ),
1155 ],
1156 ),
1157 flag_set(
1158 actions = all_link_actions,
1159 flag_groups = [flag_group(flags = ["-Wl,--gc-sections"])],
1160 with_features = [with_feature_set(features = ["opt"])],
1161 ),
1162 ],
1163 )
1164 elif (ctx.attr.cpu == "armhf-debian"):
1165 default_link_flags_feature = feature(
1166 name = "default_link_flags",
1167 enabled = True,
1168 flag_sets = [
1169 flag_set(
1170 actions = all_link_actions,
1171 flag_groups = [
1172 flag_group(
1173 flags = [
1174 "-target",
1175 "armv7a-arm-linux-gnueabif",
1176 "--sysroot=external/armhf_debian_rootfs",
1177 "-lstdc++",
1178 "-Ltools/cpp/linaro_linux_gcc/clang_more_libs",
1179 "-Lexternal/armhf_debian_rootfs/usr/lib/gcc/arm-linux-gnueabihf/8",
1180 "-Lexternal/armhf_debian_rootfs/lib/arm-linux-gnueabihf",
1181 "-Lexternal/armhf_debian_rootfs/usr/lib/arm-linux-gnueabihf",
1182 "-Lexternal/armhf_debian_rootfs/lib",
1183 "-Lexternal/armhf_debian_rootfs/usr/lib",
1184 "-Lexternal/linaro_linux_gcc_repo/lib/gcc/arm-linux-gnueabihf/7.4.1",
1185 "-Bexternal/linaro_linux_gcc_repo/lib/gcc/arm-linux-gnueabihf/7.4.1",
1186 "-Bexternal/linaro_linux_gcc_repo/arm-linux-gnueabihf/bin",
1187 "-Wl,--dynamic-linker=/lib/ld-linux-armhf.so.3",
1188 "-no-canonical-prefixes",
1189 "-Wl,-z,relro,-z,now",
1190 "-lm",
1191 "-Wl,--build-id=md5",
1192 "-Wl,--hash-style=gnu",
1193 ],
1194 ),
1195 ],
1196 ),
1197 flag_set(
1198 actions = all_link_actions,
1199 flag_groups = [flag_group(flags = ["-Wl,--gc-sections"])],
1200 with_features = [with_feature_set(features = ["opt"])],
1201 ),
1202 ],
1203 )
1204 else:
1205 default_link_flags_feature = None
1206
1207 if (ctx.attr.cpu == "roborio"):
1208 all_modes_feature = feature(
1209 name = "all_modes",
1210 enabled = True,
1211 flag_sets = [
1212 flag_set(
1213 actions = [
1214 ACTION_NAMES.preprocess_assemble,
1215 ACTION_NAMES.assemble,
1216 ACTION_NAMES.c_compile,
1217 ],
1218 flag_groups = [flag_group(flags = ["-std=gnu99"])],
1219 ),
1220 flag_set(
1221 actions = [
1222 ACTION_NAMES.cpp_compile,
1223 ACTION_NAMES.cpp_header_parsing,
1224 "c++-header-preprocessing",
1225 ACTION_NAMES.cpp_module_compile,
1226 ],
1227 flag_groups = [
1228 flag_group(
1229 flags = ["-std=gnu++1z", "-fno-sized-deallocation"],
1230 ),
1231 ],
1232 ),
1233 flag_set(
1234 actions = [
1235 ACTION_NAMES.preprocess_assemble,
1236 ACTION_NAMES.assemble,
1237 "c++-link",
1238 ACTION_NAMES.cpp_compile,
1239 ACTION_NAMES.cpp_header_parsing,
1240 "c++-header-preprocessing",
1241 ACTION_NAMES.cpp_module_compile,
1242 ACTION_NAMES.c_compile,
1243 ],
1244 flag_groups = [flag_group(flags = ["-pthread"])],
1245 ),
1246 ],
1247 )
Austin Schuh0a96ea32022-01-01 22:29:30 -08001248 elif (ctx.attr.cpu == "rp2040" or
1249 ctx.attr.cpu == "cortex-m4f" or
Austin Schuha2503a72020-12-15 20:57:57 -08001250 ctx.attr.cpu == "cortex-m4f-k22"):
Austin Schuhda9d0602019-09-15 17:29:38 -07001251 all_modes_feature = feature(
1252 name = "all_modes",
1253 flag_sets = [
1254 flag_set(
1255 actions = [
1256 ACTION_NAMES.preprocess_assemble,
1257 ACTION_NAMES.assemble,
1258 ACTION_NAMES.c_compile,
1259 ],
Austin Schuh0a96ea32022-01-01 22:29:30 -08001260 flag_groups = [flag_group(flags = ["--std=gnu11"])],
Austin Schuhda9d0602019-09-15 17:29:38 -07001261 ),
1262 flag_set(
1263 actions = [
1264 ACTION_NAMES.cpp_compile,
1265 ACTION_NAMES.cpp_header_parsing,
1266 "c++-header-preprocessing",
1267 ACTION_NAMES.cpp_module_compile,
1268 ],
1269 flag_groups = [
1270 flag_group(
1271 flags = ["--std=gnu++1z", "-fno-exceptions", "-fno-rtti"],
1272 ),
1273 ],
1274 ),
1275 ],
1276 )
1277 elif (ctx.attr.cpu == "armhf-debian"):
1278 all_modes_feature = feature(
1279 name = "all_modes",
1280 flag_sets = [
1281 flag_set(
1282 actions = [
1283 ACTION_NAMES.preprocess_assemble,
1284 ACTION_NAMES.assemble,
1285 ACTION_NAMES.c_compile,
1286 ],
1287 flag_groups = [flag_group(flags = ["-std=gnu99"])],
1288 ),
1289 flag_set(
1290 actions = [
1291 ACTION_NAMES.cpp_compile,
1292 ACTION_NAMES.cpp_header_parsing,
1293 "c++-header-preprocessing",
1294 ACTION_NAMES.cpp_module_compile,
1295 ],
1296 flag_groups = [flag_group(flags = ["-std=gnu++1z"])],
1297 ),
1298 flag_set(
1299 actions = [
1300 ACTION_NAMES.preprocess_assemble,
1301 ACTION_NAMES.assemble,
1302 "c++-link",
1303 ACTION_NAMES.cpp_compile,
1304 ACTION_NAMES.cpp_header_parsing,
1305 "c++-header-preprocessing",
1306 ACTION_NAMES.cpp_module_compile,
1307 ACTION_NAMES.c_compile,
1308 ],
1309 flag_groups = [flag_group(flags = ["-pthread"])],
1310 ),
1311 ],
1312 )
1313 elif (ctx.attr.cpu == "k8"):
1314 all_modes_feature = feature(
1315 name = "all_modes",
1316 flag_sets = [
1317 flag_set(
1318 actions = [
1319 ACTION_NAMES.preprocess_assemble,
1320 ACTION_NAMES.assemble,
1321 ACTION_NAMES.c_compile,
1322 ],
1323 flag_groups = [flag_group(flags = ["-std=gnu99"])],
1324 ),
1325 flag_set(
1326 actions = [
1327 ACTION_NAMES.cpp_compile,
1328 ACTION_NAMES.cpp_header_parsing,
1329 "c++-header-preprocessing",
1330 ACTION_NAMES.cpp_module_compile,
1331 ],
1332 flag_groups = [flag_group(flags = ["-std=gnu++1z"])],
1333 ),
1334 ],
1335 )
1336 else:
1337 all_modes_feature = None
1338
1339 supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True)
1340
1341 if (ctx.attr.cpu == "k8"):
1342 unfiltered_compile_flags_feature = feature(
1343 name = "unfiltered_compile_flags",
1344 enabled = True,
1345 flag_sets = [
1346 flag_set(
1347 actions = [
1348 ACTION_NAMES.assemble,
1349 ACTION_NAMES.preprocess_assemble,
1350 ACTION_NAMES.linkstamp_compile,
1351 ACTION_NAMES.c_compile,
1352 ACTION_NAMES.cpp_compile,
1353 ACTION_NAMES.cpp_header_parsing,
1354 ACTION_NAMES.cpp_module_compile,
1355 ACTION_NAMES.cpp_module_codegen,
1356 ACTION_NAMES.lto_backend,
1357 ACTION_NAMES.clif_match,
1358 ],
1359 flag_groups = [
1360 flag_group(
1361 flags = [
1362 "-no-canonical-prefixes",
1363 "-Wno-builtin-macro-redefined",
1364 "-D__DATE__=\"redacted\"",
1365 "-D__TIMESTAMP__=\"redacted\"",
1366 "-D__TIME__=\"redacted\"",
1367 "-Wno-varargs",
1368 "-Wno-null-pointer-arithmetic",
1369 "-Wno-mismatched-new-delete",
1370 ],
1371 ),
1372 ],
1373 ),
1374 ],
1375 )
Austin Schuh0a96ea32022-01-01 22:29:30 -08001376 elif (ctx.attr.cpu == "rp2040" or
1377 ctx.attr.cpu == "cortex-m4f" or
Austin Schuha2503a72020-12-15 20:57:57 -08001378 ctx.attr.cpu == "cortex-m4f-k22" or
1379 ctx.attr.cpu == "roborio"):
Austin Schuhda9d0602019-09-15 17:29:38 -07001380 unfiltered_compile_flags_feature = feature(
1381 name = "unfiltered_compile_flags",
1382 enabled = True,
1383 flag_sets = [
1384 flag_set(
1385 actions = [
1386 ACTION_NAMES.assemble,
1387 ACTION_NAMES.preprocess_assemble,
1388 ACTION_NAMES.linkstamp_compile,
1389 ACTION_NAMES.c_compile,
1390 ACTION_NAMES.cpp_compile,
1391 ACTION_NAMES.cpp_header_parsing,
1392 ACTION_NAMES.cpp_module_compile,
1393 ACTION_NAMES.cpp_module_codegen,
1394 ACTION_NAMES.lto_backend,
1395 ACTION_NAMES.clif_match,
1396 ],
1397 flag_groups = [
1398 flag_group(
1399 flags = [
1400 "-no-canonical-prefixes",
1401 "-Wno-builtin-macro-redefined",
1402 "-D__DATE__=\"redacted\"",
1403 "-D__TIMESTAMP__=\"redacted\"",
1404 "-D__TIME__=\"redacted\"",
1405 ],
1406 ),
1407 ],
1408 ),
1409 ],
1410 )
1411 elif (ctx.attr.cpu == "armhf-debian"):
1412 unfiltered_compile_flags_feature = feature(
1413 name = "unfiltered_compile_flags",
1414 enabled = True,
1415 flag_sets = [
1416 flag_set(
1417 actions = [
1418 ACTION_NAMES.assemble,
1419 ACTION_NAMES.preprocess_assemble,
1420 ACTION_NAMES.linkstamp_compile,
1421 ACTION_NAMES.c_compile,
1422 ACTION_NAMES.cpp_compile,
1423 ACTION_NAMES.cpp_header_parsing,
1424 ACTION_NAMES.cpp_module_compile,
1425 ACTION_NAMES.cpp_module_codegen,
1426 ACTION_NAMES.lto_backend,
1427 ACTION_NAMES.clif_match,
1428 ],
1429 flag_groups = [
1430 flag_group(
1431 flags = [
1432 "-no-canonical-prefixes",
1433 "-Wno-builtin-macro-redefined",
1434 "-Wno-mismatched-new-delete",
1435 "-Wno-null-pointer-arithmetic",
1436 "-Wno-varargs",
1437 "-D__DATE__=\"redacted\"",
1438 "-D__TIMESTAMP__=\"redacted\"",
1439 "-D__TIME__=\"redacted\"",
1440 ],
1441 ),
1442 ],
1443 ),
1444 ],
1445 )
1446 else:
1447 unfiltered_compile_flags_feature = None
1448
1449 dependency_file_feature = feature(
1450 name = "dependency_file",
1451 enabled = True,
1452 flag_sets = [
1453 flag_set(
1454 actions = [
1455 ACTION_NAMES.assemble,
1456 ACTION_NAMES.preprocess_assemble,
1457 ACTION_NAMES.c_compile,
1458 ACTION_NAMES.cpp_compile,
1459 ACTION_NAMES.cpp_module_compile,
1460 ACTION_NAMES.objc_compile,
1461 ACTION_NAMES.objcpp_compile,
1462 ACTION_NAMES.cpp_header_parsing,
1463 ACTION_NAMES.clif_match,
1464 ],
1465 flag_groups = [
1466 flag_group(
1467 flags = ["-MD", "-MF", "%{dependency_file}"],
1468 expand_if_available = "dependency_file",
1469 ),
1470 ],
1471 ),
1472 ],
1473 )
1474
1475 objcopy_embed_flags_feature = feature(
1476 name = "objcopy_embed_flags",
1477 enabled = True,
1478 flag_sets = [
1479 flag_set(
1480 actions = ["objcopy_embed_data"],
1481 flag_groups = [flag_group(flags = ["-I", "binary"])],
1482 ),
1483 ],
1484 )
1485
1486 user_compile_flags_feature = feature(
1487 name = "user_compile_flags",
1488 enabled = True,
1489 flag_sets = [
1490 flag_set(
1491 actions = [
1492 ACTION_NAMES.assemble,
1493 ACTION_NAMES.preprocess_assemble,
1494 ACTION_NAMES.linkstamp_compile,
1495 ACTION_NAMES.c_compile,
1496 ACTION_NAMES.cpp_compile,
1497 ACTION_NAMES.cpp_header_parsing,
1498 ACTION_NAMES.cpp_module_compile,
1499 ACTION_NAMES.cpp_module_codegen,
1500 ACTION_NAMES.lto_backend,
1501 ACTION_NAMES.clif_match,
1502 ],
1503 flag_groups = [
1504 flag_group(
1505 flags = ["%{user_compile_flags}"],
1506 iterate_over = "user_compile_flags",
1507 expand_if_available = "user_compile_flags",
1508 ),
1509 ],
1510 ),
1511 ],
1512 )
1513
1514 sysroot_feature = feature(
1515 name = "sysroot",
1516 enabled = True,
1517 flag_sets = [
1518 flag_set(
1519 actions = [
1520 ACTION_NAMES.preprocess_assemble,
1521 ACTION_NAMES.linkstamp_compile,
1522 ACTION_NAMES.c_compile,
1523 ACTION_NAMES.cpp_compile,
1524 ACTION_NAMES.cpp_header_parsing,
1525 ACTION_NAMES.cpp_module_compile,
1526 ACTION_NAMES.cpp_module_codegen,
1527 ACTION_NAMES.lto_backend,
1528 ACTION_NAMES.clif_match,
1529 ACTION_NAMES.cpp_link_executable,
1530 ACTION_NAMES.cpp_link_dynamic_library,
1531 ACTION_NAMES.cpp_link_nodeps_dynamic_library,
1532 ],
1533 flag_groups = [
1534 flag_group(
1535 flags = ["--sysroot=%{sysroot}"],
1536 expand_if_available = "sysroot",
1537 ),
1538 ],
1539 ),
1540 ],
1541 )
1542
1543 compile_flags1_feature = feature(
1544 name = "compile_flags1",
1545 enabled = True,
1546 flag_sets = [
1547 flag_set(
1548 actions = [
1549 ACTION_NAMES.assemble,
1550 ACTION_NAMES.preprocess_assemble,
1551 ACTION_NAMES.c_compile,
1552 ACTION_NAMES.cpp_compile,
1553 ACTION_NAMES.cpp_header_parsing,
1554 ACTION_NAMES.cpp_module_compile,
1555 ACTION_NAMES.cpp_module_codegen,
1556 ACTION_NAMES.lto_backend,
1557 ACTION_NAMES.clif_match,
1558 ],
1559 flag_groups = [
1560 flag_group(
1561 flags = [
1562 "--sysroot=external/arm_frc_linux_gnueabi_repo/arm-frc2020-linux-gnueabi",
1563 "-nostdinc",
1564 "-isystem",
1565 "external/arm_frc_linux_gnueabi_repo/arm-frc2020-linux-gnueabi/usr/lib/gcc/arm-frc2020-linux-gnueabi/7.3.0/include",
1566 "-isystem",
1567 "external/arm_frc_linux_gnueabi_repo/arm-frc2020-linux-gnueabi/usr/lib/gcc/arm-frc2020-linux-gnueabi/7.3.0/include-fixed",
1568 ],
1569 ),
1570 ],
1571 ),
1572 flag_set(
1573 actions = [
1574 ACTION_NAMES.assemble,
1575 ACTION_NAMES.preprocess_assemble,
1576 ACTION_NAMES.cpp_compile,
1577 ACTION_NAMES.cpp_header_parsing,
1578 "c++-header-preprocessing",
1579 ],
1580 flag_groups = [flag_group(flags = ["-fno-canonical-system-headers"])],
1581 ),
1582 flag_set(
1583 actions = [
1584 ACTION_NAMES.cpp_compile,
1585 ACTION_NAMES.cpp_header_parsing,
1586 ACTION_NAMES.cpp_module_compile,
1587 ACTION_NAMES.cpp_module_codegen,
1588 ],
1589 flag_groups = [
1590 flag_group(
1591 flags = [
1592 "-isystem",
1593 "external/arm_frc_linux_gnueabi_repo/arm-frc2020-linux-gnueabi/usr/include/c++/7.3.0",
1594 "-isystem",
1595 "external/arm_frc_linux_gnueabi_repo/arm-frc2020-linux-gnueabi/usr/include/c++/7.3.0/arm-frc2020-linux-gnueabi",
1596 "-isystem",
1597 "external/arm_frc_linux_gnueabi_repo/arm-frc2020-linux-gnueabi/usr/include/c++/7.3.0/backward",
1598 ],
1599 ),
1600 ],
1601 ),
1602 flag_set(
1603 actions = [
1604 ACTION_NAMES.assemble,
1605 ACTION_NAMES.preprocess_assemble,
1606 ACTION_NAMES.c_compile,
1607 ACTION_NAMES.cpp_compile,
1608 ACTION_NAMES.cpp_header_parsing,
1609 ACTION_NAMES.cpp_module_compile,
1610 ACTION_NAMES.cpp_module_codegen,
1611 ACTION_NAMES.lto_backend,
1612 ACTION_NAMES.clif_match,
1613 ],
1614 flag_groups = [
1615 flag_group(
1616 flags = [
1617 "-isystem",
1618 "external/arm_frc_linux_gnueabi_repo/arm-frc2020-linux-gnueabi/usr/include",
1619 "-mfpu=neon",
1620 "-D__STDC_FORMAT_MACROS",
1621 "-D__STDC_CONSTANT_MACROS",
1622 "-D__STDC_LIMIT_MACROS",
1623 "-D_FILE_OFFSET_BITS=64",
1624 "-DAOS_ARCHITECTURE_arm_frc",
1625 "-U_FORTIFY_SOURCE",
1626 "-fstack-protector",
1627 "-fPIE",
1628 "-fdiagnostics-color=always",
1629 "-Wall",
1630 "-Wextra",
1631 "-Wpointer-arith",
1632 "-Wstrict-aliasing",
1633 "-Wcast-qual",
1634 "-Wwrite-strings",
1635 "-Wtype-limits",
1636 "-Wsign-compare",
1637 "-Wformat=2",
1638 "-Werror",
1639 "-Wunused-local-typedefs",
1640 "-Wno-psabi",
1641 "-fno-omit-frame-pointer",
1642 "-D__has_feature(x)=0",
1643 "-pipe",
1644 "-ggdb3",
1645 ],
1646 ),
1647 ],
1648 ),
1649 ],
1650 )
1651
Austin Schuh0a96ea32022-01-01 22:29:30 -08001652 if (ctx.attr.cpu == "rp2040" or
1653 ctx.attr.cpu == "cortex-m4f" or
Austin Schuha2503a72020-12-15 20:57:57 -08001654 ctx.attr.cpu == "cortex-m4f-k22"):
Austin Schuhda9d0602019-09-15 17:29:38 -07001655 features = [
Austin Schuha2503a72020-12-15 20:57:57 -08001656 default_compile_flags_feature,
1657 default_link_flags_feature,
1658 dbg_feature,
1659 opt_feature,
1660 fastbuild_feature,
1661 all_modes_feature,
1662 include_paths_feature,
1663 objcopy_embed_flags_feature,
1664 user_compile_flags_feature,
1665 sysroot_feature,
1666 unfiltered_compile_flags_feature,
1667 ]
1668 elif (ctx.attr.cpu == "armhf-debian" or
1669 ctx.attr.cpu == "k8"):
Austin Schuhda9d0602019-09-15 17:29:38 -07001670 features = [
Austin Schuha2503a72020-12-15 20:57:57 -08001671 default_compile_flags_feature,
1672 default_link_flags_feature,
1673 opt_feature,
1674 dbg_feature,
1675 fastbuild_feature,
1676 all_modes_feature,
1677 pie_for_linking_feature,
1678 supports_dynamic_linker_feature,
1679 supports_pic_feature,
1680 objcopy_embed_flags_feature,
1681 user_compile_flags_feature,
1682 sysroot_feature,
1683 unfiltered_compile_flags_feature,
1684 ]
Austin Schuhda9d0602019-09-15 17:29:38 -07001685 elif (ctx.attr.cpu == "roborio"):
1686 features = [
Austin Schuha2503a72020-12-15 20:57:57 -08001687 default_link_flags_feature,
1688 compile_flags1_feature,
1689 opt_feature,
1690 dependency_file_feature,
1691 random_seed_feature,
1692 pic_feature,
1693 include_paths_feature,
1694 opt_post_feature,
1695 dbg_feature,
1696 fastbuild_feature,
1697 all_modes_feature,
1698 pie_for_linking_feature,
1699 supports_dynamic_linker_feature,
1700 supports_pic_feature,
1701 objcopy_embed_flags_feature,
1702 user_compile_flags_feature,
1703 sysroot_feature,
1704 unfiltered_compile_flags_feature,
1705 ]
Austin Schuhda9d0602019-09-15 17:29:38 -07001706 elif (ctx.attr.cpu == "armeabi-v7a"):
1707 features = [supports_pic_feature]
1708 else:
1709 fail("Unreachable")
1710
1711 if (ctx.attr.cpu == "armeabi-v7a"):
1712 cxx_builtin_include_directories = []
1713 elif (ctx.attr.cpu == "roborio"):
1714 cxx_builtin_include_directories = [
Austin Schuha2503a72020-12-15 20:57:57 -08001715 "%package(@arm_frc_linux_gnueabi_repo//arm-frc2020-linux-gnueabi/usr/lib/gcc/arm-frc2020-linux-gnueabi/7.3.0/include)%",
1716 "%package(@arm_frc_linux_gnueabi_repo//arm-frc2020-linux-gnueabi/usr/lib/gcc/arm-frc2020-linux-gnueabi/7.3.0/include-fixed)%",
1717 "%package(@arm_frc_linux_gnueabi_repo//arm-frc2020-linux-gnueabi/usr/include/c++/7.3.0/arm-frc2020-linux-gnueabi)%",
1718 "%package(@arm_frc_linux_gnueabi_repo//arm-frc2020-linux-gnueabi/usr/include/c++/7.3.0/backward)%",
1719 ]
Austin Schuhda9d0602019-09-15 17:29:38 -07001720 elif (ctx.attr.cpu == "k8"):
1721 cxx_builtin_include_directories = [
Austin Schuha2503a72020-12-15 20:57:57 -08001722 "%package(@clang_6p0_repo//usr)%/lib/llvm-6.0/lib/clang/6.0.0/include",
1723 "%package(@amd64_debian_sysroot//usr)%/include",
1724 "%package(@amd64_debian_sysroot//usr)%/lib/gcc/x86_64-linux-gnu/7/include",
1725 "%package(@amd64_debian_sysroot//usr)%/lib/gcc/x86_64-linux-gnu/7/include-fixed",
1726 ]
Austin Schuhda9d0602019-09-15 17:29:38 -07001727 elif (ctx.attr.cpu == "armhf-debian"):
1728 cxx_builtin_include_directories = [
Austin Schuha2503a72020-12-15 20:57:57 -08001729 "%package(@linaro_linux_gcc_repo//include)%",
1730 "%package(@armhf_debian_rootfs//usr/include)%",
1731 "%package(@linaro_linux_gcc_repo//include)%/c++/7.4.1",
1732 "%package(@linaro_linux_gcc_repo//lib/gcc/arm-linux-gnueabihf/7.4.1/include)%",
1733 "%package(@linaro_linux_gcc_repo//lib/gcc/arm-linux-gnueabihf/7.4.1/include-fixed)%",
1734 "%package(@linaro_linux_gcc_repo//arm-linux-gnueabihf/include)%/c++/7.4.1",
1735 ]
Austin Schuh0a96ea32022-01-01 22:29:30 -08001736 elif (ctx.attr.cpu == "rp2040" or
1737 ctx.attr.cpu == "cortex-m4f" or
Austin Schuha2503a72020-12-15 20:57:57 -08001738 ctx.attr.cpu == "cortex-m4f-k22"):
Austin Schuhda9d0602019-09-15 17:29:38 -07001739 cxx_builtin_include_directories = [
Austin Schuha2503a72020-12-15 20:57:57 -08001740 "/usr/lib/gcc/arm-none-eabi/4.8/include",
1741 "/usr/lib/gcc/arm-none-eabi/4.8/include-fixed",
1742 "/usr/lib/arm-none-eabi/include",
1743 "/usr/include/newlib",
1744 ]
Austin Schuhda9d0602019-09-15 17:29:38 -07001745 else:
1746 fail("Unreachable")
1747
1748 artifact_name_patterns = []
1749
1750 make_variables = []
1751
1752 if (ctx.attr.cpu == "roborio"):
1753 tool_paths = [
1754 tool_path(
1755 name = "ar",
1756 path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-ar",
1757 ),
1758 tool_path(
1759 name = "as",
1760 path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-as",
1761 ),
1762 tool_path(
1763 name = "compat-ld",
1764 path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-ld",
1765 ),
1766 tool_path(
1767 name = "cpp",
1768 path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-cpp",
1769 ),
1770 tool_path(name = "dwp", path = "/bin/false"),
1771 tool_path(
1772 name = "gcc",
1773 path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-gcc",
1774 ),
1775 tool_path(
1776 name = "gcov",
1777 path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-gcov-4.9",
1778 ),
1779 tool_path(
1780 name = "ld",
1781 path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-ld",
1782 ),
1783 tool_path(
1784 name = "nm",
1785 path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-nm",
1786 ),
1787 tool_path(
1788 name = "objcopy",
1789 path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-objcopy",
1790 ),
1791 tool_path(
1792 name = "objdump",
1793 path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-objdump",
1794 ),
1795 tool_path(
1796 name = "strip",
1797 path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-strip",
1798 ),
1799 ]
1800 elif (ctx.attr.cpu == "k8"):
1801 tool_paths = [
1802 tool_path(
1803 name = "ar",
1804 path = "clang_6p0/x86_64-linux-gnu-ar",
1805 ),
1806 tool_path(
1807 name = "compat-ld",
1808 path = "clang_6p0/x86_64-linux-gnu-ld",
1809 ),
1810 tool_path(
1811 name = "cpp",
1812 path = "clang_6p0/x86_64-linux-gnu-cpp",
1813 ),
1814 tool_path(
1815 name = "dwp",
1816 path = "clang_6p0/x86_64-linux-gnu-dwp",
1817 ),
1818 tool_path(
1819 name = "gcc",
1820 path = "clang_6p0/x86_64-linux-gnu-clang-6.0",
1821 ),
1822 tool_path(
1823 name = "gcov",
1824 path = "clang_6p0/x86_64-linux-gnu-gcov",
1825 ),
1826 tool_path(
1827 name = "ld",
1828 path = "clang_6p0/x86_64-linux-gnu-ld",
1829 ),
1830 tool_path(
1831 name = "nm",
1832 path = "clang_6p0/x86_64-linux-gnu-nm",
1833 ),
1834 tool_path(
1835 name = "objcopy",
1836 path = "clang_6p0/x86_64-linux-gnu-objcopy",
1837 ),
1838 tool_path(
1839 name = "objdump",
1840 path = "clang_6p0/x86_64-linux-gnu-objdump",
1841 ),
1842 tool_path(
1843 name = "strip",
1844 path = "clang_6p0/x86_64-linux-gnu-strip",
1845 ),
1846 ]
Austin Schuh0a96ea32022-01-01 22:29:30 -08001847 elif (ctx.attr.cpu == "rp2040" or
1848 ctx.attr.cpu == "cortex-m4f" or
Austin Schuha2503a72020-12-15 20:57:57 -08001849 ctx.attr.cpu == "cortex-m4f-k22"):
Austin Schuhda9d0602019-09-15 17:29:38 -07001850 tool_paths = [
1851 tool_path(
1852 name = "ar",
1853 path = "gcc_arm_none_eabi/arm-none-eabi-ar",
1854 ),
1855 tool_path(
1856 name = "compat-ld",
1857 path = "gcc_arm_none_eabi/arm-none-eabi-ld",
1858 ),
1859 tool_path(
1860 name = "cpp",
1861 path = "gcc_arm_none_eabi/arm-none-eabi-cpp",
1862 ),
1863 tool_path(
1864 name = "dwp",
1865 path = "gcc_arm_none_eabi/arm-none-eabi-dwp",
1866 ),
1867 tool_path(
1868 name = "gcc",
1869 path = "gcc_arm_none_eabi/arm-none-eabi-gcc",
1870 ),
1871 tool_path(
1872 name = "gcov",
1873 path = "gcc_arm_none_eabi/arm-none-eabi-gcov",
1874 ),
1875 tool_path(
1876 name = "ld",
1877 path = "gcc_arm_none_eabi/arm-none-eabi-ld",
1878 ),
1879 tool_path(
1880 name = "nm",
1881 path = "gcc_arm_none_eabi/arm-none-eabi-nm",
1882 ),
1883 tool_path(
1884 name = "objcopy",
1885 path = "gcc_arm_none_eabi/arm-none-eabi-objcopy",
1886 ),
1887 tool_path(
1888 name = "objdump",
1889 path = "gcc_arm_none_eabi/arm-none-eabi-objdump",
1890 ),
1891 tool_path(
1892 name = "strip",
1893 path = "gcc_arm_none_eabi/arm-none-eabi-strip",
1894 ),
1895 ]
1896 elif (ctx.attr.cpu == "armhf-debian"):
1897 tool_paths = [
1898 tool_path(
1899 name = "ar",
1900 path = "linaro_linux_gcc/arm-linux-gnueabihf-ar",
1901 ),
1902 tool_path(
1903 name = "compat-ld",
1904 path = "linaro_linux_gcc/arm-linux-gnueabihf-ld",
1905 ),
1906 tool_path(
1907 name = "cpp",
1908 path = "linaro_linux_gcc/clang_bin/clang",
1909 ),
1910 tool_path(
1911 name = "dwp",
1912 path = "linaro_linux_gcc/arm-linux-gnueabihf-dwp",
1913 ),
1914 tool_path(
1915 name = "gcc",
1916 path = "linaro_linux_gcc/clang_bin/clang",
1917 ),
1918 tool_path(
1919 name = "gcov",
1920 path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-gcov-4.9",
1921 ),
1922 tool_path(
1923 name = "ld",
1924 path = "linaro_linux_gcc/arm-linux-gnueabihf-ld",
1925 ),
1926 tool_path(
1927 name = "nm",
1928 path = "linaro_linux_gcc/arm-linux-gnueabihf-nm",
1929 ),
1930 tool_path(
1931 name = "objcopy",
1932 path = "linaro_linux_gcc/arm-linux-gnueabihf-objcopy",
1933 ),
1934 tool_path(
1935 name = "objdump",
1936 path = "linaro_linux_gcc/arm-linux-gnueabihf-objdump",
1937 ),
1938 tool_path(
1939 name = "strip",
1940 path = "linaro_linux_gcc/arm-linux-gnueabihf-strip",
1941 ),
1942 ]
1943 elif (ctx.attr.cpu == "armeabi-v7a"):
1944 tool_paths = [
1945 tool_path(name = "ar", path = "/bin/false"),
1946 tool_path(name = "compat-ld", path = "/bin/false"),
1947 tool_path(name = "cpp", path = "/bin/false"),
1948 tool_path(name = "dwp", path = "/bin/false"),
1949 tool_path(name = "gcc", path = "/bin/false"),
1950 tool_path(name = "gcov", path = "/bin/false"),
1951 tool_path(name = "ld", path = "/bin/false"),
1952 tool_path(name = "nm", path = "/bin/false"),
1953 tool_path(name = "objcopy", path = "/bin/false"),
1954 tool_path(name = "objdump", path = "/bin/false"),
1955 tool_path(name = "strip", path = "/bin/false"),
1956 ]
1957 else:
1958 fail("Unreachable")
1959
Austin Schuhda9d0602019-09-15 17:29:38 -07001960 out = ctx.actions.declare_file(ctx.label.name)
1961 ctx.actions.write(out, "Fake executable")
1962 return [
1963 cc_common.create_cc_toolchain_config_info(
1964 ctx = ctx,
1965 features = features,
1966 action_configs = action_configs,
1967 artifact_name_patterns = artifact_name_patterns,
1968 cxx_builtin_include_directories = cxx_builtin_include_directories,
1969 toolchain_identifier = toolchain_identifier,
1970 host_system_name = host_system_name,
1971 target_system_name = target_system_name,
1972 target_cpu = target_cpu,
1973 target_libc = target_libc,
1974 compiler = compiler,
1975 abi_version = abi_version,
1976 abi_libc_version = abi_libc_version,
1977 tool_paths = tool_paths,
1978 make_variables = make_variables,
1979 builtin_sysroot = builtin_sysroot,
Austin Schuha2503a72020-12-15 20:57:57 -08001980 cc_target_os = cc_target_os,
Austin Schuhda9d0602019-09-15 17:29:38 -07001981 ),
1982 DefaultInfo(
1983 executable = out,
1984 ),
1985 ]
Austin Schuha2503a72020-12-15 20:57:57 -08001986
1987cc_toolchain_config = rule(
Austin Schuhda9d0602019-09-15 17:29:38 -07001988 implementation = _impl,
1989 attrs = {
Austin Schuh0a96ea32022-01-01 22:29:30 -08001990 "cpu": attr.string(mandatory = True, values = ["armeabi-v7a", "armhf-debian", "cortex-m4f", "cortex-m4f-k22", "k8", "roborio", "rp2040"]),
Austin Schuhda9d0602019-09-15 17:29:38 -07001991 },
1992 provides = [CcToolchainConfigInfo],
1993 executable = True,
1994)