rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 1 | # Copyright 2019 The Bazel Authors. All rights reserved. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | """A Starlark cc_toolchain configuration rule""" |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 16 | |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 17 | load( |
| 18 | "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", |
plf | 21b5eb6 | 2020-10-21 06:53:30 -0700 | [diff] [blame] | 19 | "action_config", |
Fabian Meumertzheim | 3f1672e | 2021-12-01 02:59:53 -0800 | [diff] [blame] | 20 | "artifact_name_pattern", |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 21 | "feature", |
| 22 | "feature_set", |
| 23 | "flag_group", |
| 24 | "flag_set", |
plf | 21b5eb6 | 2020-10-21 06:53:30 -0700 | [diff] [blame] | 25 | "tool", |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 26 | "tool_path", |
| 27 | "variable_with_value", |
| 28 | "with_feature_set", |
| 29 | ) |
| 30 | load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 31 | |
hlopko | 8b9f746 | 2020-05-26 05:39:52 -0700 | [diff] [blame] | 32 | def layering_check_features(compiler): |
| 33 | if compiler != "clang": |
| 34 | return [] |
| 35 | return [ |
| 36 | feature( |
| 37 | name = "use_module_maps", |
| 38 | requires = [feature_set(features = ["module_maps"])], |
| 39 | flag_sets = [ |
| 40 | flag_set( |
| 41 | actions = [ |
| 42 | ACTION_NAMES.c_compile, |
| 43 | ACTION_NAMES.cpp_compile, |
| 44 | ACTION_NAMES.cpp_header_parsing, |
| 45 | ACTION_NAMES.cpp_module_compile, |
| 46 | ], |
| 47 | flag_groups = [ |
| 48 | flag_group( |
| 49 | flags = [ |
| 50 | "-fmodule-name=%{module_name}", |
| 51 | "-fmodule-map-file=%{module_map_file}", |
| 52 | ], |
| 53 | ), |
| 54 | ], |
| 55 | ), |
| 56 | ], |
| 57 | ), |
| 58 | |
| 59 | # Tell blaze we support module maps in general, so they will be generated |
| 60 | # for all c/c++ rules. |
| 61 | # Note: not all C++ rules support module maps; thus, do not imply this |
| 62 | # feature from other features - instead, require it. |
| 63 | feature(name = "module_maps", enabled = True), |
| 64 | feature( |
| 65 | name = "layering_check", |
| 66 | implies = ["use_module_maps"], |
| 67 | flag_sets = [ |
| 68 | flag_set( |
| 69 | actions = [ |
| 70 | ACTION_NAMES.c_compile, |
| 71 | ACTION_NAMES.cpp_compile, |
| 72 | ACTION_NAMES.cpp_header_parsing, |
| 73 | ACTION_NAMES.cpp_module_compile, |
| 74 | ], |
| 75 | flag_groups = [ |
| 76 | flag_group(flags = [ |
| 77 | "-fmodules-strict-decluse", |
| 78 | "-Wprivate-header", |
| 79 | ]), |
| 80 | flag_group( |
| 81 | iterate_over = "dependent_module_map_files", |
| 82 | flags = [ |
| 83 | "-fmodule-map-file=%{dependent_module_map_files}", |
| 84 | ], |
| 85 | ), |
| 86 | ], |
| 87 | ), |
| 88 | ], |
| 89 | ), |
| 90 | ] |
| 91 | |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 92 | all_compile_actions = [ |
| 93 | ACTION_NAMES.c_compile, |
| 94 | ACTION_NAMES.cpp_compile, |
| 95 | ACTION_NAMES.linkstamp_compile, |
| 96 | ACTION_NAMES.assemble, |
| 97 | ACTION_NAMES.preprocess_assemble, |
| 98 | ACTION_NAMES.cpp_header_parsing, |
| 99 | ACTION_NAMES.cpp_module_compile, |
| 100 | ACTION_NAMES.cpp_module_codegen, |
| 101 | ACTION_NAMES.clif_match, |
| 102 | ACTION_NAMES.lto_backend, |
| 103 | ] |
| 104 | |
| 105 | all_cpp_compile_actions = [ |
| 106 | ACTION_NAMES.cpp_compile, |
| 107 | ACTION_NAMES.linkstamp_compile, |
| 108 | ACTION_NAMES.cpp_header_parsing, |
| 109 | ACTION_NAMES.cpp_module_compile, |
| 110 | ACTION_NAMES.cpp_module_codegen, |
| 111 | ACTION_NAMES.clif_match, |
| 112 | ] |
| 113 | |
| 114 | preprocessor_compile_actions = [ |
| 115 | ACTION_NAMES.c_compile, |
| 116 | ACTION_NAMES.cpp_compile, |
| 117 | ACTION_NAMES.linkstamp_compile, |
| 118 | ACTION_NAMES.preprocess_assemble, |
| 119 | ACTION_NAMES.cpp_header_parsing, |
| 120 | ACTION_NAMES.cpp_module_compile, |
| 121 | ACTION_NAMES.clif_match, |
| 122 | ] |
| 123 | |
| 124 | codegen_compile_actions = [ |
| 125 | ACTION_NAMES.c_compile, |
| 126 | ACTION_NAMES.cpp_compile, |
| 127 | ACTION_NAMES.linkstamp_compile, |
| 128 | ACTION_NAMES.assemble, |
| 129 | ACTION_NAMES.preprocess_assemble, |
| 130 | ACTION_NAMES.cpp_module_codegen, |
| 131 | ACTION_NAMES.lto_backend, |
| 132 | ] |
| 133 | |
| 134 | all_link_actions = [ |
| 135 | ACTION_NAMES.cpp_link_executable, |
| 136 | ACTION_NAMES.cpp_link_dynamic_library, |
| 137 | ACTION_NAMES.cpp_link_nodeps_dynamic_library, |
| 138 | ] |
| 139 | |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 140 | lto_index_actions = [ |
| 141 | ACTION_NAMES.lto_index_for_executable, |
| 142 | ACTION_NAMES.lto_index_for_dynamic_library, |
| 143 | ACTION_NAMES.lto_index_for_nodeps_dynamic_library, |
| 144 | ] |
| 145 | |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 146 | def _impl(ctx): |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 147 | tool_paths = [ |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 148 | tool_path(name = name, path = path) |
| 149 | for name, path in ctx.attr.tool_paths.items() |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 150 | ] |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 151 | action_configs = [] |
| 152 | |
plf | 21b5eb6 | 2020-10-21 06:53:30 -0700 | [diff] [blame] | 153 | llvm_cov_action = action_config( |
| 154 | action_name = ACTION_NAMES.llvm_cov, |
| 155 | tools = [ |
| 156 | tool( |
| 157 | path = ctx.attr.tool_paths["llvm-cov"], |
| 158 | ), |
| 159 | ], |
| 160 | ) |
| 161 | |
| 162 | action_configs.append(llvm_cov_action) |
| 163 | |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 164 | supports_pic_feature = feature( |
| 165 | name = "supports_pic", |
| 166 | enabled = True, |
| 167 | ) |
| 168 | supports_start_end_lib_feature = feature( |
| 169 | name = "supports_start_end_lib", |
| 170 | enabled = True, |
| 171 | ) |
| 172 | |
| 173 | default_compile_flags_feature = feature( |
| 174 | name = "default_compile_flags", |
| 175 | enabled = True, |
| 176 | flag_sets = [ |
| 177 | flag_set( |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 178 | actions = all_compile_actions, |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 179 | flag_groups = ([ |
| 180 | flag_group( |
| 181 | flags = ctx.attr.compile_flags, |
| 182 | ), |
| 183 | ] if ctx.attr.compile_flags else []), |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 184 | ), |
| 185 | flag_set( |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 186 | actions = all_compile_actions, |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 187 | flag_groups = ([ |
| 188 | flag_group( |
| 189 | flags = ctx.attr.dbg_compile_flags, |
| 190 | ), |
| 191 | ] if ctx.attr.dbg_compile_flags else []), |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 192 | with_features = [with_feature_set(features = ["dbg"])], |
| 193 | ), |
| 194 | flag_set( |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 195 | actions = all_compile_actions, |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 196 | flag_groups = ([ |
| 197 | flag_group( |
| 198 | flags = ctx.attr.opt_compile_flags, |
| 199 | ), |
| 200 | ] if ctx.attr.opt_compile_flags else []), |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 201 | with_features = [with_feature_set(features = ["opt"])], |
| 202 | ), |
| 203 | flag_set( |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 204 | actions = all_cpp_compile_actions + [ACTION_NAMES.lto_backend], |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 205 | flag_groups = ([ |
| 206 | flag_group( |
| 207 | flags = ctx.attr.cxx_flags, |
| 208 | ), |
| 209 | ] if ctx.attr.cxx_flags else []), |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 210 | ), |
| 211 | ], |
| 212 | ) |
| 213 | |
| 214 | default_link_flags_feature = feature( |
| 215 | name = "default_link_flags", |
| 216 | enabled = True, |
| 217 | flag_sets = [ |
| 218 | flag_set( |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 219 | actions = all_link_actions + lto_index_actions, |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 220 | flag_groups = ([ |
| 221 | flag_group( |
| 222 | flags = ctx.attr.link_flags, |
| 223 | ), |
| 224 | ] if ctx.attr.link_flags else []), |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 225 | ), |
| 226 | flag_set( |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 227 | actions = all_link_actions + lto_index_actions, |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 228 | flag_groups = ([ |
| 229 | flag_group( |
| 230 | flags = ctx.attr.opt_link_flags, |
| 231 | ), |
| 232 | ] if ctx.attr.opt_link_flags else []), |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 233 | with_features = [with_feature_set(features = ["opt"])], |
| 234 | ), |
| 235 | ], |
| 236 | ) |
| 237 | |
| 238 | dbg_feature = feature(name = "dbg") |
| 239 | |
| 240 | opt_feature = feature(name = "opt") |
| 241 | |
| 242 | sysroot_feature = feature( |
| 243 | name = "sysroot", |
| 244 | enabled = True, |
| 245 | flag_sets = [ |
| 246 | flag_set( |
| 247 | actions = [ |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 248 | ACTION_NAMES.preprocess_assemble, |
| 249 | ACTION_NAMES.linkstamp_compile, |
| 250 | ACTION_NAMES.c_compile, |
| 251 | ACTION_NAMES.cpp_compile, |
| 252 | ACTION_NAMES.cpp_header_parsing, |
| 253 | ACTION_NAMES.cpp_module_compile, |
| 254 | ACTION_NAMES.cpp_module_codegen, |
| 255 | ACTION_NAMES.lto_backend, |
| 256 | ACTION_NAMES.clif_match, |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 257 | ] + all_link_actions + lto_index_actions, |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 258 | flag_groups = [ |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 259 | flag_group( |
| 260 | flags = ["--sysroot=%{sysroot}"], |
| 261 | expand_if_available = "sysroot", |
| 262 | ), |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 263 | ], |
| 264 | ), |
| 265 | ], |
| 266 | ) |
| 267 | |
| 268 | fdo_optimize_feature = feature( |
| 269 | name = "fdo_optimize", |
| 270 | flag_sets = [ |
| 271 | flag_set( |
| 272 | actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], |
| 273 | flag_groups = [ |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 274 | flag_group( |
| 275 | flags = [ |
| 276 | "-fprofile-use=%{fdo_profile_path}", |
| 277 | "-fprofile-correction", |
| 278 | ], |
| 279 | expand_if_available = "fdo_profile_path", |
| 280 | ), |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 281 | ], |
| 282 | ), |
| 283 | ], |
| 284 | provides = ["profile"], |
| 285 | ) |
| 286 | |
| 287 | supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) |
| 288 | |
| 289 | user_compile_flags_feature = feature( |
| 290 | name = "user_compile_flags", |
| 291 | enabled = True, |
| 292 | flag_sets = [ |
| 293 | flag_set( |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 294 | actions = all_compile_actions, |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 295 | flag_groups = [ |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 296 | flag_group( |
| 297 | flags = ["%{user_compile_flags}"], |
| 298 | iterate_over = "user_compile_flags", |
| 299 | expand_if_available = "user_compile_flags", |
| 300 | ), |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 301 | ], |
| 302 | ), |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 303 | ], |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 304 | ) |
| 305 | |
| 306 | unfiltered_compile_flags_feature = feature( |
| 307 | name = "unfiltered_compile_flags", |
| 308 | enabled = True, |
| 309 | flag_sets = [ |
| 310 | flag_set( |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 311 | actions = all_compile_actions, |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 312 | flag_groups = ([ |
| 313 | flag_group( |
| 314 | flags = ctx.attr.unfiltered_compile_flags, |
| 315 | ), |
| 316 | ] if ctx.attr.unfiltered_compile_flags else []), |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 317 | ), |
| 318 | ], |
| 319 | ) |
| 320 | |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 321 | library_search_directories_feature = feature( |
| 322 | name = "library_search_directories", |
| 323 | flag_sets = [ |
| 324 | flag_set( |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 325 | actions = all_link_actions + lto_index_actions, |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 326 | flag_groups = [ |
| 327 | flag_group( |
| 328 | flags = ["-L%{library_search_directories}"], |
| 329 | iterate_over = "library_search_directories", |
| 330 | expand_if_available = "library_search_directories", |
| 331 | ), |
| 332 | ], |
| 333 | ), |
| 334 | ], |
| 335 | ) |
| 336 | |
| 337 | static_libgcc_feature = feature( |
| 338 | name = "static_libgcc", |
| 339 | enabled = True, |
| 340 | flag_sets = [ |
| 341 | flag_set( |
| 342 | actions = [ |
| 343 | ACTION_NAMES.cpp_link_executable, |
| 344 | ACTION_NAMES.cpp_link_dynamic_library, |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 345 | ACTION_NAMES.lto_index_for_executable, |
| 346 | ACTION_NAMES.lto_index_for_dynamic_library, |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 347 | ], |
| 348 | flag_groups = [flag_group(flags = ["-static-libgcc"])], |
| 349 | with_features = [ |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 350 | with_feature_set(features = ["static_link_cpp_runtimes"]), |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 351 | ], |
| 352 | ), |
| 353 | ], |
| 354 | ) |
| 355 | |
| 356 | pic_feature = feature( |
| 357 | name = "pic", |
| 358 | enabled = True, |
| 359 | flag_sets = [ |
| 360 | flag_set( |
| 361 | actions = [ |
| 362 | ACTION_NAMES.assemble, |
| 363 | ACTION_NAMES.preprocess_assemble, |
| 364 | ACTION_NAMES.linkstamp_compile, |
| 365 | ACTION_NAMES.c_compile, |
| 366 | ACTION_NAMES.cpp_compile, |
| 367 | ACTION_NAMES.cpp_module_codegen, |
| 368 | ACTION_NAMES.cpp_module_compile, |
| 369 | ], |
| 370 | flag_groups = [ |
| 371 | flag_group(flags = ["-fPIC"], expand_if_available = "pic"), |
| 372 | ], |
| 373 | ), |
| 374 | ], |
| 375 | ) |
| 376 | |
| 377 | per_object_debug_info_feature = feature( |
| 378 | name = "per_object_debug_info", |
| 379 | flag_sets = [ |
| 380 | flag_set( |
| 381 | actions = [ |
| 382 | ACTION_NAMES.assemble, |
| 383 | ACTION_NAMES.preprocess_assemble, |
| 384 | ACTION_NAMES.c_compile, |
| 385 | ACTION_NAMES.cpp_compile, |
| 386 | ACTION_NAMES.cpp_module_codegen, |
| 387 | ], |
| 388 | flag_groups = [ |
| 389 | flag_group( |
Keith Smiley | fa69b78 | 2021-10-07 03:24:13 -0700 | [diff] [blame] | 390 | flags = ["-gsplit-dwarf", "-g"], |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 391 | expand_if_available = "per_object_debug_info_file", |
| 392 | ), |
| 393 | ], |
| 394 | ), |
| 395 | ], |
| 396 | ) |
| 397 | |
| 398 | preprocessor_defines_feature = feature( |
| 399 | name = "preprocessor_defines", |
| 400 | enabled = True, |
| 401 | flag_sets = [ |
| 402 | flag_set( |
| 403 | actions = [ |
| 404 | ACTION_NAMES.preprocess_assemble, |
| 405 | ACTION_NAMES.linkstamp_compile, |
| 406 | ACTION_NAMES.c_compile, |
| 407 | ACTION_NAMES.cpp_compile, |
| 408 | ACTION_NAMES.cpp_header_parsing, |
| 409 | ACTION_NAMES.cpp_module_compile, |
| 410 | ACTION_NAMES.clif_match, |
| 411 | ], |
| 412 | flag_groups = [ |
| 413 | flag_group( |
| 414 | flags = ["-D%{preprocessor_defines}"], |
| 415 | iterate_over = "preprocessor_defines", |
| 416 | ), |
| 417 | ], |
| 418 | ), |
| 419 | ], |
| 420 | ) |
| 421 | |
| 422 | cs_fdo_optimize_feature = feature( |
| 423 | name = "cs_fdo_optimize", |
| 424 | flag_sets = [ |
| 425 | flag_set( |
| 426 | actions = [ACTION_NAMES.lto_backend], |
| 427 | flag_groups = [ |
| 428 | flag_group( |
| 429 | flags = [ |
| 430 | "-fprofile-use=%{fdo_profile_path}", |
Googler | a5b1693 | 2020-04-13 13:06:59 -0700 | [diff] [blame] | 431 | "-Wno-profile-instr-unprofiled", |
| 432 | "-Wno-profile-instr-out-of-date", |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 433 | "-fprofile-correction", |
| 434 | ], |
| 435 | expand_if_available = "fdo_profile_path", |
| 436 | ), |
| 437 | ], |
| 438 | ), |
| 439 | ], |
| 440 | provides = ["csprofile"], |
| 441 | ) |
| 442 | |
| 443 | autofdo_feature = feature( |
| 444 | name = "autofdo", |
| 445 | flag_sets = [ |
| 446 | flag_set( |
| 447 | actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], |
| 448 | flag_groups = [ |
| 449 | flag_group( |
| 450 | flags = [ |
| 451 | "-fauto-profile=%{fdo_profile_path}", |
| 452 | "-fprofile-correction", |
| 453 | ], |
| 454 | expand_if_available = "fdo_profile_path", |
| 455 | ), |
| 456 | ], |
| 457 | ), |
| 458 | ], |
| 459 | provides = ["profile"], |
| 460 | ) |
| 461 | |
| 462 | runtime_library_search_directories_feature = feature( |
| 463 | name = "runtime_library_search_directories", |
| 464 | flag_sets = [ |
| 465 | flag_set( |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 466 | actions = all_link_actions + lto_index_actions, |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 467 | flag_groups = [ |
| 468 | flag_group( |
| 469 | iterate_over = "runtime_library_search_directories", |
| 470 | flag_groups = [ |
| 471 | flag_group( |
| 472 | flags = [ |
| 473 | "-Wl,-rpath,$EXEC_ORIGIN/%{runtime_library_search_directories}", |
| 474 | ], |
| 475 | expand_if_true = "is_cc_test", |
| 476 | ), |
| 477 | flag_group( |
| 478 | flags = [ |
| 479 | "-Wl,-rpath,$ORIGIN/%{runtime_library_search_directories}", |
| 480 | ], |
| 481 | expand_if_false = "is_cc_test", |
| 482 | ), |
| 483 | ], |
| 484 | expand_if_available = |
| 485 | "runtime_library_search_directories", |
| 486 | ), |
| 487 | ], |
| 488 | with_features = [ |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 489 | with_feature_set(features = ["static_link_cpp_runtimes"]), |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 490 | ], |
| 491 | ), |
| 492 | flag_set( |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 493 | actions = all_link_actions + lto_index_actions, |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 494 | flag_groups = [ |
| 495 | flag_group( |
| 496 | iterate_over = "runtime_library_search_directories", |
| 497 | flag_groups = [ |
| 498 | flag_group( |
| 499 | flags = [ |
| 500 | "-Wl,-rpath,$ORIGIN/%{runtime_library_search_directories}", |
| 501 | ], |
| 502 | ), |
| 503 | ], |
| 504 | expand_if_available = |
| 505 | "runtime_library_search_directories", |
| 506 | ), |
| 507 | ], |
| 508 | with_features = [ |
| 509 | with_feature_set( |
| 510 | not_features = ["static_link_cpp_runtimes"], |
| 511 | ), |
| 512 | ], |
| 513 | ), |
| 514 | ], |
| 515 | ) |
| 516 | |
| 517 | fission_support_feature = feature( |
| 518 | name = "fission_support", |
| 519 | flag_sets = [ |
| 520 | flag_set( |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 521 | actions = all_link_actions + lto_index_actions, |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 522 | flag_groups = [ |
| 523 | flag_group( |
| 524 | flags = ["-Wl,--gdb-index"], |
| 525 | expand_if_available = "is_using_fission", |
| 526 | ), |
| 527 | ], |
| 528 | ), |
| 529 | ], |
| 530 | ) |
| 531 | |
| 532 | shared_flag_feature = feature( |
| 533 | name = "shared_flag", |
| 534 | flag_sets = [ |
| 535 | flag_set( |
| 536 | actions = [ |
| 537 | ACTION_NAMES.cpp_link_dynamic_library, |
| 538 | ACTION_NAMES.cpp_link_nodeps_dynamic_library, |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 539 | ACTION_NAMES.lto_index_for_dynamic_library, |
| 540 | ACTION_NAMES.lto_index_for_nodeps_dynamic_library, |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 541 | ], |
| 542 | flag_groups = [flag_group(flags = ["-shared"])], |
| 543 | ), |
| 544 | ], |
| 545 | ) |
| 546 | |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 547 | random_seed_feature = feature( |
| 548 | name = "random_seed", |
| 549 | enabled = True, |
| 550 | flag_sets = [ |
| 551 | flag_set( |
| 552 | actions = [ |
| 553 | ACTION_NAMES.c_compile, |
| 554 | ACTION_NAMES.cpp_compile, |
| 555 | ACTION_NAMES.cpp_module_codegen, |
| 556 | ACTION_NAMES.cpp_module_compile, |
| 557 | ], |
| 558 | flag_groups = [ |
| 559 | flag_group( |
| 560 | flags = ["-frandom-seed=%{output_file}"], |
| 561 | expand_if_available = "output_file", |
| 562 | ), |
| 563 | ], |
| 564 | ), |
| 565 | ], |
| 566 | ) |
| 567 | |
| 568 | includes_feature = feature( |
| 569 | name = "includes", |
| 570 | enabled = True, |
| 571 | flag_sets = [ |
| 572 | flag_set( |
| 573 | actions = [ |
| 574 | ACTION_NAMES.preprocess_assemble, |
| 575 | ACTION_NAMES.linkstamp_compile, |
| 576 | ACTION_NAMES.c_compile, |
| 577 | ACTION_NAMES.cpp_compile, |
| 578 | ACTION_NAMES.cpp_header_parsing, |
| 579 | ACTION_NAMES.cpp_module_compile, |
| 580 | ACTION_NAMES.clif_match, |
| 581 | ACTION_NAMES.objc_compile, |
| 582 | ACTION_NAMES.objcpp_compile, |
| 583 | ], |
| 584 | flag_groups = [ |
| 585 | flag_group( |
| 586 | flags = ["-include", "%{includes}"], |
| 587 | iterate_over = "includes", |
| 588 | expand_if_available = "includes", |
| 589 | ), |
| 590 | ], |
| 591 | ), |
| 592 | ], |
| 593 | ) |
| 594 | |
| 595 | fdo_instrument_feature = feature( |
| 596 | name = "fdo_instrument", |
| 597 | flag_sets = [ |
| 598 | flag_set( |
| 599 | actions = [ |
| 600 | ACTION_NAMES.c_compile, |
| 601 | ACTION_NAMES.cpp_compile, |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 602 | ] + all_link_actions + lto_index_actions, |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 603 | flag_groups = [ |
| 604 | flag_group( |
| 605 | flags = [ |
| 606 | "-fprofile-generate=%{fdo_instrument_path}", |
| 607 | "-fno-data-sections", |
| 608 | ], |
| 609 | expand_if_available = "fdo_instrument_path", |
| 610 | ), |
| 611 | ], |
| 612 | ), |
| 613 | ], |
| 614 | provides = ["profile"], |
| 615 | ) |
| 616 | |
| 617 | cs_fdo_instrument_feature = feature( |
| 618 | name = "cs_fdo_instrument", |
| 619 | flag_sets = [ |
| 620 | flag_set( |
| 621 | actions = [ |
| 622 | ACTION_NAMES.c_compile, |
| 623 | ACTION_NAMES.cpp_compile, |
| 624 | ACTION_NAMES.lto_backend, |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 625 | ] + all_link_actions + lto_index_actions, |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 626 | flag_groups = [ |
| 627 | flag_group( |
| 628 | flags = [ |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 629 | "-fcs-profile-generate=%{cs_fdo_instrument_path}", |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 630 | ], |
| 631 | expand_if_available = "cs_fdo_instrument_path", |
| 632 | ), |
| 633 | ], |
| 634 | ), |
| 635 | ], |
| 636 | provides = ["csprofile"], |
| 637 | ) |
| 638 | |
| 639 | include_paths_feature = feature( |
| 640 | name = "include_paths", |
| 641 | enabled = True, |
| 642 | flag_sets = [ |
| 643 | flag_set( |
| 644 | actions = [ |
| 645 | ACTION_NAMES.preprocess_assemble, |
| 646 | ACTION_NAMES.linkstamp_compile, |
| 647 | ACTION_NAMES.c_compile, |
| 648 | ACTION_NAMES.cpp_compile, |
| 649 | ACTION_NAMES.cpp_header_parsing, |
| 650 | ACTION_NAMES.cpp_module_compile, |
| 651 | ACTION_NAMES.clif_match, |
| 652 | ACTION_NAMES.objc_compile, |
| 653 | ACTION_NAMES.objcpp_compile, |
| 654 | ], |
| 655 | flag_groups = [ |
| 656 | flag_group( |
| 657 | flags = ["-iquote", "%{quote_include_paths}"], |
| 658 | iterate_over = "quote_include_paths", |
| 659 | ), |
| 660 | flag_group( |
| 661 | flags = ["-I%{include_paths}"], |
| 662 | iterate_over = "include_paths", |
| 663 | ), |
| 664 | flag_group( |
| 665 | flags = ["-isystem", "%{system_include_paths}"], |
| 666 | iterate_over = "system_include_paths", |
| 667 | ), |
| 668 | ], |
| 669 | ), |
| 670 | ], |
| 671 | ) |
| 672 | |
Benedek Thaler | 08936ae | 2021-04-01 03:33:34 -0700 | [diff] [blame] | 673 | external_include_paths_feature = feature( |
| 674 | name = "external_include_paths", |
| 675 | flag_sets = [ |
| 676 | flag_set( |
| 677 | actions = [ |
| 678 | ACTION_NAMES.preprocess_assemble, |
| 679 | ACTION_NAMES.linkstamp_compile, |
| 680 | ACTION_NAMES.c_compile, |
| 681 | ACTION_NAMES.cpp_compile, |
| 682 | ACTION_NAMES.cpp_header_parsing, |
| 683 | ACTION_NAMES.cpp_module_compile, |
| 684 | ACTION_NAMES.clif_match, |
| 685 | ACTION_NAMES.objc_compile, |
| 686 | ACTION_NAMES.objcpp_compile, |
| 687 | ], |
| 688 | flag_groups = [ |
| 689 | flag_group( |
| 690 | flags = ["-isystem", "%{external_include_paths}"], |
| 691 | iterate_over = "external_include_paths", |
| 692 | expand_if_available = "external_include_paths", |
| 693 | ), |
| 694 | ], |
| 695 | ), |
| 696 | ], |
| 697 | ) |
| 698 | |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 699 | symbol_counts_feature = feature( |
| 700 | name = "symbol_counts", |
| 701 | flag_sets = [ |
| 702 | flag_set( |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 703 | actions = all_link_actions + lto_index_actions, |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 704 | flag_groups = [ |
| 705 | flag_group( |
| 706 | flags = [ |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 707 | "-Wl,--print-symbol-counts=%{symbol_counts_output}", |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 708 | ], |
| 709 | expand_if_available = "symbol_counts_output", |
| 710 | ), |
| 711 | ], |
| 712 | ), |
| 713 | ], |
| 714 | ) |
| 715 | |
| 716 | llvm_coverage_map_format_feature = feature( |
| 717 | name = "llvm_coverage_map_format", |
| 718 | flag_sets = [ |
| 719 | flag_set( |
| 720 | actions = [ |
| 721 | ACTION_NAMES.preprocess_assemble, |
| 722 | ACTION_NAMES.c_compile, |
| 723 | ACTION_NAMES.cpp_compile, |
| 724 | ACTION_NAMES.cpp_module_compile, |
| 725 | ACTION_NAMES.objc_compile, |
| 726 | ACTION_NAMES.objcpp_compile, |
| 727 | ], |
| 728 | flag_groups = [ |
| 729 | flag_group( |
| 730 | flags = [ |
| 731 | "-fprofile-instr-generate", |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 732 | "-fcoverage-mapping", |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 733 | ], |
| 734 | ), |
| 735 | ], |
| 736 | ), |
| 737 | flag_set( |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 738 | actions = all_link_actions + lto_index_actions + [ |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 739 | "objc-executable", |
| 740 | "objc++-executable", |
| 741 | ], |
| 742 | flag_groups = [ |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 743 | flag_group(flags = ["-fprofile-instr-generate"]), |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 744 | ], |
| 745 | ), |
| 746 | ], |
| 747 | requires = [feature_set(features = ["coverage"])], |
| 748 | provides = ["profile"], |
| 749 | ) |
| 750 | |
| 751 | strip_debug_symbols_feature = feature( |
| 752 | name = "strip_debug_symbols", |
| 753 | flag_sets = [ |
| 754 | flag_set( |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 755 | actions = all_link_actions + lto_index_actions, |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 756 | flag_groups = [ |
| 757 | flag_group( |
| 758 | flags = ["-Wl,-S"], |
| 759 | expand_if_available = "strip_debug_symbols", |
| 760 | ), |
| 761 | ], |
| 762 | ), |
| 763 | ], |
| 764 | ) |
| 765 | |
| 766 | build_interface_libraries_feature = feature( |
| 767 | name = "build_interface_libraries", |
| 768 | flag_sets = [ |
| 769 | flag_set( |
| 770 | actions = [ |
| 771 | ACTION_NAMES.cpp_link_dynamic_library, |
| 772 | ACTION_NAMES.cpp_link_nodeps_dynamic_library, |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 773 | ACTION_NAMES.lto_index_for_dynamic_library, |
| 774 | ACTION_NAMES.lto_index_for_nodeps_dynamic_library, |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 775 | ], |
| 776 | flag_groups = [ |
| 777 | flag_group( |
| 778 | flags = [ |
| 779 | "%{generate_interface_library}", |
| 780 | "%{interface_library_builder_path}", |
| 781 | "%{interface_library_input_path}", |
| 782 | "%{interface_library_output_path}", |
| 783 | ], |
| 784 | expand_if_available = "generate_interface_library", |
| 785 | ), |
| 786 | ], |
| 787 | with_features = [ |
| 788 | with_feature_set( |
| 789 | features = ["supports_interface_shared_libraries"], |
| 790 | ), |
| 791 | ], |
| 792 | ), |
| 793 | ], |
| 794 | ) |
| 795 | |
| 796 | libraries_to_link_feature = feature( |
| 797 | name = "libraries_to_link", |
| 798 | flag_sets = [ |
| 799 | flag_set( |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 800 | actions = all_link_actions + lto_index_actions, |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 801 | flag_groups = [ |
| 802 | flag_group( |
| 803 | iterate_over = "libraries_to_link", |
| 804 | flag_groups = [ |
| 805 | flag_group( |
| 806 | flags = ["-Wl,--start-lib"], |
| 807 | expand_if_equal = variable_with_value( |
| 808 | name = "libraries_to_link.type", |
| 809 | value = "object_file_group", |
| 810 | ), |
| 811 | ), |
| 812 | flag_group( |
| 813 | flags = ["-Wl,-whole-archive"], |
| 814 | expand_if_true = |
| 815 | "libraries_to_link.is_whole_archive", |
| 816 | ), |
| 817 | flag_group( |
| 818 | flags = ["%{libraries_to_link.object_files}"], |
| 819 | iterate_over = "libraries_to_link.object_files", |
| 820 | expand_if_equal = variable_with_value( |
| 821 | name = "libraries_to_link.type", |
| 822 | value = "object_file_group", |
| 823 | ), |
| 824 | ), |
| 825 | flag_group( |
| 826 | flags = ["%{libraries_to_link.name}"], |
| 827 | expand_if_equal = variable_with_value( |
| 828 | name = "libraries_to_link.type", |
| 829 | value = "object_file", |
| 830 | ), |
| 831 | ), |
| 832 | flag_group( |
| 833 | flags = ["%{libraries_to_link.name}"], |
| 834 | expand_if_equal = variable_with_value( |
| 835 | name = "libraries_to_link.type", |
| 836 | value = "interface_library", |
| 837 | ), |
| 838 | ), |
| 839 | flag_group( |
| 840 | flags = ["%{libraries_to_link.name}"], |
| 841 | expand_if_equal = variable_with_value( |
| 842 | name = "libraries_to_link.type", |
| 843 | value = "static_library", |
| 844 | ), |
| 845 | ), |
| 846 | flag_group( |
| 847 | flags = ["-l%{libraries_to_link.name}"], |
| 848 | expand_if_equal = variable_with_value( |
| 849 | name = "libraries_to_link.type", |
| 850 | value = "dynamic_library", |
| 851 | ), |
| 852 | ), |
| 853 | flag_group( |
| 854 | flags = ["-l:%{libraries_to_link.name}"], |
| 855 | expand_if_equal = variable_with_value( |
| 856 | name = "libraries_to_link.type", |
| 857 | value = "versioned_dynamic_library", |
| 858 | ), |
| 859 | ), |
| 860 | flag_group( |
| 861 | flags = ["-Wl,-no-whole-archive"], |
| 862 | expand_if_true = "libraries_to_link.is_whole_archive", |
| 863 | ), |
| 864 | flag_group( |
| 865 | flags = ["-Wl,--end-lib"], |
| 866 | expand_if_equal = variable_with_value( |
| 867 | name = "libraries_to_link.type", |
| 868 | value = "object_file_group", |
| 869 | ), |
| 870 | ), |
| 871 | ], |
| 872 | expand_if_available = "libraries_to_link", |
| 873 | ), |
| 874 | flag_group( |
| 875 | flags = ["-Wl,@%{thinlto_param_file}"], |
| 876 | expand_if_true = "thinlto_param_file", |
| 877 | ), |
| 878 | ], |
| 879 | ), |
| 880 | ], |
| 881 | ) |
| 882 | |
| 883 | user_link_flags_feature = feature( |
| 884 | name = "user_link_flags", |
| 885 | flag_sets = [ |
| 886 | flag_set( |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 887 | actions = all_link_actions + lto_index_actions, |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 888 | flag_groups = [ |
| 889 | flag_group( |
| 890 | flags = ["%{user_link_flags}"], |
| 891 | iterate_over = "user_link_flags", |
| 892 | expand_if_available = "user_link_flags", |
| 893 | ), |
Marcel Hlopko | ab9c1f5 | 2019-06-19 00:45:58 -0700 | [diff] [blame] | 894 | ] + ([flag_group(flags = ctx.attr.link_libs)] if ctx.attr.link_libs else []), |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 895 | ), |
| 896 | ], |
| 897 | ) |
| 898 | |
| 899 | fdo_prefetch_hints_feature = feature( |
| 900 | name = "fdo_prefetch_hints", |
| 901 | flag_sets = [ |
| 902 | flag_set( |
| 903 | actions = [ |
| 904 | ACTION_NAMES.c_compile, |
| 905 | ACTION_NAMES.cpp_compile, |
| 906 | ACTION_NAMES.lto_backend, |
| 907 | ], |
| 908 | flag_groups = [ |
| 909 | flag_group( |
| 910 | flags = [ |
Googler | a5b1693 | 2020-04-13 13:06:59 -0700 | [diff] [blame] | 911 | "-mllvm", |
| 912 | "-prefetch-hints-file=%{fdo_prefetch_hints_path}", |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 913 | ], |
| 914 | expand_if_available = "fdo_prefetch_hints_path", |
| 915 | ), |
| 916 | ], |
| 917 | ), |
| 918 | ], |
| 919 | ) |
| 920 | |
| 921 | linkstamps_feature = feature( |
| 922 | name = "linkstamps", |
| 923 | flag_sets = [ |
| 924 | flag_set( |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 925 | actions = all_link_actions + lto_index_actions, |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 926 | flag_groups = [ |
| 927 | flag_group( |
| 928 | flags = ["%{linkstamp_paths}"], |
| 929 | iterate_over = "linkstamp_paths", |
| 930 | expand_if_available = "linkstamp_paths", |
| 931 | ), |
| 932 | ], |
| 933 | ), |
| 934 | ], |
| 935 | ) |
| 936 | |
| 937 | gcc_coverage_map_format_feature = feature( |
| 938 | name = "gcc_coverage_map_format", |
| 939 | flag_sets = [ |
| 940 | flag_set( |
| 941 | actions = [ |
| 942 | ACTION_NAMES.preprocess_assemble, |
| 943 | ACTION_NAMES.c_compile, |
| 944 | ACTION_NAMES.cpp_compile, |
| 945 | ACTION_NAMES.cpp_module_compile, |
| 946 | ACTION_NAMES.objc_compile, |
| 947 | ACTION_NAMES.objcpp_compile, |
| 948 | "objc-executable", |
| 949 | "objc++-executable", |
| 950 | ], |
| 951 | flag_groups = [ |
| 952 | flag_group( |
| 953 | flags = ["-fprofile-arcs", "-ftest-coverage"], |
| 954 | expand_if_available = "gcov_gcno_file", |
| 955 | ), |
| 956 | ], |
| 957 | ), |
| 958 | flag_set( |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 959 | actions = all_link_actions + lto_index_actions, |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 960 | flag_groups = [flag_group(flags = ["--coverage"])], |
| 961 | ), |
| 962 | ], |
| 963 | requires = [feature_set(features = ["coverage"])], |
| 964 | provides = ["profile"], |
| 965 | ) |
| 966 | |
| 967 | archiver_flags_feature = feature( |
| 968 | name = "archiver_flags", |
| 969 | flag_sets = [ |
| 970 | flag_set( |
| 971 | actions = [ACTION_NAMES.cpp_link_static_library], |
| 972 | flag_groups = [ |
| 973 | flag_group(flags = ["rcsD"]), |
| 974 | flag_group( |
| 975 | flags = ["%{output_execpath}"], |
| 976 | expand_if_available = "output_execpath", |
| 977 | ), |
| 978 | ], |
| 979 | ), |
| 980 | flag_set( |
| 981 | actions = [ACTION_NAMES.cpp_link_static_library], |
| 982 | flag_groups = [ |
| 983 | flag_group( |
| 984 | iterate_over = "libraries_to_link", |
| 985 | flag_groups = [ |
| 986 | flag_group( |
| 987 | flags = ["%{libraries_to_link.name}"], |
| 988 | expand_if_equal = variable_with_value( |
| 989 | name = "libraries_to_link.type", |
| 990 | value = "object_file", |
| 991 | ), |
| 992 | ), |
| 993 | flag_group( |
| 994 | flags = ["%{libraries_to_link.object_files}"], |
| 995 | iterate_over = "libraries_to_link.object_files", |
| 996 | expand_if_equal = variable_with_value( |
| 997 | name = "libraries_to_link.type", |
| 998 | value = "object_file_group", |
| 999 | ), |
| 1000 | ), |
| 1001 | ], |
| 1002 | expand_if_available = "libraries_to_link", |
| 1003 | ), |
| 1004 | ], |
| 1005 | ), |
| 1006 | ], |
| 1007 | ) |
| 1008 | |
| 1009 | force_pic_flags_feature = feature( |
| 1010 | name = "force_pic_flags", |
| 1011 | flag_sets = [ |
| 1012 | flag_set( |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 1013 | actions = [ |
| 1014 | ACTION_NAMES.cpp_link_executable, |
| 1015 | ACTION_NAMES.lto_index_for_executable, |
| 1016 | ], |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 1017 | flag_groups = [ |
| 1018 | flag_group( |
| 1019 | flags = ["-pie"], |
| 1020 | expand_if_available = "force_pic", |
| 1021 | ), |
| 1022 | ], |
| 1023 | ), |
| 1024 | ], |
| 1025 | ) |
| 1026 | |
| 1027 | dependency_file_feature = feature( |
| 1028 | name = "dependency_file", |
| 1029 | enabled = True, |
| 1030 | flag_sets = [ |
| 1031 | flag_set( |
| 1032 | actions = [ |
| 1033 | ACTION_NAMES.assemble, |
| 1034 | ACTION_NAMES.preprocess_assemble, |
| 1035 | ACTION_NAMES.c_compile, |
| 1036 | ACTION_NAMES.cpp_compile, |
| 1037 | ACTION_NAMES.cpp_module_compile, |
| 1038 | ACTION_NAMES.objc_compile, |
| 1039 | ACTION_NAMES.objcpp_compile, |
| 1040 | ACTION_NAMES.cpp_header_parsing, |
| 1041 | ACTION_NAMES.clif_match, |
| 1042 | ], |
| 1043 | flag_groups = [ |
| 1044 | flag_group( |
| 1045 | flags = ["-MD", "-MF", "%{dependency_file}"], |
| 1046 | expand_if_available = "dependency_file", |
| 1047 | ), |
| 1048 | ], |
| 1049 | ), |
| 1050 | ], |
| 1051 | ) |
| 1052 | |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 1053 | dynamic_library_linker_tool_path = tool_paths |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 1054 | dynamic_library_linker_tool_feature = feature( |
| 1055 | name = "dynamic_library_linker_tool", |
| 1056 | flag_sets = [ |
| 1057 | flag_set( |
| 1058 | actions = [ |
| 1059 | ACTION_NAMES.cpp_link_dynamic_library, |
| 1060 | ACTION_NAMES.cpp_link_nodeps_dynamic_library, |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 1061 | ACTION_NAMES.lto_index_for_dynamic_library, |
| 1062 | ACTION_NAMES.lto_index_for_nodeps_dynamic_library, |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 1063 | ], |
| 1064 | flag_groups = [ |
| 1065 | flag_group( |
| 1066 | flags = [" + cppLinkDynamicLibraryToolPath + "], |
| 1067 | expand_if_available = "generate_interface_library", |
| 1068 | ), |
| 1069 | ], |
| 1070 | with_features = [ |
| 1071 | with_feature_set( |
| 1072 | features = ["supports_interface_shared_libraries"], |
| 1073 | ), |
| 1074 | ], |
| 1075 | ), |
| 1076 | ], |
| 1077 | ) |
| 1078 | |
| 1079 | output_execpath_flags_feature = feature( |
| 1080 | name = "output_execpath_flags", |
| 1081 | flag_sets = [ |
| 1082 | flag_set( |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 1083 | actions = all_link_actions + lto_index_actions, |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 1084 | flag_groups = [ |
| 1085 | flag_group( |
| 1086 | flags = ["-o", "%{output_execpath}"], |
| 1087 | expand_if_available = "output_execpath", |
| 1088 | ), |
| 1089 | ], |
| 1090 | ), |
| 1091 | ], |
| 1092 | ) |
| 1093 | |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 1094 | # Note that we also set --coverage for c++-link-nodeps-dynamic-library. The |
| 1095 | # generated code contains references to gcov symbols, and the dynamic linker |
| 1096 | # can't resolve them unless the library is linked against gcov. |
| 1097 | coverage_feature = feature( |
| 1098 | name = "coverage", |
| 1099 | provides = ["profile"], |
| 1100 | flag_sets = [ |
| 1101 | flag_set( |
| 1102 | actions = [ |
| 1103 | ACTION_NAMES.preprocess_assemble, |
| 1104 | ACTION_NAMES.c_compile, |
| 1105 | ACTION_NAMES.cpp_compile, |
| 1106 | ACTION_NAMES.cpp_header_parsing, |
| 1107 | ACTION_NAMES.cpp_module_compile, |
| 1108 | ], |
| 1109 | flag_groups = ([ |
| 1110 | flag_group(flags = ctx.attr.coverage_compile_flags), |
| 1111 | ] if ctx.attr.coverage_compile_flags else []), |
| 1112 | ), |
| 1113 | flag_set( |
rosica | 1112b55 | 2019-07-05 06:35:15 -0700 | [diff] [blame] | 1114 | actions = all_link_actions + lto_index_actions, |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 1115 | flag_groups = ([ |
| 1116 | flag_group(flags = ctx.attr.coverage_link_flags), |
| 1117 | ] if ctx.attr.coverage_link_flags else []), |
| 1118 | ), |
| 1119 | ], |
| 1120 | ) |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 1121 | |
rosica | e2a9e4a | 2019-08-27 03:33:31 -0700 | [diff] [blame] | 1122 | thinlto_feature = feature( |
| 1123 | name = "thin_lto", |
| 1124 | flag_sets = [ |
| 1125 | flag_set( |
| 1126 | actions = [ |
| 1127 | ACTION_NAMES.c_compile, |
| 1128 | ACTION_NAMES.cpp_compile, |
| 1129 | ] + all_link_actions + lto_index_actions, |
| 1130 | flag_groups = [ |
| 1131 | flag_group(flags = ["-flto=thin"]), |
| 1132 | flag_group( |
| 1133 | expand_if_available = "lto_indexing_bitcode_file", |
| 1134 | flags = [ |
| 1135 | "-Xclang", |
| 1136 | "-fthin-link-bitcode=%{lto_indexing_bitcode_file}", |
| 1137 | ], |
| 1138 | ), |
| 1139 | ], |
| 1140 | ), |
| 1141 | flag_set( |
| 1142 | actions = [ACTION_NAMES.linkstamp_compile], |
| 1143 | flag_groups = [flag_group(flags = ["-DBUILD_LTO_TYPE=thin"])], |
| 1144 | ), |
| 1145 | flag_set( |
| 1146 | actions = lto_index_actions, |
| 1147 | flag_groups = [ |
| 1148 | flag_group(flags = [ |
| 1149 | "-flto=thin", |
| 1150 | "-Wl,-plugin-opt,thinlto-index-only%{thinlto_optional_params_file}", |
| 1151 | "-Wl,-plugin-opt,thinlto-emit-imports-files", |
| 1152 | "-Wl,-plugin-opt,thinlto-prefix-replace=%{thinlto_prefix_replace}", |
| 1153 | ]), |
| 1154 | flag_group( |
| 1155 | expand_if_available = "thinlto_object_suffix_replace", |
| 1156 | flags = [ |
| 1157 | "-Wl,-plugin-opt,thinlto-object-suffix-replace=%{thinlto_object_suffix_replace}", |
| 1158 | ], |
| 1159 | ), |
| 1160 | flag_group( |
| 1161 | expand_if_available = "thinlto_merged_object_file", |
| 1162 | flags = [ |
| 1163 | "-Wl,-plugin-opt,obj-path=%{thinlto_merged_object_file}", |
| 1164 | ], |
| 1165 | ), |
| 1166 | ], |
| 1167 | ), |
| 1168 | flag_set( |
| 1169 | actions = [ACTION_NAMES.lto_backend], |
| 1170 | flag_groups = [ |
| 1171 | flag_group(flags = [ |
| 1172 | "-c", |
| 1173 | "-fthinlto-index=%{thinlto_index}", |
| 1174 | "-o", |
| 1175 | "%{thinlto_output_object_file}", |
| 1176 | "-x", |
| 1177 | "ir", |
| 1178 | "%{thinlto_input_bitcode_file}", |
| 1179 | ]), |
| 1180 | ], |
| 1181 | ), |
| 1182 | ], |
| 1183 | ) |
| 1184 | |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 1185 | is_linux = ctx.attr.target_libc != "macosx" |
| 1186 | |
| 1187 | # TODO(#8303): Mac crosstool should also declare every feature. |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 1188 | if is_linux: |
Fabian Meumertzheim | 3f1672e | 2021-12-01 02:59:53 -0800 | [diff] [blame] | 1189 | # Linux artifact name patterns are the default. |
| 1190 | artifact_name_patterns = [] |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 1191 | features = [ |
| 1192 | dependency_file_feature, |
| 1193 | random_seed_feature, |
| 1194 | pic_feature, |
| 1195 | per_object_debug_info_feature, |
| 1196 | preprocessor_defines_feature, |
| 1197 | includes_feature, |
| 1198 | include_paths_feature, |
Benedek Thaler | 08936ae | 2021-04-01 03:33:34 -0700 | [diff] [blame] | 1199 | external_include_paths_feature, |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 1200 | fdo_instrument_feature, |
| 1201 | cs_fdo_instrument_feature, |
| 1202 | cs_fdo_optimize_feature, |
rosica | e2a9e4a | 2019-08-27 03:33:31 -0700 | [diff] [blame] | 1203 | thinlto_feature, |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 1204 | fdo_prefetch_hints_feature, |
| 1205 | autofdo_feature, |
| 1206 | build_interface_libraries_feature, |
| 1207 | dynamic_library_linker_tool_feature, |
| 1208 | symbol_counts_feature, |
| 1209 | shared_flag_feature, |
| 1210 | linkstamps_feature, |
| 1211 | output_execpath_flags_feature, |
| 1212 | runtime_library_search_directories_feature, |
| 1213 | library_search_directories_feature, |
| 1214 | archiver_flags_feature, |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 1215 | force_pic_flags_feature, |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 1216 | fission_support_feature, |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 1217 | strip_debug_symbols_feature, |
| 1218 | coverage_feature, |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 1219 | supports_pic_feature, |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 1220 | ] + ( |
| 1221 | [ |
| 1222 | supports_start_end_lib_feature, |
| 1223 | ] if ctx.attr.supports_start_end_lib else [] |
| 1224 | ) + [ |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 1225 | default_compile_flags_feature, |
| 1226 | default_link_flags_feature, |
| 1227 | libraries_to_link_feature, |
plf | 21cf054 | 2019-05-20 09:01:24 -0700 | [diff] [blame] | 1228 | user_link_flags_feature, |
| 1229 | static_libgcc_feature, |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 1230 | fdo_optimize_feature, |
| 1231 | supports_dynamic_linker_feature, |
| 1232 | dbg_feature, |
| 1233 | opt_feature, |
| 1234 | user_compile_flags_feature, |
| 1235 | sysroot_feature, |
| 1236 | unfiltered_compile_flags_feature, |
hlopko | 8b9f746 | 2020-05-26 05:39:52 -0700 | [diff] [blame] | 1237 | ] + layering_check_features(ctx.attr.compiler) |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 1238 | else: |
Fabian Meumertzheim | 3f1672e | 2021-12-01 02:59:53 -0800 | [diff] [blame] | 1239 | # macOS artifact name patterns differ from the defaults only for dynamic |
| 1240 | # libraries. |
| 1241 | artifact_name_patterns = [ |
| 1242 | artifact_name_pattern( |
| 1243 | category_name = "dynamic_library", |
| 1244 | prefix = "lib", |
| 1245 | extension = ".dylib", |
| 1246 | ), |
| 1247 | ] |
rosica | beaba92 | 2019-05-20 02:36:26 -0700 | [diff] [blame] | 1248 | features = [ |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 1249 | supports_pic_feature, |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 1250 | ] + ( |
| 1251 | [ |
| 1252 | supports_start_end_lib_feature, |
| 1253 | ] if ctx.attr.supports_start_end_lib else [] |
| 1254 | ) + [ |
| 1255 | coverage_feature, |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 1256 | default_compile_flags_feature, |
| 1257 | default_link_flags_feature, |
Noa Resare | ae0a6c9 | 2021-11-23 10:15:13 -0800 | [diff] [blame] | 1258 | user_link_flags_feature, |
plf | 0ff6c09 | 2019-05-14 05:22:12 -0700 | [diff] [blame] | 1259 | fdo_optimize_feature, |
| 1260 | supports_dynamic_linker_feature, |
| 1261 | dbg_feature, |
| 1262 | opt_feature, |
| 1263 | user_compile_flags_feature, |
| 1264 | sysroot_feature, |
| 1265 | unfiltered_compile_flags_feature, |
hlopko | 8b9f746 | 2020-05-26 05:39:52 -0700 | [diff] [blame] | 1266 | ] + layering_check_features(ctx.attr.compiler) |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 1267 | |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 1268 | return cc_common.create_cc_toolchain_config_info( |
| 1269 | ctx = ctx, |
| 1270 | features = features, |
| 1271 | action_configs = action_configs, |
Fabian Meumertzheim | 3f1672e | 2021-12-01 02:59:53 -0800 | [diff] [blame] | 1272 | artifact_name_patterns = artifact_name_patterns, |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 1273 | cxx_builtin_include_directories = ctx.attr.cxx_builtin_include_directories, |
| 1274 | toolchain_identifier = ctx.attr.toolchain_identifier, |
| 1275 | host_system_name = ctx.attr.host_system_name, |
| 1276 | target_system_name = ctx.attr.target_system_name, |
| 1277 | target_cpu = ctx.attr.cpu, |
| 1278 | target_libc = ctx.attr.target_libc, |
| 1279 | compiler = ctx.attr.compiler, |
| 1280 | abi_version = ctx.attr.abi_version, |
| 1281 | abi_libc_version = ctx.attr.abi_libc_version, |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 1282 | tool_paths = tool_paths, |
erenon | da345f1 | 2020-10-29 08:25:15 -0700 | [diff] [blame] | 1283 | builtin_sysroot = ctx.attr.builtin_sysroot, |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 1284 | ) |
| 1285 | |
| 1286 | cc_toolchain_config = rule( |
| 1287 | implementation = _impl, |
| 1288 | attrs = { |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 1289 | "cpu": attr.string(mandatory = True), |
| 1290 | "compiler": attr.string(mandatory = True), |
| 1291 | "toolchain_identifier": attr.string(mandatory = True), |
| 1292 | "host_system_name": attr.string(mandatory = True), |
| 1293 | "target_system_name": attr.string(mandatory = True), |
| 1294 | "target_libc": attr.string(mandatory = True), |
| 1295 | "abi_version": attr.string(mandatory = True), |
| 1296 | "abi_libc_version": attr.string(mandatory = True), |
| 1297 | "cxx_builtin_include_directories": attr.string_list(), |
| 1298 | "tool_paths": attr.string_dict(), |
| 1299 | "compile_flags": attr.string_list(), |
| 1300 | "dbg_compile_flags": attr.string_list(), |
| 1301 | "opt_compile_flags": attr.string_list(), |
| 1302 | "cxx_flags": attr.string_list(), |
| 1303 | "link_flags": attr.string_list(), |
Marcel Hlopko | ab9c1f5 | 2019-06-19 00:45:58 -0700 | [diff] [blame] | 1304 | "link_libs": attr.string_list(), |
rosica | 96500b7 | 2019-05-21 03:25:53 -0700 | [diff] [blame] | 1305 | "opt_link_flags": attr.string_list(), |
| 1306 | "unfiltered_compile_flags": attr.string_list(), |
| 1307 | "coverage_compile_flags": attr.string_list(), |
| 1308 | "coverage_link_flags": attr.string_list(), |
| 1309 | "supports_start_end_lib": attr.bool(), |
erenon | da345f1 | 2020-10-29 08:25:15 -0700 | [diff] [blame] | 1310 | "builtin_sysroot": attr.string(), |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 1311 | }, |
| 1312 | provides = [CcToolchainConfigInfo], |
| 1313 | ) |