blob: 6c3796203771223f05ce07d0ed4fb07835894a8b [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):
Brian Silverman4c7235a2021-11-17 19:04:37 -080014 if ctx.attr.cpu == "rp2040":
Austin Schuh0a96ea32022-01-01 22:29:30 -080015 toolchain_identifier = "rp2040"
James Kuszmaul5a728562023-12-28 21:45:01 -080016 elif ctx.attr.cpu == "cortex-m4f-imu":
17 toolchain_identifier = "cortex-m4f-imu"
Brian Silverman94cab072022-01-02 23:50:03 -080018 elif ctx.attr.cpu == "cortex-m4f":
Austin Schuhda9d0602019-09-15 17:29:38 -070019 toolchain_identifier = "cortex-m4f"
Brian Silverman94cab072022-01-02 23:50:03 -080020 elif ctx.attr.cpu == "cortex-m4f-k22":
Austin Schuhda9d0602019-09-15 17:29:38 -070021 toolchain_identifier = "cortex-m4f-k22"
Brian Silverman94cab072022-01-02 23:50:03 -080022 elif ctx.attr.cpu == "roborio":
Austin Schuhda9d0602019-09-15 17:29:38 -070023 toolchain_identifier = "roborio_linux"
Austin Schuhda9d0602019-09-15 17:29:38 -070024 else:
25 fail("Unreachable")
26
Brian Silverman33ca3692022-02-06 18:37:17 -080027 if (ctx.attr.cpu == "rp2040" or
James Kuszmaul5a728562023-12-28 21:45:01 -080028 ctx.attr.cpu == "cortex-m4f-imu" or
Brian Silverman33ca3692022-02-06 18:37:17 -080029 ctx.attr.cpu == "cortex-m4f" or
30 ctx.attr.cpu == "cortex-m4f-k22"):
Austin Schuhda9d0602019-09-15 17:29:38 -070031 host_system_name = "local"
Brian Silverman94cab072022-01-02 23:50:03 -080032 elif ctx.attr.cpu == "roborio":
Austin Schuhda9d0602019-09-15 17:29:38 -070033 host_system_name = "roborio"
34 else:
35 fail("Unreachable")
36
Brian Silverman33ca3692022-02-06 18:37:17 -080037 if ctx.attr.cpu == "rp2040":
Austin Schuh0a96ea32022-01-01 22:29:30 -080038 target_system_name = "rp2040"
James Kuszmaul5a728562023-12-28 21:45:01 -080039 elif ctx.attr.cpu == "cortex-m4f-imu":
40 target_system_name = "cortex-m4f-imu"
Brian Silverman94cab072022-01-02 23:50:03 -080041 elif ctx.attr.cpu == "cortex-m4f":
Austin Schuhda9d0602019-09-15 17:29:38 -070042 target_system_name = "cortex-m4f"
Brian Silverman94cab072022-01-02 23:50:03 -080043 elif ctx.attr.cpu == "cortex-m4f-k22":
Austin Schuhda9d0602019-09-15 17:29:38 -070044 target_system_name = "cortex-m4f-k22"
Brian Silverman94cab072022-01-02 23:50:03 -080045 elif ctx.attr.cpu == "roborio":
Austin Schuhda9d0602019-09-15 17:29:38 -070046 target_system_name = "roborio"
47 else:
48 fail("Unreachable")
49
Brian Silverman33ca3692022-02-06 18:37:17 -080050 if ctx.attr.cpu == "rp2040":
Austin Schuh0a96ea32022-01-01 22:29:30 -080051 target_cpu = "rp2040"
James Kuszmaul5a728562023-12-28 21:45:01 -080052 elif ctx.attr.cpu == "cortex-m4f-imu":
53 target_cpu = "cortex-m4f-imu"
Brian Silverman94cab072022-01-02 23:50:03 -080054 elif ctx.attr.cpu == "cortex-m4f":
Austin Schuhda9d0602019-09-15 17:29:38 -070055 target_cpu = "cortex-m4f"
Brian Silverman94cab072022-01-02 23:50:03 -080056 elif ctx.attr.cpu == "cortex-m4f-k22":
Austin Schuhda9d0602019-09-15 17:29:38 -070057 target_cpu = "cortex-m4f-k22"
Brian Silverman94cab072022-01-02 23:50:03 -080058 elif ctx.attr.cpu == "roborio":
Austin Schuhda9d0602019-09-15 17:29:38 -070059 target_cpu = "roborio"
60 else:
61 fail("Unreachable")
62
Brian Silverman33ca3692022-02-06 18:37:17 -080063 if ctx.attr.cpu == "rp2040":
Austin Schuh0a96ea32022-01-01 22:29:30 -080064 target_libc = "rp2040"
James Kuszmaul5a728562023-12-28 21:45:01 -080065 elif ctx.attr.cpu == "cortex-m4f-imu":
66 target_libc = "cortex-m4f-imu"
Brian Silverman94cab072022-01-02 23:50:03 -080067 elif ctx.attr.cpu == "cortex-m4f":
Austin Schuhda9d0602019-09-15 17:29:38 -070068 target_libc = "cortex-m4f"
Brian Silverman94cab072022-01-02 23:50:03 -080069 elif ctx.attr.cpu == "cortex-m4f-k22":
Austin Schuhda9d0602019-09-15 17:29:38 -070070 target_libc = "cortex-m4f-k22"
Brian Silverman94cab072022-01-02 23:50:03 -080071 elif ctx.attr.cpu == "roborio":
Austin Schuhda9d0602019-09-15 17:29:38 -070072 target_libc = "roborio"
73 else:
74 fail("Unreachable")
75
Brian Silverman33ca3692022-02-06 18:37:17 -080076 if (ctx.attr.cpu == "rp2040" or
James Kuszmaul5a728562023-12-28 21:45:01 -080077 ctx.attr.cpu == "cortex-m4f-imu" or
Brian Silverman33ca3692022-02-06 18:37:17 -080078 ctx.attr.cpu == "cortex-m4f" or
79 ctx.attr.cpu == "cortex-m4f-k22" or
80 ctx.attr.cpu == "roborio"):
Austin Schuhda9d0602019-09-15 17:29:38 -070081 compiler = "gcc"
82 else:
83 fail("Unreachable")
84
Brian Silverman33ca3692022-02-06 18:37:17 -080085 if ctx.attr.cpu == "rp2040":
Austin Schuh0a96ea32022-01-01 22:29:30 -080086 abi_version = "rp2040"
James Kuszmaul5a728562023-12-28 21:45:01 -080087 elif ctx.attr.cpu == "cortex-m4f-imu":
88 abi_version = "cortex-m4f-imu"
Brian Silverman94cab072022-01-02 23:50:03 -080089 elif ctx.attr.cpu == "cortex-m4f":
Austin Schuhda9d0602019-09-15 17:29:38 -070090 abi_version = "cortex-m4f"
Brian Silverman94cab072022-01-02 23:50:03 -080091 elif ctx.attr.cpu == "cortex-m4f-k22":
Austin Schuhda9d0602019-09-15 17:29:38 -070092 abi_version = "cortex-m4f-k22"
Brian Silverman94cab072022-01-02 23:50:03 -080093 elif ctx.attr.cpu == "roborio":
Austin Schuhda9d0602019-09-15 17:29:38 -070094 abi_version = "roborio"
95 else:
96 fail("Unreachable")
97
Brian Silverman33ca3692022-02-06 18:37:17 -080098 if ctx.attr.cpu == "rp2040":
Austin Schuh0a96ea32022-01-01 22:29:30 -080099 abi_libc_version = "rp2040"
James Kuszmaul5a728562023-12-28 21:45:01 -0800100 elif ctx.attr.cpu == "cortex-m4f-imu":
101 abi_libc_version = "cortex-m4f-imu"
Brian Silverman94cab072022-01-02 23:50:03 -0800102 elif ctx.attr.cpu == "cortex-m4f":
Austin Schuhda9d0602019-09-15 17:29:38 -0700103 abi_libc_version = "cortex-m4f"
Brian Silverman94cab072022-01-02 23:50:03 -0800104 elif ctx.attr.cpu == "cortex-m4f-k22":
Austin Schuhda9d0602019-09-15 17:29:38 -0700105 abi_libc_version = "cortex-m4f-k22"
Brian Silverman94cab072022-01-02 23:50:03 -0800106 elif ctx.attr.cpu == "roborio":
Austin Schuhda9d0602019-09-15 17:29:38 -0700107 abi_libc_version = "roborio"
108 else:
109 fail("Unreachable")
110
111 cc_target_os = None
112
113 builtin_sysroot = None
114
Austin Schuhda9d0602019-09-15 17:29:38 -0700115 all_cpp_compile_actions = [
116 ACTION_NAMES.cpp_compile,
117 ACTION_NAMES.linkstamp_compile,
118 ACTION_NAMES.cpp_header_parsing,
119 ACTION_NAMES.cpp_module_compile,
120 ACTION_NAMES.cpp_module_codegen,
121 ACTION_NAMES.clif_match,
122 ]
123
Austin Schuhda9d0602019-09-15 17:29:38 -0700124 all_link_actions = [
125 ACTION_NAMES.cpp_link_executable,
126 ACTION_NAMES.cpp_link_dynamic_library,
127 ACTION_NAMES.cpp_link_nodeps_dynamic_library,
128 ]
129
Brian Silverman94cab072022-01-02 23:50:03 -0800130 if ctx.attr.cpu == "roborio":
Austin Schuhda9d0602019-09-15 17:29:38 -0700131 objcopy_embed_data_action = action_config(
132 action_name = "objcopy_embed_data",
133 enabled = True,
134 tools = [
135 tool(
136 path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-objcopy",
137 ),
138 ],
139 )
Austin Schuh0a96ea32022-01-01 22:29:30 -0800140 elif (ctx.attr.cpu == "rp2040" or
James Kuszmaul5a728562023-12-28 21:45:01 -0800141 ctx.attr.cpu == "cortex-m4f-imu" or
Austin Schuh0a96ea32022-01-01 22:29:30 -0800142 ctx.attr.cpu == "cortex-m4f" or
Austin Schuha2503a72020-12-15 20:57:57 -0800143 ctx.attr.cpu == "cortex-m4f-k22"):
Austin Schuhda9d0602019-09-15 17:29:38 -0700144 objcopy_embed_data_action = action_config(
145 action_name = "objcopy_embed_data",
146 enabled = True,
147 tools = [tool(path = "gcc_arm_none_eabi/arm-none-eabi-objcopy")],
148 )
149 else:
150 objcopy_embed_data_action = None
151
Brian Silverman33ca3692022-02-06 18:37:17 -0800152 if (ctx.attr.cpu == "rp2040" or
James Kuszmaul5a728562023-12-28 21:45:01 -0800153 ctx.attr.cpu == "cortex-m4f-imu" or
Brian Silverman33ca3692022-02-06 18:37:17 -0800154 ctx.attr.cpu == "cortex-m4f" or
155 ctx.attr.cpu == "cortex-m4f-k22" or
156 ctx.attr.cpu == "roborio"):
Austin Schuhda9d0602019-09-15 17:29:38 -0700157 action_configs = [objcopy_embed_data_action]
158 else:
159 fail("Unreachable")
160
161 opt_post_feature = feature(
162 name = "opt_post",
163 flag_sets = [
164 flag_set(
Brian Silverman7b53ae12022-05-22 21:40:57 -0700165 actions = all_cpp_compile_actions + [
Austin Schuhda9d0602019-09-15 17:29:38 -0700166 ACTION_NAMES.preprocess_assemble,
167 ACTION_NAMES.c_compile,
Austin Schuhda9d0602019-09-15 17:29:38 -0700168 ],
169 flag_groups = [flag_group(flags = ["-DAOS_DEBUG=0"])],
170 ),
171 ],
172 )
173
174 supports_pic_feature = feature(name = "supports_pic", enabled = True)
175
Brian Silverman4c7235a2021-11-17 19:04:37 -0800176 if ctx.attr.cpu == "cortex-m4f-k22":
Austin Schuhda9d0602019-09-15 17:29:38 -0700177 default_compile_flags_feature = feature(
178 name = "default_compile_flags",
179 enabled = True,
180 flag_sets = [
181 flag_set(
182 actions = [
183 ACTION_NAMES.assemble,
184 ACTION_NAMES.preprocess_assemble,
185 ACTION_NAMES.linkstamp_compile,
186 ACTION_NAMES.c_compile,
187 ACTION_NAMES.cpp_compile,
188 ACTION_NAMES.cpp_header_parsing,
189 ACTION_NAMES.cpp_module_compile,
190 ACTION_NAMES.cpp_module_codegen,
191 ACTION_NAMES.lto_backend,
192 ACTION_NAMES.clif_match,
193 ],
194 flag_groups = [
195 flag_group(
196 flags = [
197 "-D__STDC_FORMAT_MACROS",
198 "-D__STDC_CONSTANT_MACROS",
199 "-D__STDC_LIMIT_MACROS",
200 "-D__MK22FX512__",
201 "-DF_CPU=120000000",
202 "-Wl,--gc-sections",
203 "-D__have_long32",
204 "-fstack-protector",
205 "-mcpu=cortex-m4",
206 "-mfpu=fpv4-sp-d16",
207 "-mthumb",
208 "-mfloat-abi=hard",
209 "-fno-strict-aliasing",
210 "-fmessage-length=80",
211 "-fmax-errors=20",
212 "-Wall",
213 "-Wextra",
214 "-Wpointer-arith",
215 "-Wcast-qual",
216 "-Wwrite-strings",
217 "-Wtype-limits",
218 "-Wsign-compare",
219 "-Wformat=2",
220 "-Werror",
221 "-Wstrict-aliasing=2",
222 "-Wno-misleading-indentation",
223 "-Wno-int-in-bool-context",
224 "-Wdouble-promotion",
225 "-pipe",
226 "-g",
227 "-fno-common",
228 "-ffreestanding",
229 "-fbuiltin",
230 ],
231 ),
232 ],
233 ),
234 flag_set(
235 actions = [
236 ACTION_NAMES.assemble,
237 ACTION_NAMES.preprocess_assemble,
238 ACTION_NAMES.linkstamp_compile,
239 ACTION_NAMES.c_compile,
240 ACTION_NAMES.cpp_compile,
241 ACTION_NAMES.cpp_header_parsing,
242 ACTION_NAMES.cpp_module_compile,
243 ACTION_NAMES.cpp_module_codegen,
244 ACTION_NAMES.lto_backend,
245 ACTION_NAMES.clif_match,
246 ],
247 flag_groups = [
248 flag_group(
249 flags = [
250 "-O2",
251 "-finline-functions",
252 "-ffast-math",
253 "-funroll-loops",
254 "-DNDEBUG",
255 "-ffunction-sections",
256 ],
257 ),
258 ],
259 with_features = [with_feature_set(features = ["opt"])],
260 ),
261 ],
262 )
Brian Silverman94cab072022-01-02 23:50:03 -0800263 elif ctx.attr.cpu == "cortex-m4f":
Austin Schuhda9d0602019-09-15 17:29:38 -0700264 default_compile_flags_feature = feature(
265 name = "default_compile_flags",
266 enabled = True,
267 flag_sets = [
268 flag_set(
269 actions = [
270 ACTION_NAMES.assemble,
271 ACTION_NAMES.preprocess_assemble,
272 ACTION_NAMES.linkstamp_compile,
273 ACTION_NAMES.c_compile,
274 ACTION_NAMES.cpp_compile,
275 ACTION_NAMES.cpp_header_parsing,
276 ACTION_NAMES.cpp_module_compile,
277 ACTION_NAMES.cpp_module_codegen,
278 ACTION_NAMES.lto_backend,
279 ACTION_NAMES.clif_match,
280 ],
281 flag_groups = [
282 flag_group(
283 flags = [
284 "-D__STDC_FORMAT_MACROS",
285 "-D__STDC_CONSTANT_MACROS",
286 "-D__STDC_LIMIT_MACROS",
287 "-D__MK64FX512__",
288 "-DF_CPU=120000000",
289 "-Wl,--gc-sections",
290 "-D__have_long32",
291 "-fstack-protector",
292 "-mcpu=cortex-m4",
293 "-mfpu=fpv4-sp-d16",
294 "-mthumb",
295 "-mfloat-abi=hard",
296 "-fno-strict-aliasing",
297 "-fmessage-length=80",
298 "-fmax-errors=20",
299 "-Wall",
300 "-Wextra",
301 "-Wpointer-arith",
302 "-Wcast-qual",
303 "-Wwrite-strings",
304 "-Wtype-limits",
305 "-Wsign-compare",
306 "-Wformat=2",
307 "-Werror",
308 "-Wstrict-aliasing=2",
309 "-Wno-misleading-indentation",
310 "-Wno-int-in-bool-context",
311 "-Wdouble-promotion",
312 "-pipe",
313 "-g",
314 "-fno-common",
Austin Schuhda9d0602019-09-15 17:29:38 -0700315 "-fbuiltin",
316 ],
317 ),
318 ],
319 ),
320 flag_set(
321 actions = [
322 ACTION_NAMES.assemble,
323 ACTION_NAMES.preprocess_assemble,
324 ACTION_NAMES.linkstamp_compile,
325 ACTION_NAMES.c_compile,
326 ACTION_NAMES.cpp_compile,
327 ACTION_NAMES.cpp_header_parsing,
328 ACTION_NAMES.cpp_module_compile,
329 ACTION_NAMES.cpp_module_codegen,
330 ACTION_NAMES.lto_backend,
331 ACTION_NAMES.clif_match,
332 ],
333 flag_groups = [
334 flag_group(
335 flags = [
336 "-O2",
337 "-finline-functions",
338 "-ffast-math",
339 "-funroll-loops",
340 "-DNDEBUG",
341 "-ffunction-sections",
342 ],
343 ),
344 ],
345 with_features = [with_feature_set(features = ["opt"])],
346 ),
347 ],
348 )
Brian Silverman94cab072022-01-02 23:50:03 -0800349 elif ctx.attr.cpu == "rp2040":
Austin Schuh0a96ea32022-01-01 22:29:30 -0800350 default_compile_flags_feature = feature(
351 name = "default_compile_flags",
352 enabled = True,
353 flag_sets = [
354 flag_set(
355 actions = [
356 ACTION_NAMES.assemble,
357 ACTION_NAMES.preprocess_assemble,
358 ACTION_NAMES.linkstamp_compile,
359 ACTION_NAMES.c_compile,
360 ACTION_NAMES.cpp_compile,
361 ACTION_NAMES.cpp_header_parsing,
362 ACTION_NAMES.cpp_module_compile,
363 ACTION_NAMES.cpp_module_codegen,
364 ACTION_NAMES.lto_backend,
365 ACTION_NAMES.clif_match,
366 ],
367 flag_groups = [
368 flag_group(
369 flags = [
370 "-DPICO_BOARD=\"pico\"",
371 "-DPICO_BUILD=1",
372 "-DPICO_NO_HARDWARE=0",
373 "-DPICO_ON_DEVICE=1",
374 "-D__STDC_FORMAT_MACROS",
375 "-D__STDC_CONSTANT_MACROS",
376 "-D__STDC_LIMIT_MACROS",
377 "-Wl,--gc-sections",
378 "-fstack-protector",
379 "-mcpu=cortex-m0plus",
380 "-mthumb",
381 "-fno-strict-aliasing",
382 "-fmessage-length=80",
383 "-fmax-errors=20",
384 "-Wall",
385 "-Wextra",
386 "-Wpointer-arith",
387 "-Wcast-qual",
388 "-Wwrite-strings",
389 "-Wtype-limits",
390 "-Wsign-compare",
391 "-Wformat=2",
392 "-Werror",
393 "-Wstrict-aliasing=2",
394 "-Wno-misleading-indentation",
395 "-Wno-int-in-bool-context",
396 "-Wdouble-promotion",
397 "-pipe",
398 "-g",
399 ],
400 ),
401 ],
402 ),
403 flag_set(
404 actions = [
405 ACTION_NAMES.assemble,
406 ACTION_NAMES.preprocess_assemble,
407 ACTION_NAMES.linkstamp_compile,
408 ACTION_NAMES.c_compile,
409 ACTION_NAMES.cpp_compile,
410 ACTION_NAMES.cpp_header_parsing,
411 ACTION_NAMES.cpp_module_compile,
412 ACTION_NAMES.cpp_module_codegen,
413 ACTION_NAMES.lto_backend,
414 ACTION_NAMES.clif_match,
415 ],
416 flag_groups = [
417 flag_group(
418 flags = [
419 "-O3",
420 "-finline-functions",
421 "-funroll-loops",
422 "-DNDEBUG",
423 "-ffunction-sections",
424 ],
425 ),
426 ],
427 with_features = [with_feature_set(features = ["opt"])],
428 ),
429 ],
430 )
James Kuszmaul5a728562023-12-28 21:45:01 -0800431 elif ctx.attr.cpu == "cortex-m4f-imu":
432 default_compile_flags_feature = feature(
433 name = "default_compile_flags",
434 enabled = True,
435 flag_sets = [
436 flag_set(
437 actions = [
438 ACTION_NAMES.assemble,
439 ACTION_NAMES.preprocess_assemble,
440 ACTION_NAMES.linkstamp_compile,
441 ACTION_NAMES.c_compile,
442 ACTION_NAMES.cpp_compile,
443 ACTION_NAMES.cpp_header_parsing,
444 ACTION_NAMES.cpp_module_compile,
445 ACTION_NAMES.cpp_module_codegen,
446 ACTION_NAMES.lto_backend,
447 ACTION_NAMES.clif_match,
448 ],
449 flag_groups = [
450 flag_group(
451 flags = [
452 "-fdata-sections",
453 "-fstack-usage",
454 "--specs=nano.specs",
455 "-ffunction-sections",
456 "-D__STDC_FORMAT_MACROS",
457 "-D__STDC_CONSTANT_MACROS",
458 "-D__STDC_LIMIT_MACROS",
459 "-Wl,--gc-sections",
460 "-fstack-protector",
461 "-mcpu=cortex-m4",
462 "-mfpu=fpv4-sp-d16",
463 "-mthumb",
464 "-mfloat-abi=hard",
465 "-fno-strict-aliasing",
466 "-fmessage-length=80",
467 "-fmax-errors=20",
468 "-Wall",
469 "-Wextra",
470 "-Wpointer-arith",
471 "-Wcast-qual",
472 "-Wwrite-strings",
473 "-Wtype-limits",
474 "-Wsign-compare",
475 "-Wformat=2",
476 "-Werror",
477 "-Wstrict-aliasing=2",
478 "-Wno-misleading-indentation",
479 "-Wno-int-in-bool-context",
480 "-pipe",
481 "-fno-common",
482 "-fbuiltin",
483 "-g",
484 ],
485 ),
486 ],
487 ),
488 flag_set(
489 actions = [
490 ACTION_NAMES.assemble,
491 ACTION_NAMES.preprocess_assemble,
492 ACTION_NAMES.linkstamp_compile,
493 ACTION_NAMES.c_compile,
494 ACTION_NAMES.cpp_compile,
495 ACTION_NAMES.cpp_header_parsing,
496 ACTION_NAMES.cpp_module_compile,
497 ACTION_NAMES.cpp_module_codegen,
498 ACTION_NAMES.lto_backend,
499 ACTION_NAMES.clif_match,
500 ],
501 flag_groups = [
502 flag_group(
503 flags = [
504 "-O3",
505 "-finline-functions",
506 "-funroll-loops",
507 "-DNDEBUG",
508 "-ffunction-sections",
509 ],
510 ),
511 ],
512 with_features = [with_feature_set(features = ["opt"])],
513 ),
514 ],
515 )
Austin Schuhda9d0602019-09-15 17:29:38 -0700516 else:
517 default_compile_flags_feature = None
518
Brian Silverman4c7235a2021-11-17 19:04:37 -0800519 if ctx.attr.cpu == "roborio":
Austin Schuhda9d0602019-09-15 17:29:38 -0700520 dbg_feature = feature(
521 name = "dbg",
522 flag_sets = [
523 flag_set(
Brian Silverman7b53ae12022-05-22 21:40:57 -0700524 actions = all_cpp_compile_actions + [
Austin Schuhda9d0602019-09-15 17:29:38 -0700525 ACTION_NAMES.preprocess_assemble,
526 ACTION_NAMES.c_compile,
Austin Schuhda9d0602019-09-15 17:29:38 -0700527 ],
528 flag_groups = [
529 flag_group(flags = ["-DAOS_DEBUG=1"]),
530 flag_group(flags = ["-fno-omit-frame-pointer"]),
531 ],
532 ),
533 ],
534 )
Austin Schuh0a96ea32022-01-01 22:29:30 -0800535 elif (ctx.attr.cpu == "rp2040" or
James Kuszmaul5a728562023-12-28 21:45:01 -0800536 ctx.attr.cpu == "cortex-m4f-imu" or
Austin Schuh0a96ea32022-01-01 22:29:30 -0800537 ctx.attr.cpu == "cortex-m4f" or
Austin Schuha2503a72020-12-15 20:57:57 -0800538 ctx.attr.cpu == "cortex-m4f-k22"):
Austin Schuhda9d0602019-09-15 17:29:38 -0700539 dbg_feature = feature(
540 name = "dbg",
541 flag_sets = [
542 flag_set(
Brian Silverman7b53ae12022-05-22 21:40:57 -0700543 actions = all_cpp_compile_actions + [
Austin Schuhda9d0602019-09-15 17:29:38 -0700544 ACTION_NAMES.preprocess_assemble,
545 ACTION_NAMES.c_compile,
Austin Schuhda9d0602019-09-15 17:29:38 -0700546 ],
547 flag_groups = [flag_group(flags = ["-fno-omit-frame-pointer"])],
548 ),
549 ],
550 implies = ["all_modes"],
551 )
552 else:
553 dbg_feature = None
554
Brian Silverman4c7235a2021-11-17 19:04:37 -0800555 if ctx.attr.cpu == "roborio":
Austin Schuhda9d0602019-09-15 17:29:38 -0700556 fastbuild_feature = feature(
557 name = "fastbuild",
558 flag_sets = [
559 flag_set(
Brian Silverman7b53ae12022-05-22 21:40:57 -0700560 actions = all_cpp_compile_actions + [
Austin Schuhda9d0602019-09-15 17:29:38 -0700561 ACTION_NAMES.preprocess_assemble,
562 ACTION_NAMES.c_compile,
Austin Schuhda9d0602019-09-15 17:29:38 -0700563 ],
564 flag_groups = [flag_group(flags = ["-DAOS_DEBUG=0"])],
565 ),
566 ],
567 )
Austin Schuh0a96ea32022-01-01 22:29:30 -0800568 elif (ctx.attr.cpu == "rp2040" or
James Kuszmaul5a728562023-12-28 21:45:01 -0800569 ctx.attr.cpu == "cortex-m4f-imu" or
Austin Schuh0a96ea32022-01-01 22:29:30 -0800570 ctx.attr.cpu == "cortex-m4f" or
Austin Schuha2503a72020-12-15 20:57:57 -0800571 ctx.attr.cpu == "cortex-m4f-k22"):
Austin Schuhda9d0602019-09-15 17:29:38 -0700572 fastbuild_feature = feature(name = "fastbuild", implies = ["all_modes"])
573 else:
574 fastbuild_feature = None
575
576 pie_for_linking_feature = feature(
577 name = "pie_for_linking",
578 enabled = True,
579 flag_sets = [
580 flag_set(
581 actions = [ACTION_NAMES.cpp_link_executable],
582 flag_groups = [flag_group(flags = ["-pie"])],
583 ),
584 ],
585 )
586
Brian Silverman94cab072022-01-02 23:50:03 -0800587 if ctx.attr.cpu == "roborio":
Austin Schuhda9d0602019-09-15 17:29:38 -0700588 opt_feature = feature(
589 name = "opt",
590 flag_sets = [
591 flag_set(
592 actions = [
593 ACTION_NAMES.assemble,
594 ACTION_NAMES.preprocess_assemble,
595 ACTION_NAMES.c_compile,
596 ACTION_NAMES.cpp_compile,
597 ACTION_NAMES.cpp_module_compile,
598 ACTION_NAMES.objc_compile,
599 ACTION_NAMES.objcpp_compile,
600 ACTION_NAMES.cpp_header_parsing,
601 ACTION_NAMES.linkstamp_compile,
602 ],
603 flag_groups = [
604 flag_group(
605 flags = [
606 "-O2",
607 "-DNDEBUG",
608 "-D_FORTIFY_SOURCE=1",
609 "-ffunction-sections",
610 "-fdata-sections",
611 ],
612 ),
613 ],
614 ),
615 flag_set(
616 actions = [
617 ACTION_NAMES.cpp_link_executable,
618 ACTION_NAMES.cpp_link_nodeps_dynamic_library,
619 ACTION_NAMES.cpp_link_dynamic_library,
620 ],
621 flag_groups = [flag_group(flags = ["-Wl,--gc-sections"])],
622 ),
623 ],
624 implies = ["opt_post"],
625 )
Austin Schuh0a96ea32022-01-01 22:29:30 -0800626 elif (ctx.attr.cpu == "rp2040" or
James Kuszmaul5a728562023-12-28 21:45:01 -0800627 ctx.attr.cpu == "cortex-m4f-imu" or
Austin Schuh0a96ea32022-01-01 22:29:30 -0800628 ctx.attr.cpu == "cortex-m4f" or
Austin Schuha2503a72020-12-15 20:57:57 -0800629 ctx.attr.cpu == "cortex-m4f-k22"):
Austin Schuhda9d0602019-09-15 17:29:38 -0700630 opt_feature = feature(name = "opt", implies = ["all_modes"])
631 else:
632 opt_feature = None
633
634 pic_feature = feature(
635 name = "pic",
636 enabled = True,
637 flag_sets = [
638 flag_set(
639 actions = [
640 ACTION_NAMES.assemble,
641 ACTION_NAMES.preprocess_assemble,
642 ACTION_NAMES.linkstamp_compile,
643 ACTION_NAMES.c_compile,
644 ACTION_NAMES.cpp_compile,
645 ACTION_NAMES.cpp_module_codegen,
646 ACTION_NAMES.cpp_module_compile,
647 ],
648 flag_groups = [
649 flag_group(flags = ["-fPIC"], expand_if_available = "pic"),
650 ],
651 ),
652 ],
653 )
654
Austin Schuh0a96ea32022-01-01 22:29:30 -0800655 if (ctx.attr.cpu == "rp2040" or
James Kuszmaul5a728562023-12-28 21:45:01 -0800656 ctx.attr.cpu == "cortex-m4f-imu" or
Austin Schuh0a96ea32022-01-01 22:29:30 -0800657 ctx.attr.cpu == "cortex-m4f" or
Austin Schuha2503a72020-12-15 20:57:57 -0800658 ctx.attr.cpu == "cortex-m4f-k22"):
Austin Schuhda9d0602019-09-15 17:29:38 -0700659 include_paths_feature = feature(
660 name = "include_paths",
661 enabled = True,
662 flag_sets = [
663 flag_set(
Brian Silverman7b53ae12022-05-22 21:40:57 -0700664 actions = all_cpp_compile_actions + [
Austin Schuhda9d0602019-09-15 17:29:38 -0700665 ACTION_NAMES.preprocess_assemble,
666 ACTION_NAMES.c_compile,
Austin Schuhda9d0602019-09-15 17:29:38 -0700667 ],
668 flag_groups = [
669 flag_group(
670 flags = ["-iquote", "%{quote_include_paths}"],
671 iterate_over = "quote_include_paths",
672 ),
673 flag_group(
674 flags = ["-I%{include_paths}"],
675 iterate_over = "include_paths",
676 ),
677 flag_group(
678 flags = ["-I", "%{system_include_paths}"],
679 iterate_over = "system_include_paths",
680 ),
681 ],
682 ),
683 ],
684 )
Brian Silverman94cab072022-01-02 23:50:03 -0800685 elif ctx.attr.cpu == "roborio":
Austin Schuhda9d0602019-09-15 17:29:38 -0700686 include_paths_feature = feature(
687 name = "include_paths",
688 enabled = True,
689 flag_sets = [
690 flag_set(
Brian Silverman7b53ae12022-05-22 21:40:57 -0700691 actions = all_cpp_compile_actions + [
Austin Schuhda9d0602019-09-15 17:29:38 -0700692 ACTION_NAMES.preprocess_assemble,
693 ACTION_NAMES.c_compile,
Austin Schuhda9d0602019-09-15 17:29:38 -0700694 ],
695 flag_groups = [
696 flag_group(
697 flags = ["-iquote", "%{quote_include_paths}"],
698 iterate_over = "quote_include_paths",
699 ),
700 flag_group(
701 flags = ["-I%{include_paths}"],
702 iterate_over = "include_paths",
703 ),
704 flag_group(
705 flags = ["-isystem", "%{system_include_paths}"],
706 iterate_over = "system_include_paths",
707 ),
708 ],
709 ),
710 ],
711 )
712 else:
713 include_paths_feature = None
714
715 random_seed_feature = feature(
716 name = "random_seed",
717 enabled = True,
718 flag_sets = [
719 flag_set(
720 actions = [
721 ACTION_NAMES.cpp_compile,
722 ACTION_NAMES.cpp_module_codegen,
723 ACTION_NAMES.cpp_module_compile,
724 ],
725 flag_groups = [
726 flag_group(
727 flags = ["-frandom-seed=%{output_file}"],
728 expand_if_available = "output_file",
729 ),
730 ],
731 ),
732 ],
733 )
734
Brian Silverman94cab072022-01-02 23:50:03 -0800735 if ctx.attr.cpu == "roborio":
Austin Schuhda9d0602019-09-15 17:29:38 -0700736 default_link_flags_feature = feature(
737 name = "default_link_flags",
738 enabled = True,
739 flag_sets = [
740 flag_set(
741 actions = all_link_actions,
742 flag_groups = [
743 flag_group(
744 flags = [
745 "-lstdc++",
746 "-Ltools/cpp/arm-frc-linux-gnueabi/libs",
747 "-no-canonical-prefixes",
748 "-Wl,-z,relro,-z,now",
749 "-lm",
750 "-pass-exit-codes",
751 "-Wl,--build-id=md5",
752 "-Wl,--hash-style=gnu",
753 ],
754 ),
755 ],
756 ),
757 ],
758 )
Brian Silverman94cab072022-01-02 23:50:03 -0800759 elif ctx.attr.cpu == "cortex-m4f-k22":
Austin Schuhda9d0602019-09-15 17:29:38 -0700760 default_link_flags_feature = feature(
761 name = "default_link_flags",
762 enabled = True,
763 flag_sets = [
764 flag_set(
765 actions = all_link_actions,
766 flag_groups = [
767 flag_group(
768 flags = [
769 "-no-canonical-prefixes",
770 "-mcpu=cortex-m4",
771 "-mfpu=fpv4-sp-d16",
772 "-mthumb",
773 "-mfloat-abi=hard",
774 "-fno-strict-aliasing",
775 "--specs=nano.specs",
776 "-lgcc",
777 "-lstdc++_nano",
778 "-lm",
779 "-lc_nano",
780 "-Tmotors/core/kinetis_512_128.ld",
781 "-Tmotors/core/kinetis_sections.ld",
782 ],
783 ),
784 ],
785 ),
786 flag_set(
787 actions = all_link_actions,
788 flag_groups = [flag_group(flags = ["-Wl,--gc-sections"])],
789 with_features = [with_feature_set(features = ["opt"])],
790 ),
791 ],
792 )
Brian Silverman94cab072022-01-02 23:50:03 -0800793 elif ctx.attr.cpu == "cortex-m4f":
Austin Schuhda9d0602019-09-15 17:29:38 -0700794 default_link_flags_feature = feature(
795 name = "default_link_flags",
796 enabled = True,
797 flag_sets = [
798 flag_set(
799 actions = all_link_actions,
800 flag_groups = [
801 flag_group(
802 flags = [
803 "-no-canonical-prefixes",
804 "-mcpu=cortex-m4",
805 "-mfpu=fpv4-sp-d16",
806 "-mthumb",
807 "-mfloat-abi=hard",
808 "-fno-strict-aliasing",
809 "--specs=nano.specs",
810 "-lgcc",
811 "-lstdc++_nano",
812 "-lm",
813 "-lc_nano",
814 "-Tmotors/core/kinetis_512_256.ld",
815 "-Tmotors/core/kinetis_sections.ld",
816 ],
817 ),
818 ],
819 ),
820 flag_set(
821 actions = all_link_actions,
822 flag_groups = [flag_group(flags = ["-Wl,--gc-sections"])],
823 with_features = [with_feature_set(features = ["opt"])],
824 ),
825 ],
826 )
James Kuszmaul5a728562023-12-28 21:45:01 -0800827 elif ctx.attr.cpu == "cortex-m4f-imu":
828 default_link_flags_feature = feature(
829 name = "default_link_flags",
830 enabled = True,
831 flag_sets = [
832 flag_set(
833 actions = all_link_actions,
834 flag_groups = [
835 flag_group(
836 flags = [
837 "--specs=nosys.specs",
838 "-no-canonical-prefixes",
839 "-mcpu=cortex-m4",
840 "-mfpu=fpv4-sp-d16",
841 "-mthumb",
842 "-mfloat-abi=hard",
843 "-fno-strict-aliasing",
844 "--specs=nano.specs",
845 "-Wl,--start-group",
846 "-lgcc",
847 "-lstdc++",
848 "-lm",
849 "-lc",
850 "-lsupc++",
851 "-Wl,--end-group",
852 "-Tfrc971/imu_fdcan/Dual_IMU/STM32G473RETX_FLASH.ld",
853 ],
854 ),
855 ],
856 ),
857 flag_set(
858 actions = all_link_actions,
859 flag_groups = [flag_group(flags = ["-Wl,--gc-sections"])],
860 with_features = [with_feature_set(features = ["opt"])],
861 ),
862 ],
863 )
Brian Silverman94cab072022-01-02 23:50:03 -0800864 elif ctx.attr.cpu == "rp2040":
Austin Schuh0a96ea32022-01-01 22:29:30 -0800865 default_link_flags_feature = feature(
866 name = "default_link_flags",
867 enabled = True,
868 flag_sets = [
869 flag_set(
870 actions = all_link_actions,
871 flag_groups = [
872 flag_group(
873 flags = [
874 "-no-canonical-prefixes",
875 "-mcpu=cortex-m0plus",
876 "-mthumb",
877 "-fno-strict-aliasing",
878 "-Wl,--build-id=none",
879 "--specs=nosys.specs",
880 "-nostartfiles",
881 ],
882 ),
883 ],
884 ),
885 # TODO(austin): I'd love to turn --gc-sections on, but that breaks things.
886 ],
887 )
Austin Schuhda9d0602019-09-15 17:29:38 -0700888 else:
James Kuszmaul5a728562023-12-28 21:45:01 -0800889 fail("Unreachable")
Austin Schuhda9d0602019-09-15 17:29:38 -0700890
Brian Silverman94cab072022-01-02 23:50:03 -0800891 if ctx.attr.cpu == "roborio":
Austin Schuhda9d0602019-09-15 17:29:38 -0700892 all_modes_feature = feature(
893 name = "all_modes",
894 enabled = True,
895 flag_sets = [
896 flag_set(
897 actions = [
898 ACTION_NAMES.preprocess_assemble,
899 ACTION_NAMES.assemble,
900 ACTION_NAMES.c_compile,
901 ],
902 flag_groups = [flag_group(flags = ["-std=gnu99"])],
903 ),
904 flag_set(
Brian Silverman7b53ae12022-05-22 21:40:57 -0700905 actions = all_cpp_compile_actions,
Austin Schuhda9d0602019-09-15 17:29:38 -0700906 flag_groups = [
907 flag_group(
James Kuszmaul9776b392023-01-14 14:08:08 -0800908 flags = ["-std=gnu++20", "-fno-sized-deallocation"],
Austin Schuhda9d0602019-09-15 17:29:38 -0700909 ),
910 ],
911 ),
912 flag_set(
Brian Silverman7b53ae12022-05-22 21:40:57 -0700913 actions = all_cpp_compile_actions + [
Austin Schuhda9d0602019-09-15 17:29:38 -0700914 ACTION_NAMES.preprocess_assemble,
915 ACTION_NAMES.assemble,
916 "c++-link",
Austin Schuhda9d0602019-09-15 17:29:38 -0700917 ACTION_NAMES.c_compile,
918 ],
919 flag_groups = [flag_group(flags = ["-pthread"])],
920 ),
921 ],
922 )
Austin Schuh0a96ea32022-01-01 22:29:30 -0800923 elif (ctx.attr.cpu == "rp2040" or
James Kuszmaul5a728562023-12-28 21:45:01 -0800924 ctx.attr.cpu == "cortex-m4f-imu" or
Austin Schuh0a96ea32022-01-01 22:29:30 -0800925 ctx.attr.cpu == "cortex-m4f" or
Austin Schuha2503a72020-12-15 20:57:57 -0800926 ctx.attr.cpu == "cortex-m4f-k22"):
Austin Schuhda9d0602019-09-15 17:29:38 -0700927 all_modes_feature = feature(
928 name = "all_modes",
929 flag_sets = [
930 flag_set(
931 actions = [
932 ACTION_NAMES.preprocess_assemble,
933 ACTION_NAMES.assemble,
934 ACTION_NAMES.c_compile,
935 ],
Austin Schuh0a96ea32022-01-01 22:29:30 -0800936 flag_groups = [flag_group(flags = ["--std=gnu11"])],
Austin Schuhda9d0602019-09-15 17:29:38 -0700937 ),
938 flag_set(
Brian Silverman7b53ae12022-05-22 21:40:57 -0700939 actions = all_cpp_compile_actions,
Austin Schuhda9d0602019-09-15 17:29:38 -0700940 flag_groups = [
941 flag_group(
James Kuszmaulef420da2023-12-27 12:02:15 -0800942 flags = ["--std=gnu++20", "-fno-exceptions", "-fno-rtti"],
Austin Schuhda9d0602019-09-15 17:29:38 -0700943 ),
944 ],
945 ),
946 ],
947 )
Austin Schuhda9d0602019-09-15 17:29:38 -0700948 else:
949 all_modes_feature = None
950
951 supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True)
952
Brian Silverman4c7235a2021-11-17 19:04:37 -0800953 if (ctx.attr.cpu == "rp2040" or
James Kuszmaul5a728562023-12-28 21:45:01 -0800954 ctx.attr.cpu == "cortex-m4f-imu" or
Brian Silverman4c7235a2021-11-17 19:04:37 -0800955 ctx.attr.cpu == "cortex-m4f" or
956 ctx.attr.cpu == "cortex-m4f-k22" or
957 ctx.attr.cpu == "roborio"):
Austin Schuhda9d0602019-09-15 17:29:38 -0700958 unfiltered_compile_flags_feature = feature(
959 name = "unfiltered_compile_flags",
960 enabled = True,
961 flag_sets = [
962 flag_set(
963 actions = [
964 ACTION_NAMES.assemble,
965 ACTION_NAMES.preprocess_assemble,
966 ACTION_NAMES.linkstamp_compile,
967 ACTION_NAMES.c_compile,
968 ACTION_NAMES.cpp_compile,
969 ACTION_NAMES.cpp_header_parsing,
970 ACTION_NAMES.cpp_module_compile,
971 ACTION_NAMES.cpp_module_codegen,
972 ACTION_NAMES.lto_backend,
973 ACTION_NAMES.clif_match,
974 ],
975 flag_groups = [
976 flag_group(
977 flags = [
978 "-no-canonical-prefixes",
979 "-Wno-builtin-macro-redefined",
980 "-D__DATE__=\"redacted\"",
981 "-D__TIMESTAMP__=\"redacted\"",
982 "-D__TIME__=\"redacted\"",
Austin Schuhda9d0602019-09-15 17:29:38 -0700983 ],
984 ),
985 ],
986 ),
987 ],
988 )
989 else:
990 unfiltered_compile_flags_feature = None
991
992 dependency_file_feature = feature(
993 name = "dependency_file",
994 enabled = True,
995 flag_sets = [
996 flag_set(
997 actions = [
998 ACTION_NAMES.assemble,
999 ACTION_NAMES.preprocess_assemble,
1000 ACTION_NAMES.c_compile,
1001 ACTION_NAMES.cpp_compile,
1002 ACTION_NAMES.cpp_module_compile,
1003 ACTION_NAMES.objc_compile,
1004 ACTION_NAMES.objcpp_compile,
1005 ACTION_NAMES.cpp_header_parsing,
1006 ACTION_NAMES.clif_match,
1007 ],
1008 flag_groups = [
1009 flag_group(
1010 flags = ["-MD", "-MF", "%{dependency_file}"],
1011 expand_if_available = "dependency_file",
1012 ),
1013 ],
1014 ),
1015 ],
1016 )
1017
Austin Schuhda9d0602019-09-15 17:29:38 -07001018 user_compile_flags_feature = feature(
1019 name = "user_compile_flags",
1020 enabled = True,
1021 flag_sets = [
1022 flag_set(
1023 actions = [
1024 ACTION_NAMES.assemble,
1025 ACTION_NAMES.preprocess_assemble,
1026 ACTION_NAMES.linkstamp_compile,
1027 ACTION_NAMES.c_compile,
1028 ACTION_NAMES.cpp_compile,
1029 ACTION_NAMES.cpp_header_parsing,
1030 ACTION_NAMES.cpp_module_compile,
1031 ACTION_NAMES.cpp_module_codegen,
1032 ACTION_NAMES.lto_backend,
1033 ACTION_NAMES.clif_match,
1034 ],
1035 flag_groups = [
1036 flag_group(
1037 flags = ["%{user_compile_flags}"],
1038 iterate_over = "user_compile_flags",
1039 expand_if_available = "user_compile_flags",
1040 ),
1041 ],
1042 ),
1043 ],
1044 )
1045
1046 sysroot_feature = feature(
1047 name = "sysroot",
1048 enabled = True,
1049 flag_sets = [
1050 flag_set(
1051 actions = [
1052 ACTION_NAMES.preprocess_assemble,
1053 ACTION_NAMES.linkstamp_compile,
1054 ACTION_NAMES.c_compile,
1055 ACTION_NAMES.cpp_compile,
1056 ACTION_NAMES.cpp_header_parsing,
1057 ACTION_NAMES.cpp_module_compile,
1058 ACTION_NAMES.cpp_module_codegen,
1059 ACTION_NAMES.lto_backend,
1060 ACTION_NAMES.clif_match,
1061 ACTION_NAMES.cpp_link_executable,
1062 ACTION_NAMES.cpp_link_dynamic_library,
1063 ACTION_NAMES.cpp_link_nodeps_dynamic_library,
1064 ],
1065 flag_groups = [
1066 flag_group(
1067 flags = ["--sysroot=%{sysroot}"],
1068 expand_if_available = "sysroot",
1069 ),
1070 ],
1071 ),
1072 ],
1073 )
1074
1075 compile_flags1_feature = feature(
1076 name = "compile_flags1",
1077 enabled = True,
1078 flag_sets = [
1079 flag_set(
1080 actions = [
1081 ACTION_NAMES.assemble,
1082 ACTION_NAMES.preprocess_assemble,
1083 ACTION_NAMES.c_compile,
1084 ACTION_NAMES.cpp_compile,
1085 ACTION_NAMES.cpp_header_parsing,
1086 ACTION_NAMES.cpp_module_compile,
1087 ACTION_NAMES.cpp_module_codegen,
1088 ACTION_NAMES.lto_backend,
1089 ACTION_NAMES.clif_match,
1090 ],
1091 flag_groups = [
1092 flag_group(
1093 flags = [
James Kuszmaul9776b392023-01-14 14:08:08 -08001094 "--sysroot=external/arm_frc_linux_gnueabi_repo/arm-nilrt-linux-gnueabi/sysroot",
Austin Schuhda9d0602019-09-15 17:29:38 -07001095 "-nostdinc",
1096 "-isystem",
James Kuszmaul9776b392023-01-14 14:08:08 -08001097 "external/arm_frc_linux_gnueabi_repo/arm-nilrt-linux-gnueabi/sysroot/usr/lib/gcc/arm-nilrt-linux-gnueabi/12/include",
Austin Schuhda9d0602019-09-15 17:29:38 -07001098 "-isystem",
James Kuszmaul9776b392023-01-14 14:08:08 -08001099 "external/arm_frc_linux_gnueabi_repo/arm-nilrt-linux-gnueabi/sysroot/usr/lib/gcc/arm-nilrt-linux-gnueabi/12/include-fixed",
Austin Schuhda9d0602019-09-15 17:29:38 -07001100 ],
1101 ),
1102 ],
1103 ),
1104 flag_set(
Brian Silverman7b53ae12022-05-22 21:40:57 -07001105 actions = all_cpp_compile_actions + [
Austin Schuhda9d0602019-09-15 17:29:38 -07001106 ACTION_NAMES.assemble,
1107 ACTION_NAMES.preprocess_assemble,
Austin Schuhda9d0602019-09-15 17:29:38 -07001108 ],
1109 flag_groups = [flag_group(flags = ["-fno-canonical-system-headers"])],
1110 ),
1111 flag_set(
1112 actions = [
1113 ACTION_NAMES.cpp_compile,
1114 ACTION_NAMES.cpp_header_parsing,
1115 ACTION_NAMES.cpp_module_compile,
1116 ACTION_NAMES.cpp_module_codegen,
1117 ],
1118 flag_groups = [
1119 flag_group(
1120 flags = [
1121 "-isystem",
James Kuszmaul9776b392023-01-14 14:08:08 -08001122 "external/arm_frc_linux_gnueabi_repo/arm-nilrt-linux-gnueabi/sysroot/usr/include/c++/12",
Austin Schuhda9d0602019-09-15 17:29:38 -07001123 "-isystem",
James Kuszmaul9776b392023-01-14 14:08:08 -08001124 "external/arm_frc_linux_gnueabi_repo/arm-nilrt-linux-gnueabi/sysroot/usr/include/c++/12/arm-nilrt-linux-gnueabi",
Austin Schuhda9d0602019-09-15 17:29:38 -07001125 "-isystem",
James Kuszmaul9776b392023-01-14 14:08:08 -08001126 "external/arm_frc_linux_gnueabi_repo/arm-nilrt-linux-gnueabi/sysroot/usr/include/c++/12/backward",
Austin Schuhda9d0602019-09-15 17:29:38 -07001127 ],
1128 ),
1129 ],
1130 ),
1131 flag_set(
1132 actions = [
1133 ACTION_NAMES.assemble,
1134 ACTION_NAMES.preprocess_assemble,
1135 ACTION_NAMES.c_compile,
1136 ACTION_NAMES.cpp_compile,
1137 ACTION_NAMES.cpp_header_parsing,
1138 ACTION_NAMES.cpp_module_compile,
1139 ACTION_NAMES.cpp_module_codegen,
1140 ACTION_NAMES.lto_backend,
1141 ACTION_NAMES.clif_match,
1142 ],
1143 flag_groups = [
1144 flag_group(
1145 flags = [
1146 "-isystem",
James Kuszmaul9776b392023-01-14 14:08:08 -08001147 "external/arm_frc_linux_gnueabi_repo/arm-nilrt-linux-gnueabi/sysroot/usr/include",
Austin Schuhda9d0602019-09-15 17:29:38 -07001148 "-mfpu=neon",
1149 "-D__STDC_FORMAT_MACROS",
1150 "-D__STDC_CONSTANT_MACROS",
1151 "-D__STDC_LIMIT_MACROS",
1152 "-D_FILE_OFFSET_BITS=64",
1153 "-DAOS_ARCHITECTURE_arm_frc",
1154 "-U_FORTIFY_SOURCE",
1155 "-fstack-protector",
1156 "-fPIE",
1157 "-fdiagnostics-color=always",
1158 "-Wall",
1159 "-Wextra",
1160 "-Wpointer-arith",
1161 "-Wstrict-aliasing",
1162 "-Wcast-qual",
1163 "-Wwrite-strings",
1164 "-Wtype-limits",
1165 "-Wsign-compare",
1166 "-Wformat=2",
1167 "-Werror",
1168 "-Wunused-local-typedefs",
1169 "-Wno-psabi",
1170 "-fno-omit-frame-pointer",
1171 "-D__has_feature(x)=0",
1172 "-pipe",
1173 "-ggdb3",
1174 ],
1175 ),
1176 ],
1177 ),
1178 ],
1179 )
1180
Austin Schuh0a96ea32022-01-01 22:29:30 -08001181 if (ctx.attr.cpu == "rp2040" or
James Kuszmaul5a728562023-12-28 21:45:01 -08001182 ctx.attr.cpu == "cortex-m4f-imu" or
Austin Schuh0a96ea32022-01-01 22:29:30 -08001183 ctx.attr.cpu == "cortex-m4f" or
Austin Schuha2503a72020-12-15 20:57:57 -08001184 ctx.attr.cpu == "cortex-m4f-k22"):
Austin Schuhda9d0602019-09-15 17:29:38 -07001185 features = [
Austin Schuha2503a72020-12-15 20:57:57 -08001186 default_compile_flags_feature,
1187 default_link_flags_feature,
1188 dbg_feature,
1189 opt_feature,
1190 fastbuild_feature,
1191 all_modes_feature,
1192 include_paths_feature,
Austin Schuha2503a72020-12-15 20:57:57 -08001193 user_compile_flags_feature,
1194 sysroot_feature,
1195 unfiltered_compile_flags_feature,
1196 ]
Brian Silverman94cab072022-01-02 23:50:03 -08001197 elif ctx.attr.cpu == "roborio":
Austin Schuhda9d0602019-09-15 17:29:38 -07001198 features = [
Austin Schuha2503a72020-12-15 20:57:57 -08001199 default_link_flags_feature,
1200 compile_flags1_feature,
1201 opt_feature,
1202 dependency_file_feature,
1203 random_seed_feature,
1204 pic_feature,
1205 include_paths_feature,
1206 opt_post_feature,
1207 dbg_feature,
1208 fastbuild_feature,
1209 all_modes_feature,
1210 pie_for_linking_feature,
1211 supports_dynamic_linker_feature,
1212 supports_pic_feature,
Austin Schuha2503a72020-12-15 20:57:57 -08001213 user_compile_flags_feature,
1214 sysroot_feature,
1215 unfiltered_compile_flags_feature,
1216 ]
Austin Schuhda9d0602019-09-15 17:29:38 -07001217 else:
1218 fail("Unreachable")
1219
Brian Silverman33ca3692022-02-06 18:37:17 -08001220 if ctx.attr.cpu == "roborio":
Austin Schuhda9d0602019-09-15 17:29:38 -07001221 cxx_builtin_include_directories = [
James Kuszmaul9776b392023-01-14 14:08:08 -08001222 "%package(@arm_frc_linux_gnueabi_repo//arm-nilrt-linux-gnueabi/sysroot/usr/lib/gcc/arm-nilrt-linux-gnueabi/12/include)%",
1223 "%package(@arm_frc_linux_gnueabi_repo//arm-nilrt-linux-gnueabi/sysroot/usr/lib/gcc/arm-nilrt-linux-gnueabi/12/include-fixed)%",
1224 "%package(@arm_frc_linux_gnueabi_repo//arm-nilrt-linux-gnueabi/sysroot/usr/include/c++/12/arm-nilrt-linux-gnueabi)%",
1225 "%package(@arm_frc_linux_gnueabi_repo//arm-nilrt-linux-gnueabi/sysroot/usr/include/c++/12/backward)%",
Austin Schuha2503a72020-12-15 20:57:57 -08001226 ]
Austin Schuh0a96ea32022-01-01 22:29:30 -08001227 elif (ctx.attr.cpu == "rp2040" or
James Kuszmaul5a728562023-12-28 21:45:01 -08001228 ctx.attr.cpu == "cortex-m4f-imu" or
Austin Schuh0a96ea32022-01-01 22:29:30 -08001229 ctx.attr.cpu == "cortex-m4f" or
Austin Schuha2503a72020-12-15 20:57:57 -08001230 ctx.attr.cpu == "cortex-m4f-k22"):
Austin Schuhda9d0602019-09-15 17:29:38 -07001231 cxx_builtin_include_directories = [
Austin Schuha2503a72020-12-15 20:57:57 -08001232 "/usr/lib/gcc/arm-none-eabi/4.8/include",
1233 "/usr/lib/gcc/arm-none-eabi/4.8/include-fixed",
1234 "/usr/lib/arm-none-eabi/include",
1235 "/usr/include/newlib",
1236 ]
Austin Schuhda9d0602019-09-15 17:29:38 -07001237 else:
1238 fail("Unreachable")
1239
1240 artifact_name_patterns = []
1241
1242 make_variables = []
1243
Brian Silverman94cab072022-01-02 23:50:03 -08001244 if ctx.attr.cpu == "roborio":
Austin Schuhda9d0602019-09-15 17:29:38 -07001245 tool_paths = [
1246 tool_path(
1247 name = "ar",
1248 path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-ar",
1249 ),
1250 tool_path(
1251 name = "as",
1252 path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-as",
1253 ),
1254 tool_path(
1255 name = "compat-ld",
1256 path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-ld",
1257 ),
1258 tool_path(
1259 name = "cpp",
1260 path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-cpp",
1261 ),
1262 tool_path(name = "dwp", path = "/bin/false"),
1263 tool_path(
1264 name = "gcc",
1265 path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-gcc",
1266 ),
1267 tool_path(
1268 name = "gcov",
1269 path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-gcov-4.9",
1270 ),
1271 tool_path(
1272 name = "ld",
1273 path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-ld",
1274 ),
1275 tool_path(
1276 name = "nm",
1277 path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-nm",
1278 ),
1279 tool_path(
1280 name = "objcopy",
1281 path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-objcopy",
1282 ),
1283 tool_path(
1284 name = "objdump",
1285 path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-objdump",
1286 ),
1287 tool_path(
1288 name = "strip",
1289 path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-strip",
1290 ),
1291 ]
Austin Schuh0a96ea32022-01-01 22:29:30 -08001292 elif (ctx.attr.cpu == "rp2040" or
James Kuszmaul5a728562023-12-28 21:45:01 -08001293 ctx.attr.cpu == "cortex-m4f-imu" or
Austin Schuh0a96ea32022-01-01 22:29:30 -08001294 ctx.attr.cpu == "cortex-m4f" or
Austin Schuha2503a72020-12-15 20:57:57 -08001295 ctx.attr.cpu == "cortex-m4f-k22"):
Austin Schuhda9d0602019-09-15 17:29:38 -07001296 tool_paths = [
1297 tool_path(
1298 name = "ar",
1299 path = "gcc_arm_none_eabi/arm-none-eabi-ar",
1300 ),
1301 tool_path(
1302 name = "compat-ld",
1303 path = "gcc_arm_none_eabi/arm-none-eabi-ld",
1304 ),
1305 tool_path(
1306 name = "cpp",
1307 path = "gcc_arm_none_eabi/arm-none-eabi-cpp",
1308 ),
1309 tool_path(
1310 name = "dwp",
1311 path = "gcc_arm_none_eabi/arm-none-eabi-dwp",
1312 ),
1313 tool_path(
1314 name = "gcc",
1315 path = "gcc_arm_none_eabi/arm-none-eabi-gcc",
1316 ),
1317 tool_path(
1318 name = "gcov",
1319 path = "gcc_arm_none_eabi/arm-none-eabi-gcov",
1320 ),
1321 tool_path(
1322 name = "ld",
1323 path = "gcc_arm_none_eabi/arm-none-eabi-ld",
1324 ),
1325 tool_path(
1326 name = "nm",
1327 path = "gcc_arm_none_eabi/arm-none-eabi-nm",
1328 ),
1329 tool_path(
1330 name = "objcopy",
1331 path = "gcc_arm_none_eabi/arm-none-eabi-objcopy",
1332 ),
1333 tool_path(
1334 name = "objdump",
1335 path = "gcc_arm_none_eabi/arm-none-eabi-objdump",
1336 ),
1337 tool_path(
1338 name = "strip",
1339 path = "gcc_arm_none_eabi/arm-none-eabi-strip",
1340 ),
1341 ]
Austin Schuhda9d0602019-09-15 17:29:38 -07001342 else:
1343 fail("Unreachable")
1344
Austin Schuhda9d0602019-09-15 17:29:38 -07001345 out = ctx.actions.declare_file(ctx.label.name)
1346 ctx.actions.write(out, "Fake executable")
1347 return [
1348 cc_common.create_cc_toolchain_config_info(
1349 ctx = ctx,
1350 features = features,
1351 action_configs = action_configs,
1352 artifact_name_patterns = artifact_name_patterns,
1353 cxx_builtin_include_directories = cxx_builtin_include_directories,
1354 toolchain_identifier = toolchain_identifier,
1355 host_system_name = host_system_name,
1356 target_system_name = target_system_name,
1357 target_cpu = target_cpu,
1358 target_libc = target_libc,
1359 compiler = compiler,
1360 abi_version = abi_version,
1361 abi_libc_version = abi_libc_version,
1362 tool_paths = tool_paths,
1363 make_variables = make_variables,
1364 builtin_sysroot = builtin_sysroot,
Austin Schuha2503a72020-12-15 20:57:57 -08001365 cc_target_os = cc_target_os,
Austin Schuhda9d0602019-09-15 17:29:38 -07001366 ),
1367 DefaultInfo(
1368 executable = out,
1369 ),
1370 ]
Austin Schuha2503a72020-12-15 20:57:57 -08001371
1372cc_toolchain_config = rule(
Austin Schuhda9d0602019-09-15 17:29:38 -07001373 implementation = _impl,
1374 attrs = {
James Kuszmaul5a728562023-12-28 21:45:01 -08001375 "cpu": attr.string(mandatory = True, values = ["cortex-m4f", "cortex-m4f-k22", "roborio", "rp2040", "cortex-m4f-imu"]),
Austin Schuhda9d0602019-09-15 17:29:38 -07001376 },
1377 provides = [CcToolchainConfigInfo],
1378 executable = True,
1379)