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" |
James Kuszmaul | 5a72856 | 2023-12-28 21:45:01 -0800 | [diff] [blame] | 16 | elif ctx.attr.cpu == "cortex-m4f-imu": |
| 17 | toolchain_identifier = "cortex-m4f-imu" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 18 | elif ctx.attr.cpu == "cortex-m4f": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 19 | toolchain_identifier = "cortex-m4f" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 20 | elif ctx.attr.cpu == "cortex-m4f-k22": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 21 | toolchain_identifier = "cortex-m4f-k22" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 22 | elif ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 23 | toolchain_identifier = "roborio_linux" |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 24 | else: |
| 25 | fail("Unreachable") |
| 26 | |
Brian Silverman | 33ca369 | 2022-02-06 18:37:17 -0800 | [diff] [blame] | 27 | if (ctx.attr.cpu == "rp2040" or |
James Kuszmaul | 5a72856 | 2023-12-28 21:45:01 -0800 | [diff] [blame] | 28 | ctx.attr.cpu == "cortex-m4f-imu" or |
Brian Silverman | 33ca369 | 2022-02-06 18:37:17 -0800 | [diff] [blame] | 29 | ctx.attr.cpu == "cortex-m4f" or |
| 30 | ctx.attr.cpu == "cortex-m4f-k22"): |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 31 | host_system_name = "local" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 32 | elif ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 33 | host_system_name = "roborio" |
| 34 | else: |
| 35 | fail("Unreachable") |
| 36 | |
Brian Silverman | 33ca369 | 2022-02-06 18:37:17 -0800 | [diff] [blame] | 37 | if ctx.attr.cpu == "rp2040": |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 38 | target_system_name = "rp2040" |
James Kuszmaul | 5a72856 | 2023-12-28 21:45:01 -0800 | [diff] [blame] | 39 | elif ctx.attr.cpu == "cortex-m4f-imu": |
| 40 | target_system_name = "cortex-m4f-imu" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 41 | elif ctx.attr.cpu == "cortex-m4f": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 42 | target_system_name = "cortex-m4f" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 43 | elif ctx.attr.cpu == "cortex-m4f-k22": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 44 | target_system_name = "cortex-m4f-k22" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 45 | elif ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 46 | target_system_name = "roborio" |
| 47 | else: |
| 48 | fail("Unreachable") |
| 49 | |
Brian Silverman | 33ca369 | 2022-02-06 18:37:17 -0800 | [diff] [blame] | 50 | if ctx.attr.cpu == "rp2040": |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 51 | target_cpu = "rp2040" |
James Kuszmaul | 5a72856 | 2023-12-28 21:45:01 -0800 | [diff] [blame] | 52 | elif ctx.attr.cpu == "cortex-m4f-imu": |
| 53 | target_cpu = "cortex-m4f-imu" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 54 | elif ctx.attr.cpu == "cortex-m4f": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 55 | target_cpu = "cortex-m4f" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 56 | elif ctx.attr.cpu == "cortex-m4f-k22": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 57 | target_cpu = "cortex-m4f-k22" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 58 | elif ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 59 | target_cpu = "roborio" |
| 60 | else: |
| 61 | fail("Unreachable") |
| 62 | |
Brian Silverman | 33ca369 | 2022-02-06 18:37:17 -0800 | [diff] [blame] | 63 | if ctx.attr.cpu == "rp2040": |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 64 | target_libc = "rp2040" |
James Kuszmaul | 5a72856 | 2023-12-28 21:45:01 -0800 | [diff] [blame] | 65 | elif ctx.attr.cpu == "cortex-m4f-imu": |
| 66 | target_libc = "cortex-m4f-imu" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 67 | elif ctx.attr.cpu == "cortex-m4f": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 68 | target_libc = "cortex-m4f" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 69 | elif ctx.attr.cpu == "cortex-m4f-k22": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 70 | target_libc = "cortex-m4f-k22" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 71 | elif ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 72 | target_libc = "roborio" |
| 73 | else: |
| 74 | fail("Unreachable") |
| 75 | |
Brian Silverman | 33ca369 | 2022-02-06 18:37:17 -0800 | [diff] [blame] | 76 | if (ctx.attr.cpu == "rp2040" or |
James Kuszmaul | 5a72856 | 2023-12-28 21:45:01 -0800 | [diff] [blame] | 77 | ctx.attr.cpu == "cortex-m4f-imu" or |
Brian Silverman | 33ca369 | 2022-02-06 18:37:17 -0800 | [diff] [blame] | 78 | ctx.attr.cpu == "cortex-m4f" or |
| 79 | ctx.attr.cpu == "cortex-m4f-k22" or |
| 80 | ctx.attr.cpu == "roborio"): |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 81 | compiler = "gcc" |
| 82 | else: |
| 83 | fail("Unreachable") |
| 84 | |
Brian Silverman | 33ca369 | 2022-02-06 18:37:17 -0800 | [diff] [blame] | 85 | if ctx.attr.cpu == "rp2040": |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 86 | abi_version = "rp2040" |
James Kuszmaul | 5a72856 | 2023-12-28 21:45:01 -0800 | [diff] [blame] | 87 | elif ctx.attr.cpu == "cortex-m4f-imu": |
| 88 | abi_version = "cortex-m4f-imu" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 89 | elif ctx.attr.cpu == "cortex-m4f": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 90 | abi_version = "cortex-m4f" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 91 | elif ctx.attr.cpu == "cortex-m4f-k22": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 92 | abi_version = "cortex-m4f-k22" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 93 | elif ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 94 | abi_version = "roborio" |
| 95 | else: |
| 96 | fail("Unreachable") |
| 97 | |
Brian Silverman | 33ca369 | 2022-02-06 18:37:17 -0800 | [diff] [blame] | 98 | if ctx.attr.cpu == "rp2040": |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 99 | abi_libc_version = "rp2040" |
James Kuszmaul | 5a72856 | 2023-12-28 21:45:01 -0800 | [diff] [blame] | 100 | elif ctx.attr.cpu == "cortex-m4f-imu": |
| 101 | abi_libc_version = "cortex-m4f-imu" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 102 | elif ctx.attr.cpu == "cortex-m4f": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 103 | abi_libc_version = "cortex-m4f" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 104 | elif ctx.attr.cpu == "cortex-m4f-k22": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 105 | abi_libc_version = "cortex-m4f-k22" |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 106 | elif ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 107 | abi_libc_version = "roborio" |
| 108 | else: |
| 109 | fail("Unreachable") |
| 110 | |
| 111 | cc_target_os = None |
| 112 | |
| 113 | builtin_sysroot = None |
| 114 | |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 115 | 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 Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 124 | 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 Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 130 | if ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 131 | 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 Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 140 | elif (ctx.attr.cpu == "rp2040" or |
James Kuszmaul | 5a72856 | 2023-12-28 21:45:01 -0800 | [diff] [blame] | 141 | ctx.attr.cpu == "cortex-m4f-imu" or |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 142 | ctx.attr.cpu == "cortex-m4f" or |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 143 | ctx.attr.cpu == "cortex-m4f-k22"): |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 144 | 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 Silverman | 33ca369 | 2022-02-06 18:37:17 -0800 | [diff] [blame] | 152 | if (ctx.attr.cpu == "rp2040" or |
James Kuszmaul | 5a72856 | 2023-12-28 21:45:01 -0800 | [diff] [blame] | 153 | ctx.attr.cpu == "cortex-m4f-imu" or |
Brian Silverman | 33ca369 | 2022-02-06 18:37:17 -0800 | [diff] [blame] | 154 | ctx.attr.cpu == "cortex-m4f" or |
| 155 | ctx.attr.cpu == "cortex-m4f-k22" or |
| 156 | ctx.attr.cpu == "roborio"): |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 157 | 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 Silverman | 7b53ae1 | 2022-05-22 21:40:57 -0700 | [diff] [blame] | 165 | actions = all_cpp_compile_actions + [ |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 166 | ACTION_NAMES.preprocess_assemble, |
| 167 | ACTION_NAMES.c_compile, |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 168 | ], |
| 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 Silverman | 4c7235a | 2021-11-17 19:04:37 -0800 | [diff] [blame] | 176 | if ctx.attr.cpu == "cortex-m4f-k22": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 177 | 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 Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 263 | elif ctx.attr.cpu == "cortex-m4f": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 264 | 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 Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 315 | "-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 Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 349 | elif ctx.attr.cpu == "rp2040": |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 350 | 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 Kuszmaul | 5a72856 | 2023-12-28 21:45:01 -0800 | [diff] [blame] | 431 | 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 Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 516 | else: |
| 517 | default_compile_flags_feature = None |
| 518 | |
Brian Silverman | 4c7235a | 2021-11-17 19:04:37 -0800 | [diff] [blame] | 519 | if ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 520 | dbg_feature = feature( |
| 521 | name = "dbg", |
| 522 | flag_sets = [ |
| 523 | flag_set( |
Brian Silverman | 7b53ae1 | 2022-05-22 21:40:57 -0700 | [diff] [blame] | 524 | actions = all_cpp_compile_actions + [ |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 525 | ACTION_NAMES.preprocess_assemble, |
| 526 | ACTION_NAMES.c_compile, |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 527 | ], |
| 528 | flag_groups = [ |
| 529 | flag_group(flags = ["-DAOS_DEBUG=1"]), |
| 530 | flag_group(flags = ["-fno-omit-frame-pointer"]), |
| 531 | ], |
| 532 | ), |
| 533 | ], |
| 534 | ) |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 535 | elif (ctx.attr.cpu == "rp2040" or |
James Kuszmaul | 5a72856 | 2023-12-28 21:45:01 -0800 | [diff] [blame] | 536 | ctx.attr.cpu == "cortex-m4f-imu" or |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 537 | ctx.attr.cpu == "cortex-m4f" or |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 538 | ctx.attr.cpu == "cortex-m4f-k22"): |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 539 | dbg_feature = feature( |
| 540 | name = "dbg", |
| 541 | flag_sets = [ |
| 542 | flag_set( |
Brian Silverman | 7b53ae1 | 2022-05-22 21:40:57 -0700 | [diff] [blame] | 543 | actions = all_cpp_compile_actions + [ |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 544 | ACTION_NAMES.preprocess_assemble, |
| 545 | ACTION_NAMES.c_compile, |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 546 | ], |
| 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 Silverman | 4c7235a | 2021-11-17 19:04:37 -0800 | [diff] [blame] | 555 | if ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 556 | fastbuild_feature = feature( |
| 557 | name = "fastbuild", |
| 558 | flag_sets = [ |
| 559 | flag_set( |
Brian Silverman | 7b53ae1 | 2022-05-22 21:40:57 -0700 | [diff] [blame] | 560 | actions = all_cpp_compile_actions + [ |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 561 | ACTION_NAMES.preprocess_assemble, |
| 562 | ACTION_NAMES.c_compile, |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 563 | ], |
| 564 | flag_groups = [flag_group(flags = ["-DAOS_DEBUG=0"])], |
| 565 | ), |
| 566 | ], |
| 567 | ) |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 568 | elif (ctx.attr.cpu == "rp2040" or |
James Kuszmaul | 5a72856 | 2023-12-28 21:45:01 -0800 | [diff] [blame] | 569 | ctx.attr.cpu == "cortex-m4f-imu" or |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 570 | ctx.attr.cpu == "cortex-m4f" or |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 571 | ctx.attr.cpu == "cortex-m4f-k22"): |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 572 | 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 Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 587 | if ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 588 | 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 Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 626 | elif (ctx.attr.cpu == "rp2040" or |
James Kuszmaul | 5a72856 | 2023-12-28 21:45:01 -0800 | [diff] [blame] | 627 | ctx.attr.cpu == "cortex-m4f-imu" or |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 628 | ctx.attr.cpu == "cortex-m4f" or |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 629 | ctx.attr.cpu == "cortex-m4f-k22"): |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 630 | 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 Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 655 | if (ctx.attr.cpu == "rp2040" or |
James Kuszmaul | 5a72856 | 2023-12-28 21:45:01 -0800 | [diff] [blame] | 656 | ctx.attr.cpu == "cortex-m4f-imu" or |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 657 | ctx.attr.cpu == "cortex-m4f" or |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 658 | ctx.attr.cpu == "cortex-m4f-k22"): |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 659 | include_paths_feature = feature( |
| 660 | name = "include_paths", |
| 661 | enabled = True, |
| 662 | flag_sets = [ |
| 663 | flag_set( |
Brian Silverman | 7b53ae1 | 2022-05-22 21:40:57 -0700 | [diff] [blame] | 664 | actions = all_cpp_compile_actions + [ |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 665 | ACTION_NAMES.preprocess_assemble, |
| 666 | ACTION_NAMES.c_compile, |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 667 | ], |
| 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 Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 685 | elif ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 686 | include_paths_feature = feature( |
| 687 | name = "include_paths", |
| 688 | enabled = True, |
| 689 | flag_sets = [ |
| 690 | flag_set( |
Brian Silverman | 7b53ae1 | 2022-05-22 21:40:57 -0700 | [diff] [blame] | 691 | actions = all_cpp_compile_actions + [ |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 692 | ACTION_NAMES.preprocess_assemble, |
| 693 | ACTION_NAMES.c_compile, |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 694 | ], |
| 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 Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 735 | if ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 736 | 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 Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 759 | elif ctx.attr.cpu == "cortex-m4f-k22": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 760 | 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 Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 793 | elif ctx.attr.cpu == "cortex-m4f": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 794 | 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 Kuszmaul | 5a72856 | 2023-12-28 21:45:01 -0800 | [diff] [blame] | 827 | 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 Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 864 | elif ctx.attr.cpu == "rp2040": |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 865 | 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 Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 888 | else: |
James Kuszmaul | 5a72856 | 2023-12-28 21:45:01 -0800 | [diff] [blame] | 889 | fail("Unreachable") |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 890 | |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 891 | if ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 892 | 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 Silverman | 7b53ae1 | 2022-05-22 21:40:57 -0700 | [diff] [blame] | 905 | actions = all_cpp_compile_actions, |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 906 | flag_groups = [ |
| 907 | flag_group( |
James Kuszmaul | 9776b39 | 2023-01-14 14:08:08 -0800 | [diff] [blame] | 908 | flags = ["-std=gnu++20", "-fno-sized-deallocation"], |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 909 | ), |
| 910 | ], |
| 911 | ), |
| 912 | flag_set( |
Brian Silverman | 7b53ae1 | 2022-05-22 21:40:57 -0700 | [diff] [blame] | 913 | actions = all_cpp_compile_actions + [ |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 914 | ACTION_NAMES.preprocess_assemble, |
| 915 | ACTION_NAMES.assemble, |
| 916 | "c++-link", |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 917 | ACTION_NAMES.c_compile, |
| 918 | ], |
| 919 | flag_groups = [flag_group(flags = ["-pthread"])], |
| 920 | ), |
| 921 | ], |
| 922 | ) |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 923 | elif (ctx.attr.cpu == "rp2040" or |
James Kuszmaul | 5a72856 | 2023-12-28 21:45:01 -0800 | [diff] [blame] | 924 | ctx.attr.cpu == "cortex-m4f-imu" or |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 925 | ctx.attr.cpu == "cortex-m4f" or |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 926 | ctx.attr.cpu == "cortex-m4f-k22"): |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 927 | 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 Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 936 | flag_groups = [flag_group(flags = ["--std=gnu11"])], |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 937 | ), |
| 938 | flag_set( |
Brian Silverman | 7b53ae1 | 2022-05-22 21:40:57 -0700 | [diff] [blame] | 939 | actions = all_cpp_compile_actions, |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 940 | flag_groups = [ |
| 941 | flag_group( |
James Kuszmaul | ef420da | 2023-12-27 12:02:15 -0800 | [diff] [blame] | 942 | flags = ["--std=gnu++20", "-fno-exceptions", "-fno-rtti"], |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 943 | ), |
| 944 | ], |
| 945 | ), |
| 946 | ], |
| 947 | ) |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 948 | else: |
| 949 | all_modes_feature = None |
| 950 | |
| 951 | supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) |
| 952 | |
Brian Silverman | 4c7235a | 2021-11-17 19:04:37 -0800 | [diff] [blame] | 953 | if (ctx.attr.cpu == "rp2040" or |
James Kuszmaul | 5a72856 | 2023-12-28 21:45:01 -0800 | [diff] [blame] | 954 | ctx.attr.cpu == "cortex-m4f-imu" or |
Brian Silverman | 4c7235a | 2021-11-17 19:04:37 -0800 | [diff] [blame] | 955 | ctx.attr.cpu == "cortex-m4f" or |
| 956 | ctx.attr.cpu == "cortex-m4f-k22" or |
| 957 | ctx.attr.cpu == "roborio"): |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 958 | 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 Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 983 | ], |
| 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 Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1018 | 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 Kuszmaul | 9776b39 | 2023-01-14 14:08:08 -0800 | [diff] [blame] | 1094 | "--sysroot=external/arm_frc_linux_gnueabi_repo/arm-nilrt-linux-gnueabi/sysroot", |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1095 | "-nostdinc", |
| 1096 | "-isystem", |
James Kuszmaul | 9776b39 | 2023-01-14 14:08:08 -0800 | [diff] [blame] | 1097 | "external/arm_frc_linux_gnueabi_repo/arm-nilrt-linux-gnueabi/sysroot/usr/lib/gcc/arm-nilrt-linux-gnueabi/12/include", |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1098 | "-isystem", |
James Kuszmaul | 9776b39 | 2023-01-14 14:08:08 -0800 | [diff] [blame] | 1099 | "external/arm_frc_linux_gnueabi_repo/arm-nilrt-linux-gnueabi/sysroot/usr/lib/gcc/arm-nilrt-linux-gnueabi/12/include-fixed", |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1100 | ], |
| 1101 | ), |
| 1102 | ], |
| 1103 | ), |
| 1104 | flag_set( |
Brian Silverman | 7b53ae1 | 2022-05-22 21:40:57 -0700 | [diff] [blame] | 1105 | actions = all_cpp_compile_actions + [ |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1106 | ACTION_NAMES.assemble, |
| 1107 | ACTION_NAMES.preprocess_assemble, |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1108 | ], |
| 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 Kuszmaul | 9776b39 | 2023-01-14 14:08:08 -0800 | [diff] [blame] | 1122 | "external/arm_frc_linux_gnueabi_repo/arm-nilrt-linux-gnueabi/sysroot/usr/include/c++/12", |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1123 | "-isystem", |
James Kuszmaul | 9776b39 | 2023-01-14 14:08:08 -0800 | [diff] [blame] | 1124 | "external/arm_frc_linux_gnueabi_repo/arm-nilrt-linux-gnueabi/sysroot/usr/include/c++/12/arm-nilrt-linux-gnueabi", |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1125 | "-isystem", |
James Kuszmaul | 9776b39 | 2023-01-14 14:08:08 -0800 | [diff] [blame] | 1126 | "external/arm_frc_linux_gnueabi_repo/arm-nilrt-linux-gnueabi/sysroot/usr/include/c++/12/backward", |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1127 | ], |
| 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 Kuszmaul | 9776b39 | 2023-01-14 14:08:08 -0800 | [diff] [blame] | 1147 | "external/arm_frc_linux_gnueabi_repo/arm-nilrt-linux-gnueabi/sysroot/usr/include", |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1148 | "-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 Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 1181 | if (ctx.attr.cpu == "rp2040" or |
James Kuszmaul | 5a72856 | 2023-12-28 21:45:01 -0800 | [diff] [blame] | 1182 | ctx.attr.cpu == "cortex-m4f-imu" or |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 1183 | ctx.attr.cpu == "cortex-m4f" or |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 1184 | ctx.attr.cpu == "cortex-m4f-k22"): |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1185 | features = [ |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 1186 | 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 Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 1193 | user_compile_flags_feature, |
| 1194 | sysroot_feature, |
| 1195 | unfiltered_compile_flags_feature, |
| 1196 | ] |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 1197 | elif ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1198 | features = [ |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 1199 | 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 Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 1213 | user_compile_flags_feature, |
| 1214 | sysroot_feature, |
| 1215 | unfiltered_compile_flags_feature, |
| 1216 | ] |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1217 | else: |
| 1218 | fail("Unreachable") |
| 1219 | |
Brian Silverman | 33ca369 | 2022-02-06 18:37:17 -0800 | [diff] [blame] | 1220 | if ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1221 | cxx_builtin_include_directories = [ |
James Kuszmaul | 9776b39 | 2023-01-14 14:08:08 -0800 | [diff] [blame] | 1222 | "%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 Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 1226 | ] |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 1227 | elif (ctx.attr.cpu == "rp2040" or |
James Kuszmaul | 5a72856 | 2023-12-28 21:45:01 -0800 | [diff] [blame] | 1228 | ctx.attr.cpu == "cortex-m4f-imu" or |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 1229 | ctx.attr.cpu == "cortex-m4f" or |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 1230 | ctx.attr.cpu == "cortex-m4f-k22"): |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1231 | cxx_builtin_include_directories = [ |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 1232 | "/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 Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1237 | else: |
| 1238 | fail("Unreachable") |
| 1239 | |
| 1240 | artifact_name_patterns = [] |
| 1241 | |
| 1242 | make_variables = [] |
| 1243 | |
Brian Silverman | 94cab07 | 2022-01-02 23:50:03 -0800 | [diff] [blame] | 1244 | if ctx.attr.cpu == "roborio": |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1245 | 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 Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 1292 | elif (ctx.attr.cpu == "rp2040" or |
James Kuszmaul | 5a72856 | 2023-12-28 21:45:01 -0800 | [diff] [blame] | 1293 | ctx.attr.cpu == "cortex-m4f-imu" or |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 1294 | ctx.attr.cpu == "cortex-m4f" or |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 1295 | ctx.attr.cpu == "cortex-m4f-k22"): |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1296 | 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 Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1342 | else: |
| 1343 | fail("Unreachable") |
| 1344 | |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1345 | 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 Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 1365 | cc_target_os = cc_target_os, |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1366 | ), |
| 1367 | DefaultInfo( |
| 1368 | executable = out, |
| 1369 | ), |
| 1370 | ] |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 1371 | |
| 1372 | cc_toolchain_config = rule( |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1373 | implementation = _impl, |
| 1374 | attrs = { |
James Kuszmaul | 5a72856 | 2023-12-28 21:45:01 -0800 | [diff] [blame] | 1375 | "cpu": attr.string(mandatory = True, values = ["cortex-m4f", "cortex-m4f-k22", "roborio", "rp2040", "cortex-m4f-imu"]), |
Austin Schuh | da9d060 | 2019-09-15 17:29:38 -0700 | [diff] [blame] | 1376 | }, |
| 1377 | provides = [CcToolchainConfigInfo], |
| 1378 | executable = True, |
| 1379 | ) |