Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 1 | load( |
| 2 | "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 3 | "action_config", |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 4 | "feature", |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 5 | "flag_group", |
| 6 | "flag_set", |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 7 | "tool", |
| 8 | "tool_path", |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 9 | "with_feature_set", |
| 10 | ) |
| 11 | load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") |
| 12 | |
| 13 | def _impl(ctx): |
Brian Silverman | 4c7235a | 2021-11-17 19:04:37 -0800 | [diff] [blame] | 14 | if ctx.attr.cpu == "rp2040": |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 15 | toolchain_identifier = "rp2040" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 16 | elif ctx.attr.cpu == "cortex-m4f": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 17 | toolchain_identifier = "cortex-m4f" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 18 | elif ctx.attr.cpu == "cortex-m4f-k22": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 19 | toolchain_identifier = "cortex-m4f-k22" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 20 | elif ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 21 | toolchain_identifier = "roborio_linux" |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 22 | else: |
| 23 | fail("Unreachable") |
| 24 | |
Brian Silverman | 33ca369 | 2022-02-06 18:37:17 -0800 | [diff] [blame] | 25 | if (ctx.attr.cpu == "rp2040" or |
| 26 | ctx.attr.cpu == "cortex-m4f" or |
| 27 | ctx.attr.cpu == "cortex-m4f-k22"): |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 28 | host_system_name = "local" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 29 | elif ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 30 | host_system_name = "roborio" |
| 31 | else: |
| 32 | fail("Unreachable") |
| 33 | |
Brian Silverman | 33ca369 | 2022-02-06 18:37:17 -0800 | [diff] [blame] | 34 | if ctx.attr.cpu == "rp2040": |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 35 | target_system_name = "rp2040" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 36 | elif ctx.attr.cpu == "cortex-m4f": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 37 | target_system_name = "cortex-m4f" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 38 | elif ctx.attr.cpu == "cortex-m4f-k22": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 39 | target_system_name = "cortex-m4f-k22" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 40 | elif ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 41 | target_system_name = "roborio" |
| 42 | else: |
| 43 | fail("Unreachable") |
| 44 | |
Brian Silverman | 33ca369 | 2022-02-06 18:37:17 -0800 | [diff] [blame] | 45 | if ctx.attr.cpu == "rp2040": |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 46 | target_cpu = "rp2040" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 47 | elif ctx.attr.cpu == "cortex-m4f": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 48 | target_cpu = "cortex-m4f" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 49 | elif ctx.attr.cpu == "cortex-m4f-k22": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 50 | target_cpu = "cortex-m4f-k22" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 51 | elif ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 52 | target_cpu = "roborio" |
| 53 | else: |
| 54 | fail("Unreachable") |
| 55 | |
Brian Silverman | 33ca369 | 2022-02-06 18:37:17 -0800 | [diff] [blame] | 56 | if ctx.attr.cpu == "rp2040": |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 57 | target_libc = "rp2040" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 58 | elif ctx.attr.cpu == "cortex-m4f": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 59 | target_libc = "cortex-m4f" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 60 | elif ctx.attr.cpu == "cortex-m4f-k22": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 61 | target_libc = "cortex-m4f-k22" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 62 | elif ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 63 | target_libc = "roborio" |
| 64 | else: |
| 65 | fail("Unreachable") |
| 66 | |
Brian Silverman | 33ca369 | 2022-02-06 18:37:17 -0800 | [diff] [blame] | 67 | if (ctx.attr.cpu == "rp2040" or |
| 68 | ctx.attr.cpu == "cortex-m4f" or |
| 69 | ctx.attr.cpu == "cortex-m4f-k22" or |
| 70 | ctx.attr.cpu == "roborio"): |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 71 | compiler = "gcc" |
| 72 | else: |
| 73 | fail("Unreachable") |
| 74 | |
Brian Silverman | 33ca369 | 2022-02-06 18:37:17 -0800 | [diff] [blame] | 75 | if ctx.attr.cpu == "rp2040": |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 76 | abi_version = "rp2040" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 77 | elif ctx.attr.cpu == "cortex-m4f": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 78 | abi_version = "cortex-m4f" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 79 | elif ctx.attr.cpu == "cortex-m4f-k22": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 80 | abi_version = "cortex-m4f-k22" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 81 | elif ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 82 | abi_version = "roborio" |
| 83 | else: |
| 84 | fail("Unreachable") |
| 85 | |
Brian Silverman | 33ca369 | 2022-02-06 18:37:17 -0800 | [diff] [blame] | 86 | if ctx.attr.cpu == "rp2040": |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 87 | abi_libc_version = "rp2040" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 88 | elif ctx.attr.cpu == "cortex-m4f": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 89 | abi_libc_version = "cortex-m4f" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 90 | elif ctx.attr.cpu == "cortex-m4f-k22": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 91 | abi_libc_version = "cortex-m4f-k22" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 92 | elif ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 93 | abi_libc_version = "roborio" |
| 94 | else: |
| 95 | fail("Unreachable") |
| 96 | |
| 97 | cc_target_os = None |
| 98 | |
| 99 | builtin_sysroot = None |
| 100 | |
| 101 | all_compile_actions = [ |
| 102 | ACTION_NAMES.c_compile, |
| 103 | ACTION_NAMES.cpp_compile, |
| 104 | ACTION_NAMES.linkstamp_compile, |
| 105 | ACTION_NAMES.assemble, |
| 106 | ACTION_NAMES.preprocess_assemble, |
| 107 | ACTION_NAMES.cpp_header_parsing, |
| 108 | ACTION_NAMES.cpp_module_compile, |
| 109 | ACTION_NAMES.cpp_module_codegen, |
| 110 | ACTION_NAMES.clif_match, |
| 111 | ACTION_NAMES.lto_backend, |
| 112 | ] |
| 113 | |
| 114 | all_cpp_compile_actions = [ |
| 115 | ACTION_NAMES.cpp_compile, |
| 116 | ACTION_NAMES.linkstamp_compile, |
| 117 | ACTION_NAMES.cpp_header_parsing, |
| 118 | ACTION_NAMES.cpp_module_compile, |
| 119 | ACTION_NAMES.cpp_module_codegen, |
| 120 | ACTION_NAMES.clif_match, |
| 121 | ] |
| 122 | |
| 123 | preprocessor_compile_actions = [ |
| 124 | ACTION_NAMES.c_compile, |
| 125 | ACTION_NAMES.cpp_compile, |
| 126 | ACTION_NAMES.linkstamp_compile, |
| 127 | ACTION_NAMES.preprocess_assemble, |
| 128 | ACTION_NAMES.cpp_header_parsing, |
| 129 | ACTION_NAMES.cpp_module_compile, |
| 130 | ACTION_NAMES.clif_match, |
| 131 | ] |
| 132 | |
| 133 | codegen_compile_actions = [ |
| 134 | ACTION_NAMES.c_compile, |
| 135 | ACTION_NAMES.cpp_compile, |
| 136 | ACTION_NAMES.linkstamp_compile, |
| 137 | ACTION_NAMES.assemble, |
| 138 | ACTION_NAMES.preprocess_assemble, |
| 139 | ACTION_NAMES.cpp_module_codegen, |
| 140 | ACTION_NAMES.lto_backend, |
| 141 | ] |
| 142 | |
| 143 | all_link_actions = [ |
| 144 | ACTION_NAMES.cpp_link_executable, |
| 145 | ACTION_NAMES.cpp_link_dynamic_library, |
| 146 | ACTION_NAMES.cpp_link_nodeps_dynamic_library, |
| 147 | ] |
| 148 | |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 149 | if ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 150 | objcopy_embed_data_action = action_config( |
| 151 | action_name = "objcopy_embed_data", |
| 152 | enabled = True, |
| 153 | tools = [ |
| 154 | tool( |
| 155 | path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-objcopy", |
| 156 | ), |
| 157 | ], |
| 158 | ) |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 159 | elif (ctx.attr.cpu == "rp2040" or |
| 160 | ctx.attr.cpu == "cortex-m4f" or |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 161 | ctx.attr.cpu == "cortex-m4f-k22"): |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 162 | objcopy_embed_data_action = action_config( |
| 163 | action_name = "objcopy_embed_data", |
| 164 | enabled = True, |
| 165 | tools = [tool(path = "gcc_arm_none_eabi/arm-none-eabi-objcopy")], |
| 166 | ) |
| 167 | else: |
| 168 | objcopy_embed_data_action = None |
| 169 | |
Brian Silverman | 33ca369 | 2022-02-06 18:37:17 -0800 | [diff] [blame] | 170 | if (ctx.attr.cpu == "rp2040" or |
| 171 | ctx.attr.cpu == "cortex-m4f" or |
| 172 | ctx.attr.cpu == "cortex-m4f-k22" or |
| 173 | ctx.attr.cpu == "roborio"): |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 174 | action_configs = [objcopy_embed_data_action] |
| 175 | else: |
| 176 | fail("Unreachable") |
| 177 | |
| 178 | opt_post_feature = feature( |
| 179 | name = "opt_post", |
| 180 | flag_sets = [ |
| 181 | flag_set( |
| 182 | actions = [ |
| 183 | ACTION_NAMES.preprocess_assemble, |
| 184 | ACTION_NAMES.c_compile, |
| 185 | ACTION_NAMES.cpp_compile, |
| 186 | ACTION_NAMES.cpp_header_parsing, |
| 187 | "c++-header-preprocessing", |
| 188 | ACTION_NAMES.cpp_module_compile, |
| 189 | ], |
| 190 | flag_groups = [flag_group(flags = ["-DAOS_DEBUG=0"])], |
| 191 | ), |
| 192 | ], |
| 193 | ) |
| 194 | |
| 195 | supports_pic_feature = feature(name = "supports_pic", enabled = True) |
| 196 | |
Brian Silverman | 4c7235a | 2021-11-17 19:04:37 -0800 | [diff] [blame] | 197 | if ctx.attr.cpu == "cortex-m4f-k22": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 198 | default_compile_flags_feature = feature( |
| 199 | name = "default_compile_flags", |
| 200 | enabled = True, |
| 201 | flag_sets = [ |
| 202 | flag_set( |
| 203 | actions = [ |
| 204 | ACTION_NAMES.assemble, |
| 205 | ACTION_NAMES.preprocess_assemble, |
| 206 | ACTION_NAMES.linkstamp_compile, |
| 207 | ACTION_NAMES.c_compile, |
| 208 | ACTION_NAMES.cpp_compile, |
| 209 | ACTION_NAMES.cpp_header_parsing, |
| 210 | ACTION_NAMES.cpp_module_compile, |
| 211 | ACTION_NAMES.cpp_module_codegen, |
| 212 | ACTION_NAMES.lto_backend, |
| 213 | ACTION_NAMES.clif_match, |
| 214 | ], |
| 215 | flag_groups = [ |
| 216 | flag_group( |
| 217 | flags = [ |
| 218 | "-D__STDC_FORMAT_MACROS", |
| 219 | "-D__STDC_CONSTANT_MACROS", |
| 220 | "-D__STDC_LIMIT_MACROS", |
| 221 | "-D__MK22FX512__", |
| 222 | "-DF_CPU=120000000", |
| 223 | "-Wl,--gc-sections", |
| 224 | "-D__have_long32", |
| 225 | "-fstack-protector", |
| 226 | "-mcpu=cortex-m4", |
| 227 | "-mfpu=fpv4-sp-d16", |
| 228 | "-mthumb", |
| 229 | "-mfloat-abi=hard", |
| 230 | "-fno-strict-aliasing", |
| 231 | "-fmessage-length=80", |
| 232 | "-fmax-errors=20", |
| 233 | "-Wall", |
| 234 | "-Wextra", |
| 235 | "-Wpointer-arith", |
| 236 | "-Wcast-qual", |
| 237 | "-Wwrite-strings", |
| 238 | "-Wtype-limits", |
| 239 | "-Wsign-compare", |
| 240 | "-Wformat=2", |
| 241 | "-Werror", |
| 242 | "-Wstrict-aliasing=2", |
| 243 | "-Wno-misleading-indentation", |
| 244 | "-Wno-int-in-bool-context", |
| 245 | "-Wdouble-promotion", |
| 246 | "-pipe", |
| 247 | "-g", |
| 248 | "-fno-common", |
| 249 | "-ffreestanding", |
| 250 | "-fbuiltin", |
| 251 | ], |
| 252 | ), |
| 253 | ], |
| 254 | ), |
| 255 | flag_set( |
| 256 | actions = [ |
| 257 | ACTION_NAMES.assemble, |
| 258 | ACTION_NAMES.preprocess_assemble, |
| 259 | ACTION_NAMES.linkstamp_compile, |
| 260 | ACTION_NAMES.c_compile, |
| 261 | ACTION_NAMES.cpp_compile, |
| 262 | ACTION_NAMES.cpp_header_parsing, |
| 263 | ACTION_NAMES.cpp_module_compile, |
| 264 | ACTION_NAMES.cpp_module_codegen, |
| 265 | ACTION_NAMES.lto_backend, |
| 266 | ACTION_NAMES.clif_match, |
| 267 | ], |
| 268 | flag_groups = [ |
| 269 | flag_group( |
| 270 | flags = [ |
| 271 | "-O2", |
| 272 | "-finline-functions", |
| 273 | "-ffast-math", |
| 274 | "-funroll-loops", |
| 275 | "-DNDEBUG", |
| 276 | "-ffunction-sections", |
| 277 | ], |
| 278 | ), |
| 279 | ], |
| 280 | with_features = [with_feature_set(features = ["opt"])], |
| 281 | ), |
| 282 | ], |
| 283 | ) |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 284 | elif ctx.attr.cpu == "cortex-m4f": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 285 | default_compile_flags_feature = feature( |
| 286 | name = "default_compile_flags", |
| 287 | enabled = True, |
| 288 | flag_sets = [ |
| 289 | flag_set( |
| 290 | actions = [ |
| 291 | ACTION_NAMES.assemble, |
| 292 | ACTION_NAMES.preprocess_assemble, |
| 293 | ACTION_NAMES.linkstamp_compile, |
| 294 | ACTION_NAMES.c_compile, |
| 295 | ACTION_NAMES.cpp_compile, |
| 296 | ACTION_NAMES.cpp_header_parsing, |
| 297 | ACTION_NAMES.cpp_module_compile, |
| 298 | ACTION_NAMES.cpp_module_codegen, |
| 299 | ACTION_NAMES.lto_backend, |
| 300 | ACTION_NAMES.clif_match, |
| 301 | ], |
| 302 | flag_groups = [ |
| 303 | flag_group( |
| 304 | flags = [ |
| 305 | "-D__STDC_FORMAT_MACROS", |
| 306 | "-D__STDC_CONSTANT_MACROS", |
| 307 | "-D__STDC_LIMIT_MACROS", |
| 308 | "-D__MK64FX512__", |
| 309 | "-DF_CPU=120000000", |
| 310 | "-Wl,--gc-sections", |
| 311 | "-D__have_long32", |
| 312 | "-fstack-protector", |
| 313 | "-mcpu=cortex-m4", |
| 314 | "-mfpu=fpv4-sp-d16", |
| 315 | "-mthumb", |
| 316 | "-mfloat-abi=hard", |
| 317 | "-fno-strict-aliasing", |
| 318 | "-fmessage-length=80", |
| 319 | "-fmax-errors=20", |
| 320 | "-Wall", |
| 321 | "-Wextra", |
| 322 | "-Wpointer-arith", |
| 323 | "-Wcast-qual", |
| 324 | "-Wwrite-strings", |
| 325 | "-Wtype-limits", |
| 326 | "-Wsign-compare", |
| 327 | "-Wformat=2", |
| 328 | "-Werror", |
| 329 | "-Wstrict-aliasing=2", |
| 330 | "-Wno-misleading-indentation", |
| 331 | "-Wno-int-in-bool-context", |
| 332 | "-Wdouble-promotion", |
| 333 | "-pipe", |
| 334 | "-g", |
| 335 | "-fno-common", |
| 336 | "-ffreestanding", |
| 337 | "-fbuiltin", |
| 338 | ], |
| 339 | ), |
| 340 | ], |
| 341 | ), |
| 342 | flag_set( |
| 343 | actions = [ |
| 344 | ACTION_NAMES.assemble, |
| 345 | ACTION_NAMES.preprocess_assemble, |
| 346 | ACTION_NAMES.linkstamp_compile, |
| 347 | ACTION_NAMES.c_compile, |
| 348 | ACTION_NAMES.cpp_compile, |
| 349 | ACTION_NAMES.cpp_header_parsing, |
| 350 | ACTION_NAMES.cpp_module_compile, |
| 351 | ACTION_NAMES.cpp_module_codegen, |
| 352 | ACTION_NAMES.lto_backend, |
| 353 | ACTION_NAMES.clif_match, |
| 354 | ], |
| 355 | flag_groups = [ |
| 356 | flag_group( |
| 357 | flags = [ |
| 358 | "-O2", |
| 359 | "-finline-functions", |
| 360 | "-ffast-math", |
| 361 | "-funroll-loops", |
| 362 | "-DNDEBUG", |
| 363 | "-ffunction-sections", |
| 364 | ], |
| 365 | ), |
| 366 | ], |
| 367 | with_features = [with_feature_set(features = ["opt"])], |
| 368 | ), |
| 369 | ], |
| 370 | ) |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 371 | elif ctx.attr.cpu == "rp2040": |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 372 | default_compile_flags_feature = feature( |
| 373 | name = "default_compile_flags", |
| 374 | enabled = True, |
| 375 | flag_sets = [ |
| 376 | flag_set( |
| 377 | actions = [ |
| 378 | ACTION_NAMES.assemble, |
| 379 | ACTION_NAMES.preprocess_assemble, |
| 380 | ACTION_NAMES.linkstamp_compile, |
| 381 | ACTION_NAMES.c_compile, |
| 382 | ACTION_NAMES.cpp_compile, |
| 383 | ACTION_NAMES.cpp_header_parsing, |
| 384 | ACTION_NAMES.cpp_module_compile, |
| 385 | ACTION_NAMES.cpp_module_codegen, |
| 386 | ACTION_NAMES.lto_backend, |
| 387 | ACTION_NAMES.clif_match, |
| 388 | ], |
| 389 | flag_groups = [ |
| 390 | flag_group( |
| 391 | flags = [ |
| 392 | "-DPICO_BOARD=\"pico\"", |
| 393 | "-DPICO_BUILD=1", |
| 394 | "-DPICO_NO_HARDWARE=0", |
| 395 | "-DPICO_ON_DEVICE=1", |
| 396 | "-D__STDC_FORMAT_MACROS", |
| 397 | "-D__STDC_CONSTANT_MACROS", |
| 398 | "-D__STDC_LIMIT_MACROS", |
| 399 | "-Wl,--gc-sections", |
| 400 | "-fstack-protector", |
| 401 | "-mcpu=cortex-m0plus", |
| 402 | "-mthumb", |
| 403 | "-fno-strict-aliasing", |
| 404 | "-fmessage-length=80", |
| 405 | "-fmax-errors=20", |
| 406 | "-Wall", |
| 407 | "-Wextra", |
| 408 | "-Wpointer-arith", |
| 409 | "-Wcast-qual", |
| 410 | "-Wwrite-strings", |
| 411 | "-Wtype-limits", |
| 412 | "-Wsign-compare", |
| 413 | "-Wformat=2", |
| 414 | "-Werror", |
| 415 | "-Wstrict-aliasing=2", |
| 416 | "-Wno-misleading-indentation", |
| 417 | "-Wno-int-in-bool-context", |
| 418 | "-Wdouble-promotion", |
| 419 | "-pipe", |
| 420 | "-g", |
| 421 | ], |
| 422 | ), |
| 423 | ], |
| 424 | ), |
| 425 | flag_set( |
| 426 | actions = [ |
| 427 | ACTION_NAMES.assemble, |
| 428 | ACTION_NAMES.preprocess_assemble, |
| 429 | ACTION_NAMES.linkstamp_compile, |
| 430 | ACTION_NAMES.c_compile, |
| 431 | ACTION_NAMES.cpp_compile, |
| 432 | ACTION_NAMES.cpp_header_parsing, |
| 433 | ACTION_NAMES.cpp_module_compile, |
| 434 | ACTION_NAMES.cpp_module_codegen, |
| 435 | ACTION_NAMES.lto_backend, |
| 436 | ACTION_NAMES.clif_match, |
| 437 | ], |
| 438 | flag_groups = [ |
| 439 | flag_group( |
| 440 | flags = [ |
| 441 | "-O3", |
| 442 | "-finline-functions", |
| 443 | "-funroll-loops", |
| 444 | "-DNDEBUG", |
| 445 | "-ffunction-sections", |
| 446 | ], |
| 447 | ), |
| 448 | ], |
| 449 | with_features = [with_feature_set(features = ["opt"])], |
| 450 | ), |
| 451 | ], |
| 452 | ) |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 453 | else: |
| 454 | default_compile_flags_feature = None |
| 455 | |
Brian Silverman | 4c7235a | 2021-11-17 19:04:37 -0800 | [diff] [blame] | 456 | if ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 457 | dbg_feature = feature( |
| 458 | name = "dbg", |
| 459 | flag_sets = [ |
| 460 | flag_set( |
| 461 | actions = [ |
| 462 | ACTION_NAMES.preprocess_assemble, |
| 463 | ACTION_NAMES.c_compile, |
| 464 | ACTION_NAMES.cpp_compile, |
| 465 | ACTION_NAMES.cpp_header_parsing, |
| 466 | "c++-header-preprocessing", |
| 467 | ACTION_NAMES.cpp_module_compile, |
| 468 | ], |
| 469 | flag_groups = [ |
| 470 | flag_group(flags = ["-DAOS_DEBUG=1"]), |
| 471 | flag_group(flags = ["-fno-omit-frame-pointer"]), |
| 472 | ], |
| 473 | ), |
| 474 | ], |
| 475 | ) |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 476 | elif (ctx.attr.cpu == "rp2040" or |
| 477 | ctx.attr.cpu == "cortex-m4f" or |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 478 | ctx.attr.cpu == "cortex-m4f-k22"): |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 479 | dbg_feature = feature( |
| 480 | name = "dbg", |
| 481 | flag_sets = [ |
| 482 | flag_set( |
| 483 | actions = [ |
| 484 | ACTION_NAMES.preprocess_assemble, |
| 485 | ACTION_NAMES.c_compile, |
| 486 | ACTION_NAMES.cpp_compile, |
| 487 | ACTION_NAMES.cpp_header_parsing, |
| 488 | "c++-header-preprocessing", |
| 489 | ACTION_NAMES.cpp_module_compile, |
| 490 | ], |
| 491 | flag_groups = [flag_group(flags = ["-fno-omit-frame-pointer"])], |
| 492 | ), |
| 493 | ], |
| 494 | implies = ["all_modes"], |
| 495 | ) |
| 496 | else: |
| 497 | dbg_feature = None |
| 498 | |
Brian Silverman | 4c7235a | 2021-11-17 19:04:37 -0800 | [diff] [blame] | 499 | if ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 500 | fastbuild_feature = feature( |
| 501 | name = "fastbuild", |
| 502 | flag_sets = [ |
| 503 | flag_set( |
| 504 | actions = [ |
| 505 | ACTION_NAMES.preprocess_assemble, |
| 506 | ACTION_NAMES.c_compile, |
| 507 | ACTION_NAMES.cpp_compile, |
| 508 | ACTION_NAMES.cpp_header_parsing, |
| 509 | "c++-header-preprocessing", |
| 510 | ACTION_NAMES.cpp_module_compile, |
| 511 | ], |
| 512 | flag_groups = [flag_group(flags = ["-DAOS_DEBUG=0"])], |
| 513 | ), |
| 514 | ], |
| 515 | ) |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 516 | elif (ctx.attr.cpu == "rp2040" or |
| 517 | ctx.attr.cpu == "cortex-m4f" or |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 518 | ctx.attr.cpu == "cortex-m4f-k22"): |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 519 | fastbuild_feature = feature(name = "fastbuild", implies = ["all_modes"]) |
| 520 | else: |
| 521 | fastbuild_feature = None |
| 522 | |
| 523 | pie_for_linking_feature = feature( |
| 524 | name = "pie_for_linking", |
| 525 | enabled = True, |
| 526 | flag_sets = [ |
| 527 | flag_set( |
| 528 | actions = [ACTION_NAMES.cpp_link_executable], |
| 529 | flag_groups = [flag_group(flags = ["-pie"])], |
| 530 | ), |
| 531 | ], |
| 532 | ) |
| 533 | |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 534 | if ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 535 | opt_feature = feature( |
| 536 | name = "opt", |
| 537 | flag_sets = [ |
| 538 | flag_set( |
| 539 | actions = [ |
| 540 | ACTION_NAMES.assemble, |
| 541 | ACTION_NAMES.preprocess_assemble, |
| 542 | ACTION_NAMES.c_compile, |
| 543 | ACTION_NAMES.cpp_compile, |
| 544 | ACTION_NAMES.cpp_module_compile, |
| 545 | ACTION_NAMES.objc_compile, |
| 546 | ACTION_NAMES.objcpp_compile, |
| 547 | ACTION_NAMES.cpp_header_parsing, |
| 548 | ACTION_NAMES.linkstamp_compile, |
| 549 | ], |
| 550 | flag_groups = [ |
| 551 | flag_group( |
| 552 | flags = [ |
| 553 | "-O2", |
| 554 | "-DNDEBUG", |
| 555 | "-D_FORTIFY_SOURCE=1", |
| 556 | "-ffunction-sections", |
| 557 | "-fdata-sections", |
| 558 | ], |
| 559 | ), |
| 560 | ], |
| 561 | ), |
| 562 | flag_set( |
| 563 | actions = [ |
| 564 | ACTION_NAMES.cpp_link_executable, |
| 565 | ACTION_NAMES.cpp_link_nodeps_dynamic_library, |
| 566 | ACTION_NAMES.cpp_link_dynamic_library, |
| 567 | ], |
| 568 | flag_groups = [flag_group(flags = ["-Wl,--gc-sections"])], |
| 569 | ), |
| 570 | ], |
| 571 | implies = ["opt_post"], |
| 572 | ) |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 573 | elif (ctx.attr.cpu == "rp2040" or |
| 574 | ctx.attr.cpu == "cortex-m4f" or |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 575 | ctx.attr.cpu == "cortex-m4f-k22"): |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 576 | opt_feature = feature(name = "opt", implies = ["all_modes"]) |
| 577 | else: |
| 578 | opt_feature = None |
| 579 | |
| 580 | pic_feature = feature( |
| 581 | name = "pic", |
| 582 | enabled = True, |
| 583 | flag_sets = [ |
| 584 | flag_set( |
| 585 | actions = [ |
| 586 | ACTION_NAMES.assemble, |
| 587 | ACTION_NAMES.preprocess_assemble, |
| 588 | ACTION_NAMES.linkstamp_compile, |
| 589 | ACTION_NAMES.c_compile, |
| 590 | ACTION_NAMES.cpp_compile, |
| 591 | ACTION_NAMES.cpp_module_codegen, |
| 592 | ACTION_NAMES.cpp_module_compile, |
| 593 | ], |
| 594 | flag_groups = [ |
| 595 | flag_group(flags = ["-fPIC"], expand_if_available = "pic"), |
| 596 | ], |
| 597 | ), |
| 598 | ], |
| 599 | ) |
| 600 | |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 601 | if (ctx.attr.cpu == "rp2040" or |
| 602 | ctx.attr.cpu == "cortex-m4f" or |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 603 | ctx.attr.cpu == "cortex-m4f-k22"): |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 604 | include_paths_feature = feature( |
| 605 | name = "include_paths", |
| 606 | enabled = True, |
| 607 | flag_sets = [ |
| 608 | flag_set( |
| 609 | actions = [ |
| 610 | ACTION_NAMES.preprocess_assemble, |
| 611 | ACTION_NAMES.c_compile, |
| 612 | ACTION_NAMES.cpp_compile, |
| 613 | ACTION_NAMES.cpp_header_parsing, |
| 614 | "c++-header-preprocessing", |
| 615 | ACTION_NAMES.cpp_module_compile, |
| 616 | ], |
| 617 | flag_groups = [ |
| 618 | flag_group( |
| 619 | flags = ["-iquote", "%{quote_include_paths}"], |
| 620 | iterate_over = "quote_include_paths", |
| 621 | ), |
| 622 | flag_group( |
| 623 | flags = ["-I%{include_paths}"], |
| 624 | iterate_over = "include_paths", |
| 625 | ), |
| 626 | flag_group( |
| 627 | flags = ["-I", "%{system_include_paths}"], |
| 628 | iterate_over = "system_include_paths", |
| 629 | ), |
| 630 | ], |
| 631 | ), |
| 632 | ], |
| 633 | ) |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 634 | elif ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 635 | include_paths_feature = feature( |
| 636 | name = "include_paths", |
| 637 | enabled = True, |
| 638 | flag_sets = [ |
| 639 | flag_set( |
| 640 | actions = [ |
| 641 | ACTION_NAMES.preprocess_assemble, |
| 642 | ACTION_NAMES.c_compile, |
| 643 | ACTION_NAMES.cpp_compile, |
| 644 | ACTION_NAMES.cpp_header_parsing, |
| 645 | "c++-header-preprocessing", |
| 646 | ACTION_NAMES.cpp_module_compile, |
| 647 | ], |
| 648 | flag_groups = [ |
| 649 | flag_group( |
| 650 | flags = ["-iquote", "%{quote_include_paths}"], |
| 651 | iterate_over = "quote_include_paths", |
| 652 | ), |
| 653 | flag_group( |
| 654 | flags = ["-I%{include_paths}"], |
| 655 | iterate_over = "include_paths", |
| 656 | ), |
| 657 | flag_group( |
| 658 | flags = ["-isystem", "%{system_include_paths}"], |
| 659 | iterate_over = "system_include_paths", |
| 660 | ), |
| 661 | ], |
| 662 | ), |
| 663 | ], |
| 664 | ) |
| 665 | else: |
| 666 | include_paths_feature = None |
| 667 | |
| 668 | random_seed_feature = feature( |
| 669 | name = "random_seed", |
| 670 | enabled = True, |
| 671 | flag_sets = [ |
| 672 | flag_set( |
| 673 | actions = [ |
| 674 | ACTION_NAMES.cpp_compile, |
| 675 | ACTION_NAMES.cpp_module_codegen, |
| 676 | ACTION_NAMES.cpp_module_compile, |
| 677 | ], |
| 678 | flag_groups = [ |
| 679 | flag_group( |
| 680 | flags = ["-frandom-seed=%{output_file}"], |
| 681 | expand_if_available = "output_file", |
| 682 | ), |
| 683 | ], |
| 684 | ), |
| 685 | ], |
| 686 | ) |
| 687 | |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 688 | if ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 689 | default_link_flags_feature = feature( |
| 690 | name = "default_link_flags", |
| 691 | enabled = True, |
| 692 | flag_sets = [ |
| 693 | flag_set( |
| 694 | actions = all_link_actions, |
| 695 | flag_groups = [ |
| 696 | flag_group( |
| 697 | flags = [ |
| 698 | "-lstdc++", |
| 699 | "-Ltools/cpp/arm-frc-linux-gnueabi/libs", |
| 700 | "-no-canonical-prefixes", |
| 701 | "-Wl,-z,relro,-z,now", |
| 702 | "-lm", |
| 703 | "-pass-exit-codes", |
| 704 | "-Wl,--build-id=md5", |
| 705 | "-Wl,--hash-style=gnu", |
| 706 | ], |
| 707 | ), |
| 708 | ], |
| 709 | ), |
| 710 | ], |
| 711 | ) |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 712 | elif ctx.attr.cpu == "cortex-m4f-k22": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 713 | default_link_flags_feature = feature( |
| 714 | name = "default_link_flags", |
| 715 | enabled = True, |
| 716 | flag_sets = [ |
| 717 | flag_set( |
| 718 | actions = all_link_actions, |
| 719 | flag_groups = [ |
| 720 | flag_group( |
| 721 | flags = [ |
| 722 | "-no-canonical-prefixes", |
| 723 | "-mcpu=cortex-m4", |
| 724 | "-mfpu=fpv4-sp-d16", |
| 725 | "-mthumb", |
| 726 | "-mfloat-abi=hard", |
| 727 | "-fno-strict-aliasing", |
| 728 | "--specs=nano.specs", |
| 729 | "-lgcc", |
| 730 | "-lstdc++_nano", |
| 731 | "-lm", |
| 732 | "-lc_nano", |
| 733 | "-Tmotors/core/kinetis_512_128.ld", |
| 734 | "-Tmotors/core/kinetis_sections.ld", |
| 735 | ], |
| 736 | ), |
| 737 | ], |
| 738 | ), |
| 739 | flag_set( |
| 740 | actions = all_link_actions, |
| 741 | flag_groups = [flag_group(flags = ["-Wl,--gc-sections"])], |
| 742 | with_features = [with_feature_set(features = ["opt"])], |
| 743 | ), |
| 744 | ], |
| 745 | ) |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 746 | elif ctx.attr.cpu == "cortex-m4f": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 747 | default_link_flags_feature = feature( |
| 748 | name = "default_link_flags", |
| 749 | enabled = True, |
| 750 | flag_sets = [ |
| 751 | flag_set( |
| 752 | actions = all_link_actions, |
| 753 | flag_groups = [ |
| 754 | flag_group( |
| 755 | flags = [ |
| 756 | "-no-canonical-prefixes", |
| 757 | "-mcpu=cortex-m4", |
| 758 | "-mfpu=fpv4-sp-d16", |
| 759 | "-mthumb", |
| 760 | "-mfloat-abi=hard", |
| 761 | "-fno-strict-aliasing", |
| 762 | "--specs=nano.specs", |
| 763 | "-lgcc", |
| 764 | "-lstdc++_nano", |
| 765 | "-lm", |
| 766 | "-lc_nano", |
| 767 | "-Tmotors/core/kinetis_512_256.ld", |
| 768 | "-Tmotors/core/kinetis_sections.ld", |
| 769 | ], |
| 770 | ), |
| 771 | ], |
| 772 | ), |
| 773 | flag_set( |
| 774 | actions = all_link_actions, |
| 775 | flag_groups = [flag_group(flags = ["-Wl,--gc-sections"])], |
| 776 | with_features = [with_feature_set(features = ["opt"])], |
| 777 | ), |
| 778 | ], |
| 779 | ) |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 780 | elif ctx.attr.cpu == "rp2040": |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 781 | default_link_flags_feature = feature( |
| 782 | name = "default_link_flags", |
| 783 | enabled = True, |
| 784 | flag_sets = [ |
| 785 | flag_set( |
| 786 | actions = all_link_actions, |
| 787 | flag_groups = [ |
| 788 | flag_group( |
| 789 | flags = [ |
| 790 | "-no-canonical-prefixes", |
| 791 | "-mcpu=cortex-m0plus", |
| 792 | "-mthumb", |
| 793 | "-fno-strict-aliasing", |
| 794 | "-Wl,--build-id=none", |
| 795 | "--specs=nosys.specs", |
| 796 | "-nostartfiles", |
| 797 | ], |
| 798 | ), |
| 799 | ], |
| 800 | ), |
| 801 | # TODO(austin): I'd love to turn --gc-sections on, but that breaks things. |
| 802 | ], |
| 803 | ) |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 804 | else: |
| 805 | default_link_flags_feature = None |
| 806 | |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 807 | if ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 808 | all_modes_feature = feature( |
| 809 | name = "all_modes", |
| 810 | enabled = True, |
| 811 | flag_sets = [ |
| 812 | flag_set( |
| 813 | actions = [ |
| 814 | ACTION_NAMES.preprocess_assemble, |
| 815 | ACTION_NAMES.assemble, |
| 816 | ACTION_NAMES.c_compile, |
| 817 | ], |
| 818 | flag_groups = [flag_group(flags = ["-std=gnu99"])], |
| 819 | ), |
| 820 | flag_set( |
| 821 | actions = [ |
| 822 | ACTION_NAMES.cpp_compile, |
| 823 | ACTION_NAMES.cpp_header_parsing, |
| 824 | "c++-header-preprocessing", |
| 825 | ACTION_NAMES.cpp_module_compile, |
| 826 | ], |
| 827 | flag_groups = [ |
| 828 | flag_group( |
| 829 | flags = ["-std=gnu++1z", "-fno-sized-deallocation"], |
| 830 | ), |
| 831 | ], |
| 832 | ), |
| 833 | flag_set( |
| 834 | actions = [ |
| 835 | ACTION_NAMES.preprocess_assemble, |
| 836 | ACTION_NAMES.assemble, |
| 837 | "c++-link", |
| 838 | ACTION_NAMES.cpp_compile, |
| 839 | ACTION_NAMES.cpp_header_parsing, |
| 840 | "c++-header-preprocessing", |
| 841 | ACTION_NAMES.cpp_module_compile, |
| 842 | ACTION_NAMES.c_compile, |
| 843 | ], |
| 844 | flag_groups = [flag_group(flags = ["-pthread"])], |
| 845 | ), |
| 846 | ], |
| 847 | ) |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 848 | elif (ctx.attr.cpu == "rp2040" or |
| 849 | ctx.attr.cpu == "cortex-m4f" or |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 850 | ctx.attr.cpu == "cortex-m4f-k22"): |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 851 | all_modes_feature = feature( |
| 852 | name = "all_modes", |
| 853 | flag_sets = [ |
| 854 | flag_set( |
| 855 | actions = [ |
| 856 | ACTION_NAMES.preprocess_assemble, |
| 857 | ACTION_NAMES.assemble, |
| 858 | ACTION_NAMES.c_compile, |
| 859 | ], |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 860 | flag_groups = [flag_group(flags = ["--std=gnu11"])], |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 861 | ), |
| 862 | flag_set( |
| 863 | actions = [ |
| 864 | ACTION_NAMES.cpp_compile, |
| 865 | ACTION_NAMES.cpp_header_parsing, |
| 866 | "c++-header-preprocessing", |
| 867 | ACTION_NAMES.cpp_module_compile, |
| 868 | ], |
| 869 | flag_groups = [ |
| 870 | flag_group( |
| 871 | flags = ["--std=gnu++1z", "-fno-exceptions", "-fno-rtti"], |
| 872 | ), |
| 873 | ], |
| 874 | ), |
| 875 | ], |
| 876 | ) |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 877 | else: |
| 878 | all_modes_feature = None |
| 879 | |
| 880 | supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) |
| 881 | |
Brian Silverman | 4c7235a | 2021-11-17 19:04:37 -0800 | [diff] [blame] | 882 | if (ctx.attr.cpu == "rp2040" or |
| 883 | ctx.attr.cpu == "cortex-m4f" or |
| 884 | ctx.attr.cpu == "cortex-m4f-k22" or |
| 885 | ctx.attr.cpu == "roborio"): |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 886 | unfiltered_compile_flags_feature = feature( |
| 887 | name = "unfiltered_compile_flags", |
| 888 | enabled = True, |
| 889 | flag_sets = [ |
| 890 | flag_set( |
| 891 | actions = [ |
| 892 | ACTION_NAMES.assemble, |
| 893 | ACTION_NAMES.preprocess_assemble, |
| 894 | ACTION_NAMES.linkstamp_compile, |
| 895 | ACTION_NAMES.c_compile, |
| 896 | ACTION_NAMES.cpp_compile, |
| 897 | ACTION_NAMES.cpp_header_parsing, |
| 898 | ACTION_NAMES.cpp_module_compile, |
| 899 | ACTION_NAMES.cpp_module_codegen, |
| 900 | ACTION_NAMES.lto_backend, |
| 901 | ACTION_NAMES.clif_match, |
| 902 | ], |
| 903 | flag_groups = [ |
| 904 | flag_group( |
| 905 | flags = [ |
| 906 | "-no-canonical-prefixes", |
| 907 | "-Wno-builtin-macro-redefined", |
| 908 | "-D__DATE__=\"redacted\"", |
| 909 | "-D__TIMESTAMP__=\"redacted\"", |
| 910 | "-D__TIME__=\"redacted\"", |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 911 | ], |
| 912 | ), |
| 913 | ], |
| 914 | ), |
| 915 | ], |
| 916 | ) |
| 917 | else: |
| 918 | unfiltered_compile_flags_feature = None |
| 919 | |
| 920 | dependency_file_feature = feature( |
| 921 | name = "dependency_file", |
| 922 | enabled = True, |
| 923 | flag_sets = [ |
| 924 | flag_set( |
| 925 | actions = [ |
| 926 | ACTION_NAMES.assemble, |
| 927 | ACTION_NAMES.preprocess_assemble, |
| 928 | ACTION_NAMES.c_compile, |
| 929 | ACTION_NAMES.cpp_compile, |
| 930 | ACTION_NAMES.cpp_module_compile, |
| 931 | ACTION_NAMES.objc_compile, |
| 932 | ACTION_NAMES.objcpp_compile, |
| 933 | ACTION_NAMES.cpp_header_parsing, |
| 934 | ACTION_NAMES.clif_match, |
| 935 | ], |
| 936 | flag_groups = [ |
| 937 | flag_group( |
| 938 | flags = ["-MD", "-MF", "%{dependency_file}"], |
| 939 | expand_if_available = "dependency_file", |
| 940 | ), |
| 941 | ], |
| 942 | ), |
| 943 | ], |
| 944 | ) |
| 945 | |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 946 | user_compile_flags_feature = feature( |
| 947 | name = "user_compile_flags", |
| 948 | enabled = True, |
| 949 | flag_sets = [ |
| 950 | flag_set( |
| 951 | actions = [ |
| 952 | ACTION_NAMES.assemble, |
| 953 | ACTION_NAMES.preprocess_assemble, |
| 954 | ACTION_NAMES.linkstamp_compile, |
| 955 | ACTION_NAMES.c_compile, |
| 956 | ACTION_NAMES.cpp_compile, |
| 957 | ACTION_NAMES.cpp_header_parsing, |
| 958 | ACTION_NAMES.cpp_module_compile, |
| 959 | ACTION_NAMES.cpp_module_codegen, |
| 960 | ACTION_NAMES.lto_backend, |
| 961 | ACTION_NAMES.clif_match, |
| 962 | ], |
| 963 | flag_groups = [ |
| 964 | flag_group( |
| 965 | flags = ["%{user_compile_flags}"], |
| 966 | iterate_over = "user_compile_flags", |
| 967 | expand_if_available = "user_compile_flags", |
| 968 | ), |
| 969 | ], |
| 970 | ), |
| 971 | ], |
| 972 | ) |
| 973 | |
| 974 | sysroot_feature = feature( |
| 975 | name = "sysroot", |
| 976 | enabled = True, |
| 977 | flag_sets = [ |
| 978 | flag_set( |
| 979 | actions = [ |
| 980 | ACTION_NAMES.preprocess_assemble, |
| 981 | ACTION_NAMES.linkstamp_compile, |
| 982 | ACTION_NAMES.c_compile, |
| 983 | ACTION_NAMES.cpp_compile, |
| 984 | ACTION_NAMES.cpp_header_parsing, |
| 985 | ACTION_NAMES.cpp_module_compile, |
| 986 | ACTION_NAMES.cpp_module_codegen, |
| 987 | ACTION_NAMES.lto_backend, |
| 988 | ACTION_NAMES.clif_match, |
| 989 | ACTION_NAMES.cpp_link_executable, |
| 990 | ACTION_NAMES.cpp_link_dynamic_library, |
| 991 | ACTION_NAMES.cpp_link_nodeps_dynamic_library, |
| 992 | ], |
| 993 | flag_groups = [ |
| 994 | flag_group( |
| 995 | flags = ["--sysroot=%{sysroot}"], |
| 996 | expand_if_available = "sysroot", |
| 997 | ), |
| 998 | ], |
| 999 | ), |
| 1000 | ], |
| 1001 | ) |
| 1002 | |
| 1003 | compile_flags1_feature = feature( |
| 1004 | name = "compile_flags1", |
| 1005 | enabled = True, |
| 1006 | flag_sets = [ |
| 1007 | flag_set( |
| 1008 | actions = [ |
| 1009 | ACTION_NAMES.assemble, |
| 1010 | ACTION_NAMES.preprocess_assemble, |
| 1011 | ACTION_NAMES.c_compile, |
| 1012 | ACTION_NAMES.cpp_compile, |
| 1013 | ACTION_NAMES.cpp_header_parsing, |
| 1014 | ACTION_NAMES.cpp_module_compile, |
| 1015 | ACTION_NAMES.cpp_module_codegen, |
| 1016 | ACTION_NAMES.lto_backend, |
| 1017 | ACTION_NAMES.clif_match, |
| 1018 | ], |
| 1019 | flag_groups = [ |
| 1020 | flag_group( |
| 1021 | flags = [ |
| 1022 | "--sysroot=external/arm_frc_linux_gnueabi_repo/arm-frc2020-linux-gnueabi", |
| 1023 | "-nostdinc", |
| 1024 | "-isystem", |
| 1025 | "external/arm_frc_linux_gnueabi_repo/arm-frc2020-linux-gnueabi/usr/lib/gcc/arm-frc2020-linux-gnueabi/7.3.0/include", |
| 1026 | "-isystem", |
| 1027 | "external/arm_frc_linux_gnueabi_repo/arm-frc2020-linux-gnueabi/usr/lib/gcc/arm-frc2020-linux-gnueabi/7.3.0/include-fixed", |
| 1028 | ], |
| 1029 | ), |
| 1030 | ], |
| 1031 | ), |
| 1032 | flag_set( |
| 1033 | actions = [ |
| 1034 | ACTION_NAMES.assemble, |
| 1035 | ACTION_NAMES.preprocess_assemble, |
| 1036 | ACTION_NAMES.cpp_compile, |
| 1037 | ACTION_NAMES.cpp_header_parsing, |
| 1038 | "c++-header-preprocessing", |
| 1039 | ], |
| 1040 | flag_groups = [flag_group(flags = ["-fno-canonical-system-headers"])], |
| 1041 | ), |
| 1042 | flag_set( |
| 1043 | actions = [ |
| 1044 | ACTION_NAMES.cpp_compile, |
| 1045 | ACTION_NAMES.cpp_header_parsing, |
| 1046 | ACTION_NAMES.cpp_module_compile, |
| 1047 | ACTION_NAMES.cpp_module_codegen, |
| 1048 | ], |
| 1049 | flag_groups = [ |
| 1050 | flag_group( |
| 1051 | flags = [ |
| 1052 | "-isystem", |
| 1053 | "external/arm_frc_linux_gnueabi_repo/arm-frc2020-linux-gnueabi/usr/include/c++/7.3.0", |
| 1054 | "-isystem", |
| 1055 | "external/arm_frc_linux_gnueabi_repo/arm-frc2020-linux-gnueabi/usr/include/c++/7.3.0/arm-frc2020-linux-gnueabi", |
| 1056 | "-isystem", |
| 1057 | "external/arm_frc_linux_gnueabi_repo/arm-frc2020-linux-gnueabi/usr/include/c++/7.3.0/backward", |
| 1058 | ], |
| 1059 | ), |
| 1060 | ], |
| 1061 | ), |
| 1062 | flag_set( |
| 1063 | actions = [ |
| 1064 | ACTION_NAMES.assemble, |
| 1065 | ACTION_NAMES.preprocess_assemble, |
| 1066 | ACTION_NAMES.c_compile, |
| 1067 | ACTION_NAMES.cpp_compile, |
| 1068 | ACTION_NAMES.cpp_header_parsing, |
| 1069 | ACTION_NAMES.cpp_module_compile, |
| 1070 | ACTION_NAMES.cpp_module_codegen, |
| 1071 | ACTION_NAMES.lto_backend, |
| 1072 | ACTION_NAMES.clif_match, |
| 1073 | ], |
| 1074 | flag_groups = [ |
| 1075 | flag_group( |
| 1076 | flags = [ |
| 1077 | "-isystem", |
| 1078 | "external/arm_frc_linux_gnueabi_repo/arm-frc2020-linux-gnueabi/usr/include", |
| 1079 | "-mfpu=neon", |
| 1080 | "-D__STDC_FORMAT_MACROS", |
| 1081 | "-D__STDC_CONSTANT_MACROS", |
| 1082 | "-D__STDC_LIMIT_MACROS", |
| 1083 | "-D_FILE_OFFSET_BITS=64", |
| 1084 | "-DAOS_ARCHITECTURE_arm_frc", |
| 1085 | "-U_FORTIFY_SOURCE", |
| 1086 | "-fstack-protector", |
| 1087 | "-fPIE", |
| 1088 | "-fdiagnostics-color=always", |
| 1089 | "-Wall", |
| 1090 | "-Wextra", |
| 1091 | "-Wpointer-arith", |
| 1092 | "-Wstrict-aliasing", |
| 1093 | "-Wcast-qual", |
| 1094 | "-Wwrite-strings", |
| 1095 | "-Wtype-limits", |
| 1096 | "-Wsign-compare", |
| 1097 | "-Wformat=2", |
| 1098 | "-Werror", |
| 1099 | "-Wunused-local-typedefs", |
| 1100 | "-Wno-psabi", |
| 1101 | "-fno-omit-frame-pointer", |
| 1102 | "-D__has_feature(x)=0", |
| 1103 | "-pipe", |
| 1104 | "-ggdb3", |
| 1105 | ], |
| 1106 | ), |
| 1107 | ], |
| 1108 | ), |
| 1109 | ], |
| 1110 | ) |
| 1111 | |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 1112 | if (ctx.attr.cpu == "rp2040" or |
| 1113 | ctx.attr.cpu == "cortex-m4f" or |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 1114 | ctx.attr.cpu == "cortex-m4f-k22"): |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1115 | features = [ |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 1116 | default_compile_flags_feature, |
| 1117 | default_link_flags_feature, |
| 1118 | dbg_feature, |
| 1119 | opt_feature, |
| 1120 | fastbuild_feature, |
| 1121 | all_modes_feature, |
| 1122 | include_paths_feature, |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 1123 | user_compile_flags_feature, |
| 1124 | sysroot_feature, |
| 1125 | unfiltered_compile_flags_feature, |
| 1126 | ] |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 1127 | elif ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1128 | features = [ |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 1129 | default_link_flags_feature, |
| 1130 | compile_flags1_feature, |
| 1131 | opt_feature, |
| 1132 | dependency_file_feature, |
| 1133 | random_seed_feature, |
| 1134 | pic_feature, |
| 1135 | include_paths_feature, |
| 1136 | opt_post_feature, |
| 1137 | dbg_feature, |
| 1138 | fastbuild_feature, |
| 1139 | all_modes_feature, |
| 1140 | pie_for_linking_feature, |
| 1141 | supports_dynamic_linker_feature, |
| 1142 | supports_pic_feature, |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 1143 | user_compile_flags_feature, |
| 1144 | sysroot_feature, |
| 1145 | unfiltered_compile_flags_feature, |
| 1146 | ] |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1147 | else: |
| 1148 | fail("Unreachable") |
| 1149 | |
Brian Silverman | 33ca369 | 2022-02-06 18:37:17 -0800 | [diff] [blame] | 1150 | if ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1151 | cxx_builtin_include_directories = [ |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 1152 | "%package(@arm_frc_linux_gnueabi_repo//arm-frc2020-linux-gnueabi/usr/lib/gcc/arm-frc2020-linux-gnueabi/7.3.0/include)%", |
| 1153 | "%package(@arm_frc_linux_gnueabi_repo//arm-frc2020-linux-gnueabi/usr/lib/gcc/arm-frc2020-linux-gnueabi/7.3.0/include-fixed)%", |
| 1154 | "%package(@arm_frc_linux_gnueabi_repo//arm-frc2020-linux-gnueabi/usr/include/c++/7.3.0/arm-frc2020-linux-gnueabi)%", |
| 1155 | "%package(@arm_frc_linux_gnueabi_repo//arm-frc2020-linux-gnueabi/usr/include/c++/7.3.0/backward)%", |
| 1156 | ] |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 1157 | elif (ctx.attr.cpu == "rp2040" or |
| 1158 | ctx.attr.cpu == "cortex-m4f" or |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 1159 | ctx.attr.cpu == "cortex-m4f-k22"): |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1160 | cxx_builtin_include_directories = [ |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 1161 | "/usr/lib/gcc/arm-none-eabi/4.8/include", |
| 1162 | "/usr/lib/gcc/arm-none-eabi/4.8/include-fixed", |
| 1163 | "/usr/lib/arm-none-eabi/include", |
| 1164 | "/usr/include/newlib", |
| 1165 | ] |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1166 | else: |
| 1167 | fail("Unreachable") |
| 1168 | |
| 1169 | artifact_name_patterns = [] |
| 1170 | |
| 1171 | make_variables = [] |
| 1172 | |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 1173 | if ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1174 | tool_paths = [ |
| 1175 | tool_path( |
| 1176 | name = "ar", |
| 1177 | path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-ar", |
| 1178 | ), |
| 1179 | tool_path( |
| 1180 | name = "as", |
| 1181 | path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-as", |
| 1182 | ), |
| 1183 | tool_path( |
| 1184 | name = "compat-ld", |
| 1185 | path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-ld", |
| 1186 | ), |
| 1187 | tool_path( |
| 1188 | name = "cpp", |
| 1189 | path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-cpp", |
| 1190 | ), |
| 1191 | tool_path(name = "dwp", path = "/bin/false"), |
| 1192 | tool_path( |
| 1193 | name = "gcc", |
| 1194 | path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-gcc", |
| 1195 | ), |
| 1196 | tool_path( |
| 1197 | name = "gcov", |
| 1198 | path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-gcov-4.9", |
| 1199 | ), |
| 1200 | tool_path( |
| 1201 | name = "ld", |
| 1202 | path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-ld", |
| 1203 | ), |
| 1204 | tool_path( |
| 1205 | name = "nm", |
| 1206 | path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-nm", |
| 1207 | ), |
| 1208 | tool_path( |
| 1209 | name = "objcopy", |
| 1210 | path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-objcopy", |
| 1211 | ), |
| 1212 | tool_path( |
| 1213 | name = "objdump", |
| 1214 | path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-objdump", |
| 1215 | ), |
| 1216 | tool_path( |
| 1217 | name = "strip", |
| 1218 | path = "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-strip", |
| 1219 | ), |
| 1220 | ] |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 1221 | elif (ctx.attr.cpu == "rp2040" or |
| 1222 | ctx.attr.cpu == "cortex-m4f" or |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 1223 | ctx.attr.cpu == "cortex-m4f-k22"): |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1224 | tool_paths = [ |
| 1225 | tool_path( |
| 1226 | name = "ar", |
| 1227 | path = "gcc_arm_none_eabi/arm-none-eabi-ar", |
| 1228 | ), |
| 1229 | tool_path( |
| 1230 | name = "compat-ld", |
| 1231 | path = "gcc_arm_none_eabi/arm-none-eabi-ld", |
| 1232 | ), |
| 1233 | tool_path( |
| 1234 | name = "cpp", |
| 1235 | path = "gcc_arm_none_eabi/arm-none-eabi-cpp", |
| 1236 | ), |
| 1237 | tool_path( |
| 1238 | name = "dwp", |
| 1239 | path = "gcc_arm_none_eabi/arm-none-eabi-dwp", |
| 1240 | ), |
| 1241 | tool_path( |
| 1242 | name = "gcc", |
| 1243 | path = "gcc_arm_none_eabi/arm-none-eabi-gcc", |
| 1244 | ), |
| 1245 | tool_path( |
| 1246 | name = "gcov", |
| 1247 | path = "gcc_arm_none_eabi/arm-none-eabi-gcov", |
| 1248 | ), |
| 1249 | tool_path( |
| 1250 | name = "ld", |
| 1251 | path = "gcc_arm_none_eabi/arm-none-eabi-ld", |
| 1252 | ), |
| 1253 | tool_path( |
| 1254 | name = "nm", |
| 1255 | path = "gcc_arm_none_eabi/arm-none-eabi-nm", |
| 1256 | ), |
| 1257 | tool_path( |
| 1258 | name = "objcopy", |
| 1259 | path = "gcc_arm_none_eabi/arm-none-eabi-objcopy", |
| 1260 | ), |
| 1261 | tool_path( |
| 1262 | name = "objdump", |
| 1263 | path = "gcc_arm_none_eabi/arm-none-eabi-objdump", |
| 1264 | ), |
| 1265 | tool_path( |
| 1266 | name = "strip", |
| 1267 | path = "gcc_arm_none_eabi/arm-none-eabi-strip", |
| 1268 | ), |
| 1269 | ] |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1270 | else: |
| 1271 | fail("Unreachable") |
| 1272 | |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1273 | out = ctx.actions.declare_file(ctx.label.name) |
| 1274 | ctx.actions.write(out, "Fake executable") |
| 1275 | return [ |
| 1276 | cc_common.create_cc_toolchain_config_info( |
| 1277 | ctx = ctx, |
| 1278 | features = features, |
| 1279 | action_configs = action_configs, |
| 1280 | artifact_name_patterns = artifact_name_patterns, |
| 1281 | cxx_builtin_include_directories = cxx_builtin_include_directories, |
| 1282 | toolchain_identifier = toolchain_identifier, |
| 1283 | host_system_name = host_system_name, |
| 1284 | target_system_name = target_system_name, |
| 1285 | target_cpu = target_cpu, |
| 1286 | target_libc = target_libc, |
| 1287 | compiler = compiler, |
| 1288 | abi_version = abi_version, |
| 1289 | abi_libc_version = abi_libc_version, |
| 1290 | tool_paths = tool_paths, |
| 1291 | make_variables = make_variables, |
| 1292 | builtin_sysroot = builtin_sysroot, |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 1293 | cc_target_os = cc_target_os, |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1294 | ), |
| 1295 | DefaultInfo( |
| 1296 | executable = out, |
| 1297 | ), |
| 1298 | ] |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 1299 | |
| 1300 | cc_toolchain_config = rule( |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1301 | implementation = _impl, |
| 1302 | attrs = { |
Brian Silverman | 33ca369 | 2022-02-06 18:37:17 -0800 | [diff] [blame] | 1303 | "cpu": attr.string(mandatory = True, values = ["cortex-m4f", "cortex-m4f-k22", "roborio", "rp2040"]), |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1304 | }, |
| 1305 | provides = [CcToolchainConfigInfo], |
| 1306 | executable = True, |
| 1307 | ) |