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