github.com/distbuild/reclient@v0.0.0-20240401075343-3de72e395564/configs/windows/cc/windows_cc_toolchain_config.bzl (about) 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 for Windows""" 16 17 load( 18 "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", 19 "action_config", 20 "artifact_name_pattern", 21 "env_entry", 22 "env_set", 23 "feature", 24 "flag_group", 25 "flag_set", 26 "tool", 27 "tool_path", 28 "variable_with_value", 29 "with_feature_set", 30 ) 31 load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") 32 33 all_compile_actions = [ 34 ACTION_NAMES.c_compile, 35 ACTION_NAMES.cpp_compile, 36 ACTION_NAMES.linkstamp_compile, 37 ACTION_NAMES.assemble, 38 ACTION_NAMES.preprocess_assemble, 39 ACTION_NAMES.cpp_header_parsing, 40 ACTION_NAMES.cpp_module_compile, 41 ACTION_NAMES.cpp_module_codegen, 42 ACTION_NAMES.clif_match, 43 ACTION_NAMES.lto_backend, 44 ] 45 46 all_cpp_compile_actions = [ 47 ACTION_NAMES.cpp_compile, 48 ACTION_NAMES.linkstamp_compile, 49 ACTION_NAMES.cpp_header_parsing, 50 ACTION_NAMES.cpp_module_compile, 51 ACTION_NAMES.cpp_module_codegen, 52 ACTION_NAMES.clif_match, 53 ] 54 55 preprocessor_compile_actions = [ 56 ACTION_NAMES.c_compile, 57 ACTION_NAMES.cpp_compile, 58 ACTION_NAMES.linkstamp_compile, 59 ACTION_NAMES.preprocess_assemble, 60 ACTION_NAMES.cpp_header_parsing, 61 ACTION_NAMES.cpp_module_compile, 62 ACTION_NAMES.clif_match, 63 ] 64 65 codegen_compile_actions = [ 66 ACTION_NAMES.c_compile, 67 ACTION_NAMES.cpp_compile, 68 ACTION_NAMES.linkstamp_compile, 69 ACTION_NAMES.assemble, 70 ACTION_NAMES.preprocess_assemble, 71 ACTION_NAMES.cpp_module_codegen, 72 ACTION_NAMES.lto_backend, 73 ] 74 75 all_link_actions = [ 76 ACTION_NAMES.cpp_link_executable, 77 ACTION_NAMES.cpp_link_dynamic_library, 78 ACTION_NAMES.cpp_link_nodeps_dynamic_library, 79 ] 80 81 def _use_msvc_toolchain(ctx): 82 return ctx.attr.cpu in ["x64_windows", "arm64_windows"] and (ctx.attr.compiler == "msvc-cl" or ctx.attr.compiler == "clang-cl") 83 84 def _impl(ctx): 85 if _use_msvc_toolchain(ctx): 86 artifact_name_patterns = [ 87 artifact_name_pattern( 88 category_name = "object_file", 89 prefix = "", 90 extension = ".obj", 91 ), 92 artifact_name_pattern( 93 category_name = "static_library", 94 prefix = "", 95 extension = ".lib", 96 ), 97 artifact_name_pattern( 98 category_name = "alwayslink_static_library", 99 prefix = "", 100 extension = ".lo.lib", 101 ), 102 artifact_name_pattern( 103 category_name = "executable", 104 prefix = "", 105 extension = ".exe", 106 ), 107 artifact_name_pattern( 108 category_name = "dynamic_library", 109 prefix = "", 110 extension = ".dll", 111 ), 112 artifact_name_pattern( 113 category_name = "interface_library", 114 prefix = "", 115 extension = ".if.lib", 116 ), 117 ] 118 else: 119 artifact_name_patterns = [ 120 artifact_name_pattern( 121 category_name = "executable", 122 prefix = "", 123 extension = ".exe", 124 ), 125 ] 126 127 if _use_msvc_toolchain(ctx): 128 cpp_link_nodeps_dynamic_library_action = action_config( 129 action_name = ACTION_NAMES.cpp_link_nodeps_dynamic_library, 130 implies = [ 131 "nologo", 132 "shared_flag", 133 "linkstamps", 134 "output_execpath_flags", 135 "input_param_flags", 136 "user_link_flags", 137 "linker_subsystem_flag", 138 "linker_param_file", 139 "msvc_env", 140 "no_stripping", 141 "has_configured_linker_path", 142 "def_file", 143 ], 144 tools = [tool(path = ctx.attr.msvc_link_path)], 145 ) 146 147 cpp_link_static_library_action = action_config( 148 action_name = ACTION_NAMES.cpp_link_static_library, 149 implies = [ 150 "nologo", 151 "archiver_flags", 152 "input_param_flags", 153 "linker_param_file", 154 "msvc_env", 155 ], 156 tools = [tool(path = ctx.attr.msvc_lib_path)], 157 ) 158 159 assemble_action = action_config( 160 action_name = ACTION_NAMES.assemble, 161 implies = [ 162 "compiler_input_flags", 163 "compiler_output_flags", 164 "nologo", 165 "msvc_env", 166 "sysroot", 167 ], 168 tools = [tool(path = ctx.attr.msvc_ml_path)], 169 ) 170 171 preprocess_assemble_action = action_config( 172 action_name = ACTION_NAMES.preprocess_assemble, 173 implies = [ 174 "compiler_input_flags", 175 "compiler_output_flags", 176 "nologo", 177 "msvc_env", 178 "sysroot", 179 ], 180 tools = [tool(path = ctx.attr.msvc_ml_path)], 181 ) 182 183 c_compile_action = action_config( 184 action_name = ACTION_NAMES.c_compile, 185 implies = [ 186 "compiler_input_flags", 187 "compiler_output_flags", 188 "nologo", 189 "msvc_env", 190 "parse_showincludes", 191 "user_compile_flags", 192 "sysroot", 193 ], 194 tools = [tool(path = ctx.attr.msvc_cl_path)], 195 ) 196 197 linkstamp_compile_action = action_config( 198 action_name = ACTION_NAMES.linkstamp_compile, 199 implies = [ 200 "compiler_input_flags", 201 "compiler_output_flags", 202 "default_compile_flags", 203 "nologo", 204 "msvc_env", 205 "parse_showincludes", 206 "user_compile_flags", 207 "sysroot", 208 "unfiltered_compile_flags", 209 ], 210 tools = [tool(path = ctx.attr.msvc_cl_path)], 211 ) 212 213 cpp_compile_action = action_config( 214 action_name = ACTION_NAMES.cpp_compile, 215 implies = [ 216 "compiler_input_flags", 217 "compiler_output_flags", 218 "nologo", 219 "msvc_env", 220 "parse_showincludes", 221 "user_compile_flags", 222 "sysroot", 223 ], 224 tools = [tool(path = ctx.attr.msvc_cl_path)], 225 ) 226 227 cpp_link_executable_action = action_config( 228 action_name = ACTION_NAMES.cpp_link_executable, 229 implies = [ 230 "nologo", 231 "linkstamps", 232 "output_execpath_flags", 233 "input_param_flags", 234 "user_link_flags", 235 "linker_subsystem_flag", 236 "linker_param_file", 237 "msvc_env", 238 "no_stripping", 239 ], 240 tools = [tool(path = ctx.attr.msvc_link_path)], 241 ) 242 243 cpp_link_dynamic_library_action = action_config( 244 action_name = ACTION_NAMES.cpp_link_dynamic_library, 245 implies = [ 246 "nologo", 247 "shared_flag", 248 "linkstamps", 249 "output_execpath_flags", 250 "input_param_flags", 251 "user_link_flags", 252 "linker_subsystem_flag", 253 "linker_param_file", 254 "msvc_env", 255 "no_stripping", 256 "has_configured_linker_path", 257 "def_file", 258 ], 259 tools = [tool(path = ctx.attr.msvc_link_path)], 260 ) 261 262 action_configs = [ 263 assemble_action, 264 preprocess_assemble_action, 265 c_compile_action, 266 linkstamp_compile_action, 267 cpp_compile_action, 268 cpp_link_executable_action, 269 cpp_link_dynamic_library_action, 270 cpp_link_nodeps_dynamic_library_action, 271 cpp_link_static_library_action, 272 ] 273 else: 274 action_configs = [] 275 276 if _use_msvc_toolchain(ctx): 277 msvc_link_env_feature = feature( 278 name = "msvc_link_env", 279 env_sets = [ 280 env_set( 281 actions = all_link_actions + 282 [ACTION_NAMES.cpp_link_static_library], 283 env_entries = [env_entry(key = "LIB", value = ctx.attr.msvc_env_lib)], 284 ), 285 ], 286 ) 287 288 shared_flag_feature = feature( 289 name = "shared_flag", 290 flag_sets = [ 291 flag_set( 292 actions = [ 293 ACTION_NAMES.cpp_link_dynamic_library, 294 ACTION_NAMES.cpp_link_nodeps_dynamic_library, 295 ], 296 flag_groups = [flag_group(flags = ["/DLL"])], 297 ), 298 ], 299 ) 300 301 determinism_feature = feature( 302 name = "determinism", 303 enabled = True, 304 flag_sets = [ 305 flag_set( 306 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 307 flag_groups = [ 308 flag_group( 309 flags = [ 310 "/wd4117", 311 "-D__DATE__=\"redacted\"", 312 "-D__TIMESTAMP__=\"redacted\"", 313 "-D__TIME__=\"redacted\"", 314 ] + (["-Wno-builtin-macro-redefined"] if ctx.attr.compiler == "clang-cl" else []), 315 ), 316 ], 317 ), 318 ], 319 ) 320 321 sysroot_feature = feature( 322 name = "sysroot", 323 flag_sets = [ 324 flag_set( 325 actions = [ 326 ACTION_NAMES.assemble, 327 ACTION_NAMES.preprocess_assemble, 328 ACTION_NAMES.c_compile, 329 ACTION_NAMES.linkstamp_compile, 330 ACTION_NAMES.cpp_compile, 331 ACTION_NAMES.cpp_header_parsing, 332 ACTION_NAMES.cpp_module_compile, 333 ACTION_NAMES.cpp_module_codegen, 334 ACTION_NAMES.cpp_link_executable, 335 ACTION_NAMES.cpp_link_dynamic_library, 336 ACTION_NAMES.cpp_link_nodeps_dynamic_library, 337 ], 338 flag_groups = [ 339 flag_group( 340 flags = ["--sysroot=%{sysroot}"], 341 iterate_over = "sysroot", 342 expand_if_available = "sysroot", 343 ), 344 ], 345 ), 346 ], 347 ) 348 349 unfiltered_compile_flags_feature = feature( 350 name = "unfiltered_compile_flags", 351 enabled = True, 352 flag_sets = [ 353 flag_set( 354 actions = [ 355 ACTION_NAMES.preprocess_assemble, 356 ACTION_NAMES.c_compile, 357 ACTION_NAMES.linkstamp_compile, 358 ACTION_NAMES.cpp_compile, 359 ACTION_NAMES.cpp_header_parsing, 360 ACTION_NAMES.cpp_module_compile, 361 ACTION_NAMES.cpp_module_codegen, 362 ], 363 flag_groups = [ 364 flag_group( 365 flags = ["%{unfiltered_compile_flags}"], 366 iterate_over = "unfiltered_compile_flags", 367 expand_if_available = "unfiltered_compile_flags", 368 ), 369 ], 370 ), 371 ], 372 ) 373 374 archive_param_file_feature = feature( 375 name = "archive_param_file", 376 enabled = True, 377 ) 378 379 compiler_param_file_feature = feature( 380 name = "compiler_param_file", 381 ) 382 383 copy_dynamic_libraries_to_binary_feature = feature( 384 name = "copy_dynamic_libraries_to_binary", 385 ) 386 387 input_param_flags_feature = feature( 388 name = "input_param_flags", 389 flag_sets = [ 390 flag_set( 391 actions = [ 392 ACTION_NAMES.cpp_link_dynamic_library, 393 ACTION_NAMES.cpp_link_nodeps_dynamic_library, 394 ], 395 flag_groups = [ 396 flag_group( 397 flags = ["/IMPLIB:%{interface_library_output_path}"], 398 expand_if_available = "interface_library_output_path", 399 ), 400 ], 401 ), 402 flag_set( 403 actions = all_link_actions, 404 flag_groups = [ 405 flag_group( 406 flags = ["%{libopts}"], 407 iterate_over = "libopts", 408 expand_if_available = "libopts", 409 ), 410 ], 411 ), 412 flag_set( 413 actions = all_link_actions + 414 [ACTION_NAMES.cpp_link_static_library], 415 flag_groups = [ 416 flag_group( 417 iterate_over = "libraries_to_link", 418 flag_groups = [ 419 flag_group( 420 iterate_over = "libraries_to_link.object_files", 421 flag_groups = [flag_group(flags = ["%{libraries_to_link.object_files}"])], 422 expand_if_equal = variable_with_value( 423 name = "libraries_to_link.type", 424 value = "object_file_group", 425 ), 426 ), 427 flag_group( 428 flag_groups = [flag_group(flags = ["%{libraries_to_link.name}"])], 429 expand_if_equal = variable_with_value( 430 name = "libraries_to_link.type", 431 value = "object_file", 432 ), 433 ), 434 flag_group( 435 flag_groups = [flag_group(flags = ["%{libraries_to_link.name}"])], 436 expand_if_equal = variable_with_value( 437 name = "libraries_to_link.type", 438 value = "interface_library", 439 ), 440 ), 441 flag_group( 442 flag_groups = [ 443 flag_group( 444 flags = ["%{libraries_to_link.name}"], 445 expand_if_false = "libraries_to_link.is_whole_archive", 446 ), 447 flag_group( 448 flags = ["/WHOLEARCHIVE:%{libraries_to_link.name}"], 449 expand_if_true = "libraries_to_link.is_whole_archive", 450 ), 451 ], 452 expand_if_equal = variable_with_value( 453 name = "libraries_to_link.type", 454 value = "static_library", 455 ), 456 ), 457 ], 458 expand_if_available = "libraries_to_link", 459 ), 460 ], 461 ), 462 ], 463 ) 464 465 fastbuild_feature = feature( 466 name = "fastbuild", 467 flag_sets = [ 468 flag_set( 469 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 470 flag_groups = [flag_group(flags = ["/Od", "/Z7"])], 471 ), 472 flag_set( 473 actions = all_link_actions, 474 flag_groups = [ 475 flag_group( 476 flags = [ctx.attr.fastbuild_mode_debug_flag, "/INCREMENTAL:NO"], 477 ), 478 ], 479 ), 480 ], 481 implies = ["generate_pdb_file"], 482 ) 483 484 user_compile_flags_feature = feature( 485 name = "user_compile_flags", 486 flag_sets = [ 487 flag_set( 488 actions = [ 489 ACTION_NAMES.preprocess_assemble, 490 ACTION_NAMES.c_compile, 491 ACTION_NAMES.linkstamp_compile, 492 ACTION_NAMES.cpp_compile, 493 ACTION_NAMES.cpp_header_parsing, 494 ACTION_NAMES.cpp_module_compile, 495 ACTION_NAMES.cpp_module_codegen, 496 ], 497 flag_groups = [ 498 flag_group( 499 flags = ["%{user_compile_flags}"], 500 iterate_over = "user_compile_flags", 501 expand_if_available = "user_compile_flags", 502 ), 503 ], 504 ), 505 ], 506 ) 507 508 archiver_flags_feature = feature( 509 name = "archiver_flags", 510 flag_sets = [ 511 flag_set( 512 actions = [ACTION_NAMES.cpp_link_static_library], 513 flag_groups = [ 514 flag_group( 515 flags = ["/OUT:%{output_execpath}"], 516 expand_if_available = "output_execpath", 517 ), 518 flag_group( 519 flags = ctx.attr.archiver_flags, 520 ), 521 ], 522 ), 523 ], 524 ) 525 526 default_link_flags_feature = feature( 527 name = "default_link_flags", 528 enabled = True, 529 flag_sets = [ 530 flag_set( 531 actions = all_link_actions, 532 flag_groups = [flag_group(flags = ctx.attr.default_link_flags)], 533 ), 534 ], 535 ) 536 537 static_link_msvcrt_feature = feature( 538 name = "static_link_msvcrt", 539 flag_sets = [ 540 flag_set( 541 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 542 flag_groups = [flag_group(flags = ["/MT"])], 543 with_features = [with_feature_set(not_features = ["dbg"])], 544 ), 545 flag_set( 546 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 547 flag_groups = [flag_group(flags = ["/MTd"])], 548 with_features = [with_feature_set(features = ["dbg"])], 549 ), 550 flag_set( 551 actions = all_link_actions, 552 flag_groups = [flag_group(flags = ["/DEFAULTLIB:libcmt.lib"])], 553 with_features = [with_feature_set(not_features = ["dbg"])], 554 ), 555 flag_set( 556 actions = all_link_actions, 557 flag_groups = [flag_group(flags = ["/DEFAULTLIB:libcmtd.lib"])], 558 with_features = [with_feature_set(features = ["dbg"])], 559 ), 560 ], 561 ) 562 563 dynamic_link_msvcrt_feature = feature( 564 name = "dynamic_link_msvcrt", 565 enabled = True, 566 flag_sets = [ 567 flag_set( 568 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 569 flag_groups = [flag_group(flags = ["/MD"])], 570 with_features = [with_feature_set(not_features = ["dbg", "static_link_msvcrt"])], 571 ), 572 flag_set( 573 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 574 flag_groups = [flag_group(flags = ["/MDd"])], 575 with_features = [with_feature_set(features = ["dbg"], not_features = ["static_link_msvcrt"])], 576 ), 577 flag_set( 578 actions = all_link_actions, 579 flag_groups = [flag_group(flags = ["/DEFAULTLIB:msvcrt.lib"])], 580 with_features = [with_feature_set(not_features = ["dbg", "static_link_msvcrt"])], 581 ), 582 flag_set( 583 actions = all_link_actions, 584 flag_groups = [flag_group(flags = ["/DEFAULTLIB:msvcrtd.lib"])], 585 with_features = [with_feature_set(features = ["dbg"], not_features = ["static_link_msvcrt"])], 586 ), 587 ], 588 ) 589 590 dbg_feature = feature( 591 name = "dbg", 592 flag_sets = [ 593 flag_set( 594 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 595 flag_groups = [flag_group(flags = ["/Od", "/Z7"])], 596 ), 597 flag_set( 598 actions = all_link_actions, 599 flag_groups = [ 600 flag_group( 601 flags = [ctx.attr.dbg_mode_debug_flag, "/INCREMENTAL:NO"], 602 ), 603 ], 604 ), 605 ], 606 implies = ["generate_pdb_file"], 607 ) 608 609 opt_feature = feature( 610 name = "opt", 611 flag_sets = [ 612 flag_set( 613 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 614 flag_groups = [flag_group(flags = ["/O2"])], 615 ), 616 ], 617 implies = ["frame_pointer"], 618 ) 619 620 supports_interface_shared_libraries_feature = feature( 621 name = "supports_interface_shared_libraries", 622 enabled = True, 623 ) 624 625 user_link_flags_feature = feature( 626 name = "user_link_flags", 627 flag_sets = [ 628 flag_set( 629 actions = all_link_actions, 630 flag_groups = [ 631 flag_group( 632 flags = ["%{user_link_flags}"], 633 iterate_over = "user_link_flags", 634 expand_if_available = "user_link_flags", 635 ), 636 ], 637 ), 638 ], 639 ) 640 641 default_compile_flags_feature = feature( 642 name = "default_compile_flags", 643 enabled = True, 644 flag_sets = [ 645 flag_set( 646 actions = [ 647 ACTION_NAMES.assemble, 648 ACTION_NAMES.preprocess_assemble, 649 ACTION_NAMES.linkstamp_compile, 650 ACTION_NAMES.c_compile, 651 ACTION_NAMES.cpp_compile, 652 ACTION_NAMES.cpp_header_parsing, 653 ACTION_NAMES.cpp_module_compile, 654 ACTION_NAMES.cpp_module_codegen, 655 ACTION_NAMES.lto_backend, 656 ACTION_NAMES.clif_match, 657 ], 658 flag_groups = [ 659 flag_group( 660 flags = [ 661 "/DCOMPILER_MSVC", 662 "/DNOMINMAX", 663 "/D_WIN32_WINNT=0x0601", 664 "/D_CRT_SECURE_NO_DEPRECATE", 665 "/D_CRT_SECURE_NO_WARNINGS", 666 "/bigobj", 667 "/Zm500", 668 "/EHsc", 669 "/wd4351", 670 "/wd4291", 671 "/wd4250", 672 "/wd4996", 673 ], 674 ), 675 ], 676 ), 677 ], 678 ) 679 680 msvc_compile_env_feature = feature( 681 name = "msvc_compile_env", 682 env_sets = [ 683 env_set( 684 actions = [ 685 ACTION_NAMES.c_compile, 686 ACTION_NAMES.linkstamp_compile, 687 ACTION_NAMES.cpp_compile, 688 ACTION_NAMES.cpp_module_compile, 689 ACTION_NAMES.cpp_module_codegen, 690 ACTION_NAMES.cpp_header_parsing, 691 ACTION_NAMES.assemble, 692 ACTION_NAMES.preprocess_assemble, 693 ], 694 env_entries = [env_entry(key = "INCLUDE", value = ctx.attr.msvc_env_include)], 695 ), 696 ], 697 ) 698 699 preprocessor_defines_feature = feature( 700 name = "preprocessor_defines", 701 enabled = True, 702 flag_sets = [ 703 flag_set( 704 actions = [ 705 ACTION_NAMES.assemble, 706 ACTION_NAMES.preprocess_assemble, 707 ACTION_NAMES.c_compile, 708 ACTION_NAMES.linkstamp_compile, 709 ACTION_NAMES.cpp_compile, 710 ACTION_NAMES.cpp_header_parsing, 711 ACTION_NAMES.cpp_module_compile, 712 ], 713 flag_groups = [ 714 flag_group( 715 flags = ["/D%{preprocessor_defines}"], 716 iterate_over = "preprocessor_defines", 717 ), 718 ], 719 ), 720 ], 721 ) 722 723 generate_pdb_file_feature = feature( 724 name = "generate_pdb_file", 725 ) 726 727 output_execpath_flags_feature = feature( 728 name = "output_execpath_flags", 729 flag_sets = [ 730 flag_set( 731 actions = all_link_actions, 732 flag_groups = [ 733 flag_group( 734 flags = ["/OUT:%{output_execpath}"], 735 expand_if_available = "output_execpath", 736 ), 737 ], 738 ), 739 ], 740 ) 741 742 disable_assertions_feature = feature( 743 name = "disable_assertions", 744 enabled = True, 745 flag_sets = [ 746 flag_set( 747 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 748 flag_groups = [flag_group(flags = ["/DNDEBUG"])], 749 with_features = [with_feature_set(features = ["opt"])], 750 ), 751 ], 752 ) 753 754 has_configured_linker_path_feature = feature(name = "has_configured_linker_path") 755 756 supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) 757 758 no_stripping_feature = feature(name = "no_stripping") 759 760 linker_param_file_feature = feature( 761 name = "linker_param_file", 762 flag_sets = [ 763 flag_set( 764 actions = all_link_actions + 765 [ACTION_NAMES.cpp_link_static_library], 766 flag_groups = [ 767 flag_group( 768 flags = ["@%{linker_param_file}"], 769 expand_if_available = "linker_param_file", 770 ), 771 ], 772 ), 773 ], 774 ) 775 776 ignore_noisy_warnings_feature = feature( 777 name = "ignore_noisy_warnings", 778 enabled = True, 779 flag_sets = [ 780 flag_set( 781 actions = [ACTION_NAMES.cpp_link_static_library], 782 flag_groups = [flag_group(flags = ["/ignore:4221"])], 783 ), 784 ], 785 ) 786 787 no_legacy_features_feature = feature(name = "no_legacy_features") 788 789 parse_showincludes_feature = feature( 790 name = "parse_showincludes", 791 flag_sets = [ 792 flag_set( 793 actions = [ 794 ACTION_NAMES.preprocess_assemble, 795 ACTION_NAMES.c_compile, 796 ACTION_NAMES.linkstamp_compile, 797 ACTION_NAMES.cpp_compile, 798 ACTION_NAMES.cpp_module_compile, 799 ACTION_NAMES.cpp_header_parsing, 800 ], 801 flag_groups = [flag_group(flags = ["/showIncludes"])], 802 ), 803 ], 804 ) 805 806 treat_warnings_as_errors_feature = feature( 807 name = "treat_warnings_as_errors", 808 flag_sets = [ 809 flag_set( 810 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile] + all_link_actions, 811 flag_groups = [flag_group(flags = ["/WX"])], 812 ), 813 ], 814 ) 815 816 windows_export_all_symbols_feature = feature(name = "windows_export_all_symbols") 817 818 no_windows_export_all_symbols_feature = feature(name = "no_windows_export_all_symbols") 819 820 include_paths_feature = feature( 821 name = "include_paths", 822 enabled = True, 823 flag_sets = [ 824 flag_set( 825 actions = [ 826 ACTION_NAMES.assemble, 827 ACTION_NAMES.preprocess_assemble, 828 ACTION_NAMES.c_compile, 829 ACTION_NAMES.linkstamp_compile, 830 ACTION_NAMES.cpp_compile, 831 ACTION_NAMES.cpp_header_parsing, 832 ACTION_NAMES.cpp_module_compile, 833 ], 834 flag_groups = [ 835 flag_group( 836 flags = ["/I%{quote_include_paths}"], 837 iterate_over = "quote_include_paths", 838 ), 839 flag_group( 840 flags = ["/I%{include_paths}"], 841 iterate_over = "include_paths", 842 ), 843 flag_group( 844 flags = ["/I%{system_include_paths}"], 845 iterate_over = "system_include_paths", 846 ), 847 ], 848 ), 849 ], 850 ) 851 852 external_include_paths_feature = feature( 853 name = "external_include_paths", 854 flag_sets = [ 855 flag_set( 856 actions = [ 857 ACTION_NAMES.preprocess_assemble, 858 ACTION_NAMES.linkstamp_compile, 859 ACTION_NAMES.c_compile, 860 ACTION_NAMES.cpp_compile, 861 ACTION_NAMES.cpp_header_parsing, 862 ACTION_NAMES.cpp_module_compile, 863 ACTION_NAMES.clif_match, 864 ACTION_NAMES.objc_compile, 865 ACTION_NAMES.objcpp_compile, 866 ], 867 flag_groups = [ 868 flag_group( 869 flags = ["/external:I", "%{external_include_paths}"], 870 iterate_over = "external_include_paths", 871 expand_if_available = "external_include_paths", 872 ), 873 ], 874 ), 875 ], 876 ) 877 878 linkstamps_feature = feature( 879 name = "linkstamps", 880 flag_sets = [ 881 flag_set( 882 actions = all_link_actions, 883 flag_groups = [ 884 flag_group( 885 flags = ["%{linkstamp_paths}"], 886 iterate_over = "linkstamp_paths", 887 expand_if_available = "linkstamp_paths", 888 ), 889 ], 890 ), 891 ], 892 ) 893 894 targets_windows_feature = feature( 895 name = "targets_windows", 896 enabled = True, 897 implies = ["copy_dynamic_libraries_to_binary"], 898 ) 899 900 linker_subsystem_flag_feature = feature( 901 name = "linker_subsystem_flag", 902 flag_sets = [ 903 flag_set( 904 actions = all_link_actions, 905 flag_groups = [flag_group(flags = ["/SUBSYSTEM:CONSOLE"])], 906 ), 907 ], 908 ) 909 910 frame_pointer_feature = feature( 911 name = "frame_pointer", 912 flag_sets = [ 913 flag_set( 914 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 915 flag_groups = [flag_group(flags = ["/Oy-"])], 916 ), 917 ], 918 ) 919 920 compiler_output_flags_feature = feature( 921 name = "compiler_output_flags", 922 flag_sets = [ 923 flag_set( 924 actions = [ACTION_NAMES.assemble], 925 flag_groups = [ 926 flag_group( 927 flag_groups = [ 928 flag_group( 929 flags = ["/Fo%{output_file}", "/Zi"], 930 expand_if_available = "output_file", 931 expand_if_not_available = "output_assembly_file", 932 ), 933 ], 934 expand_if_not_available = "output_preprocess_file", 935 ), 936 ], 937 ), 938 flag_set( 939 actions = [ 940 ACTION_NAMES.preprocess_assemble, 941 ACTION_NAMES.c_compile, 942 ACTION_NAMES.linkstamp_compile, 943 ACTION_NAMES.cpp_compile, 944 ACTION_NAMES.cpp_header_parsing, 945 ACTION_NAMES.cpp_module_compile, 946 ACTION_NAMES.cpp_module_codegen, 947 ], 948 flag_groups = [ 949 flag_group( 950 flag_groups = [ 951 flag_group( 952 flags = ["/Fo%{output_file}"], 953 expand_if_not_available = "output_preprocess_file", 954 ), 955 ], 956 expand_if_available = "output_file", 957 expand_if_not_available = "output_assembly_file", 958 ), 959 flag_group( 960 flag_groups = [ 961 flag_group( 962 flags = ["/Fa%{output_file}"], 963 expand_if_available = "output_assembly_file", 964 ), 965 ], 966 expand_if_available = "output_file", 967 ), 968 flag_group( 969 flag_groups = [ 970 flag_group( 971 flags = ["/P", "/Fi%{output_file}"], 972 expand_if_available = "output_preprocess_file", 973 ), 974 ], 975 expand_if_available = "output_file", 976 ), 977 ], 978 ), 979 ], 980 ) 981 982 nologo_feature = feature( 983 name = "nologo", 984 flag_sets = [ 985 flag_set( 986 actions = [ 987 ACTION_NAMES.c_compile, 988 ACTION_NAMES.linkstamp_compile, 989 ACTION_NAMES.cpp_compile, 990 ACTION_NAMES.cpp_module_compile, 991 ACTION_NAMES.cpp_module_codegen, 992 ACTION_NAMES.cpp_header_parsing, 993 ACTION_NAMES.assemble, 994 ACTION_NAMES.preprocess_assemble, 995 ACTION_NAMES.cpp_link_executable, 996 ACTION_NAMES.cpp_link_dynamic_library, 997 ACTION_NAMES.cpp_link_nodeps_dynamic_library, 998 ACTION_NAMES.cpp_link_static_library, 999 ], 1000 flag_groups = [flag_group(flags = ["/nologo"])], 1001 ), 1002 ], 1003 ) 1004 1005 smaller_binary_feature = feature( 1006 name = "smaller_binary", 1007 enabled = True, 1008 flag_sets = [ 1009 flag_set( 1010 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 1011 flag_groups = [flag_group(flags = ["/Gy", "/Gw"])], 1012 with_features = [with_feature_set(features = ["opt"])], 1013 ), 1014 flag_set( 1015 actions = all_link_actions, 1016 flag_groups = [flag_group(flags = ["/OPT:ICF", "/OPT:REF"])], 1017 with_features = [with_feature_set(features = ["opt"])], 1018 ), 1019 ], 1020 ) 1021 1022 compiler_input_flags_feature = feature( 1023 name = "compiler_input_flags", 1024 flag_sets = [ 1025 flag_set( 1026 actions = [ 1027 ACTION_NAMES.assemble, 1028 ACTION_NAMES.preprocess_assemble, 1029 ACTION_NAMES.c_compile, 1030 ACTION_NAMES.linkstamp_compile, 1031 ACTION_NAMES.cpp_compile, 1032 ACTION_NAMES.cpp_header_parsing, 1033 ACTION_NAMES.cpp_module_compile, 1034 ACTION_NAMES.cpp_module_codegen, 1035 ], 1036 flag_groups = [ 1037 flag_group( 1038 flags = ["/c", "%{source_file}"], 1039 expand_if_available = "source_file", 1040 ), 1041 ], 1042 ), 1043 ], 1044 ) 1045 1046 def_file_feature = feature( 1047 name = "def_file", 1048 flag_sets = [ 1049 flag_set( 1050 actions = all_link_actions, 1051 flag_groups = [ 1052 flag_group( 1053 flags = ["/DEF:%{def_file_path}", "/ignore:4070"], 1054 expand_if_available = "def_file_path", 1055 ), 1056 ], 1057 ), 1058 ], 1059 ) 1060 1061 msvc_env_feature = feature( 1062 name = "msvc_env", 1063 env_sets = [ 1064 env_set( 1065 actions = [ 1066 ACTION_NAMES.c_compile, 1067 ACTION_NAMES.linkstamp_compile, 1068 ACTION_NAMES.cpp_compile, 1069 ACTION_NAMES.cpp_module_compile, 1070 ACTION_NAMES.cpp_module_codegen, 1071 ACTION_NAMES.cpp_header_parsing, 1072 ACTION_NAMES.assemble, 1073 ACTION_NAMES.preprocess_assemble, 1074 ACTION_NAMES.cpp_link_executable, 1075 ACTION_NAMES.cpp_link_dynamic_library, 1076 ACTION_NAMES.cpp_link_nodeps_dynamic_library, 1077 ACTION_NAMES.cpp_link_static_library, 1078 ], 1079 env_entries = [ 1080 env_entry(key = "PATH", value = ctx.attr.msvc_env_path), 1081 env_entry(key = "TMP", value = ctx.attr.msvc_env_tmp), 1082 env_entry(key = "TEMP", value = ctx.attr.msvc_env_tmp), 1083 ], 1084 ), 1085 ], 1086 implies = ["msvc_compile_env", "msvc_link_env"], 1087 ) 1088 features = [ 1089 no_legacy_features_feature, 1090 nologo_feature, 1091 has_configured_linker_path_feature, 1092 no_stripping_feature, 1093 targets_windows_feature, 1094 copy_dynamic_libraries_to_binary_feature, 1095 default_compile_flags_feature, 1096 msvc_env_feature, 1097 msvc_compile_env_feature, 1098 msvc_link_env_feature, 1099 include_paths_feature, 1100 external_include_paths_feature, 1101 preprocessor_defines_feature, 1102 parse_showincludes_feature, 1103 generate_pdb_file_feature, 1104 shared_flag_feature, 1105 linkstamps_feature, 1106 output_execpath_flags_feature, 1107 archiver_flags_feature, 1108 input_param_flags_feature, 1109 linker_subsystem_flag_feature, 1110 user_link_flags_feature, 1111 default_link_flags_feature, 1112 linker_param_file_feature, 1113 static_link_msvcrt_feature, 1114 dynamic_link_msvcrt_feature, 1115 dbg_feature, 1116 fastbuild_feature, 1117 opt_feature, 1118 frame_pointer_feature, 1119 disable_assertions_feature, 1120 determinism_feature, 1121 treat_warnings_as_errors_feature, 1122 smaller_binary_feature, 1123 ignore_noisy_warnings_feature, 1124 user_compile_flags_feature, 1125 sysroot_feature, 1126 unfiltered_compile_flags_feature, 1127 archive_param_file_feature, 1128 compiler_param_file_feature, 1129 compiler_output_flags_feature, 1130 compiler_input_flags_feature, 1131 def_file_feature, 1132 windows_export_all_symbols_feature, 1133 no_windows_export_all_symbols_feature, 1134 supports_dynamic_linker_feature, 1135 supports_interface_shared_libraries_feature, 1136 ] 1137 else: 1138 targets_windows_feature = feature( 1139 name = "targets_windows", 1140 implies = ["copy_dynamic_libraries_to_binary"], 1141 enabled = True, 1142 ) 1143 1144 copy_dynamic_libraries_to_binary_feature = feature(name = "copy_dynamic_libraries_to_binary") 1145 1146 gcc_env_feature = feature( 1147 name = "gcc_env", 1148 enabled = True, 1149 env_sets = [ 1150 env_set( 1151 actions = [ 1152 ACTION_NAMES.c_compile, 1153 ACTION_NAMES.linkstamp_compile, 1154 ACTION_NAMES.cpp_compile, 1155 ACTION_NAMES.cpp_module_compile, 1156 ACTION_NAMES.cpp_module_codegen, 1157 ACTION_NAMES.cpp_header_parsing, 1158 ACTION_NAMES.assemble, 1159 ACTION_NAMES.preprocess_assemble, 1160 ACTION_NAMES.cpp_link_executable, 1161 ACTION_NAMES.cpp_link_dynamic_library, 1162 ACTION_NAMES.cpp_link_nodeps_dynamic_library, 1163 ACTION_NAMES.cpp_link_static_library, 1164 ], 1165 env_entries = [ 1166 env_entry(key = "PATH", value = ctx.attr.tool_bin_path), 1167 ], 1168 ), 1169 ], 1170 ) 1171 1172 default_compile_flags_feature = feature( 1173 name = "default_compile_flags", 1174 enabled = True, 1175 flag_sets = [ 1176 flag_set( 1177 actions = [ 1178 ACTION_NAMES.linkstamp_compile, 1179 ACTION_NAMES.cpp_compile, 1180 ACTION_NAMES.cpp_header_parsing, 1181 ACTION_NAMES.cpp_module_compile, 1182 ACTION_NAMES.cpp_module_codegen, 1183 ACTION_NAMES.lto_backend, 1184 ACTION_NAMES.clif_match, 1185 ], 1186 flag_groups = [flag_group(flags = ["-std=gnu++0x"])], 1187 ), 1188 ], 1189 ) 1190 1191 default_link_flags_feature = feature( 1192 name = "default_link_flags", 1193 enabled = True, 1194 flag_sets = [ 1195 flag_set( 1196 actions = all_link_actions, 1197 flag_groups = [flag_group(flags = ["-lstdc++"])], 1198 ), 1199 ], 1200 ) 1201 1202 supports_dynamic_linker_feature = feature( 1203 name = "supports_dynamic_linker", 1204 enabled = True, 1205 ) 1206 1207 dbg_feature = feature( 1208 name = "dbg", 1209 flag_sets = [ 1210 flag_set( 1211 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 1212 flag_groups = [flag_group(flags = ["-g", "-Og"])], 1213 ), 1214 ], 1215 ) 1216 1217 opt_feature = feature( 1218 name = "opt", 1219 flag_sets = [ 1220 flag_set( 1221 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 1222 flag_groups = [flag_group(flags = [ 1223 "-g0", 1224 "-O3", 1225 "-DNDEBUG", 1226 "-ffunction-sections", 1227 "-fdata-sections", 1228 ])], 1229 ), 1230 flag_set( 1231 actions = all_link_actions, 1232 flag_groups = [flag_group(flags = ["-Wl,--gc-sections"])], 1233 ), 1234 ], 1235 ) 1236 1237 if ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "mingw-gcc": 1238 archive_param_file_feature = feature( 1239 name = "archive_param_file", 1240 enabled = True, 1241 ) 1242 1243 compiler_param_file_feature = feature( 1244 name = "compiler_param_file", 1245 ) 1246 1247 features = [ 1248 targets_windows_feature, 1249 copy_dynamic_libraries_to_binary_feature, 1250 gcc_env_feature, 1251 default_compile_flags_feature, 1252 archive_param_file_feature, 1253 compiler_param_file_feature, 1254 default_link_flags_feature, 1255 supports_dynamic_linker_feature, 1256 dbg_feature, 1257 opt_feature, 1258 ] 1259 else: 1260 supports_pic_feature = feature( 1261 name = "supports_pic", 1262 enabled = True, 1263 ) 1264 1265 sysroot_feature = feature( 1266 name = "sysroot", 1267 enabled = True, 1268 flag_sets = [ 1269 flag_set( 1270 actions = [ 1271 ACTION_NAMES.preprocess_assemble, 1272 ACTION_NAMES.linkstamp_compile, 1273 ACTION_NAMES.c_compile, 1274 ACTION_NAMES.cpp_compile, 1275 ACTION_NAMES.cpp_header_parsing, 1276 ACTION_NAMES.cpp_module_compile, 1277 ACTION_NAMES.cpp_module_codegen, 1278 ACTION_NAMES.lto_backend, 1279 ACTION_NAMES.clif_match, 1280 ACTION_NAMES.cpp_link_executable, 1281 ACTION_NAMES.cpp_link_dynamic_library, 1282 ACTION_NAMES.cpp_link_nodeps_dynamic_library, 1283 ], 1284 flag_groups = [ 1285 flag_group( 1286 flags = ["--sysroot=%{sysroot}"], 1287 expand_if_available = "sysroot", 1288 ), 1289 ], 1290 ), 1291 ], 1292 ) 1293 1294 fdo_optimize_feature = feature( 1295 name = "fdo_optimize", 1296 flag_sets = [ 1297 flag_set( 1298 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 1299 flag_groups = [ 1300 flag_group( 1301 flags = [ 1302 "-fprofile-use=%{fdo_profile_path}", 1303 "-fprofile-correction", 1304 ], 1305 expand_if_available = "fdo_profile_path", 1306 ), 1307 ], 1308 ), 1309 ], 1310 provides = ["profile"], 1311 ) 1312 1313 treat_warnings_as_errors_feature = feature( 1314 name = "treat_warnings_as_errors", 1315 flag_sets = [ 1316 flag_set( 1317 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 1318 flag_groups = [flag_group(flags = ["-Werror"])], 1319 ), 1320 flag_set( 1321 actions = all_link_actions, 1322 flag_groups = [flag_group(flags = ["-Wl,-fatal-warnings"])], 1323 ), 1324 ], 1325 ) 1326 1327 user_compile_flags_feature = feature( 1328 name = "user_compile_flags", 1329 enabled = True, 1330 flag_sets = [ 1331 flag_set( 1332 actions = [ 1333 ACTION_NAMES.assemble, 1334 ACTION_NAMES.preprocess_assemble, 1335 ACTION_NAMES.linkstamp_compile, 1336 ACTION_NAMES.c_compile, 1337 ACTION_NAMES.cpp_compile, 1338 ACTION_NAMES.cpp_header_parsing, 1339 ACTION_NAMES.cpp_module_compile, 1340 ACTION_NAMES.cpp_module_codegen, 1341 ACTION_NAMES.lto_backend, 1342 ACTION_NAMES.clif_match, 1343 ], 1344 flag_groups = [ 1345 flag_group( 1346 flags = ["%{user_compile_flags}"], 1347 iterate_over = "user_compile_flags", 1348 expand_if_available = "user_compile_flags", 1349 ), 1350 ], 1351 ), 1352 ], 1353 ) 1354 1355 features = [ 1356 targets_windows_feature, 1357 copy_dynamic_libraries_to_binary_feature, 1358 gcc_env_feature, 1359 supports_pic_feature, 1360 default_compile_flags_feature, 1361 default_link_flags_feature, 1362 fdo_optimize_feature, 1363 supports_dynamic_linker_feature, 1364 dbg_feature, 1365 opt_feature, 1366 user_compile_flags_feature, 1367 treat_warnings_as_errors_feature, 1368 sysroot_feature, 1369 ] 1370 1371 tool_paths = [ 1372 tool_path(name = name, path = path) 1373 for name, path in ctx.attr.tool_paths.items() 1374 ] 1375 1376 return cc_common.create_cc_toolchain_config_info( 1377 ctx = ctx, 1378 features = features, 1379 action_configs = action_configs, 1380 artifact_name_patterns = artifact_name_patterns, 1381 cxx_builtin_include_directories = ctx.attr.cxx_builtin_include_directories, 1382 toolchain_identifier = ctx.attr.toolchain_identifier, 1383 host_system_name = ctx.attr.host_system_name, 1384 target_system_name = ctx.attr.target_system_name, 1385 target_cpu = ctx.attr.cpu, 1386 target_libc = ctx.attr.target_libc, 1387 compiler = ctx.attr.compiler, 1388 abi_version = ctx.attr.abi_version, 1389 abi_libc_version = ctx.attr.abi_libc_version, 1390 tool_paths = tool_paths, 1391 ) 1392 1393 cc_toolchain_config = rule( 1394 implementation = _impl, 1395 attrs = { 1396 "cpu": attr.string(mandatory = True), 1397 "compiler": attr.string(), 1398 "toolchain_identifier": attr.string(), 1399 "host_system_name": attr.string(), 1400 "target_system_name": attr.string(), 1401 "target_libc": attr.string(), 1402 "abi_version": attr.string(), 1403 "abi_libc_version": attr.string(), 1404 "tool_paths": attr.string_dict(), 1405 "cxx_builtin_include_directories": attr.string_list(), 1406 "archiver_flags": attr.string_list(default = []), 1407 "default_link_flags": attr.string_list(default = []), 1408 "msvc_env_tmp": attr.string(default = "msvc_not_found"), 1409 "msvc_env_path": attr.string(default = "msvc_not_found"), 1410 "msvc_env_include": attr.string(default = "msvc_not_found"), 1411 "msvc_env_lib": attr.string(default = "msvc_not_found"), 1412 "msvc_cl_path": attr.string(default = "vc_installation_error.bat"), 1413 "msvc_ml_path": attr.string(default = "vc_installation_error.bat"), 1414 "msvc_link_path": attr.string(default = "vc_installation_error.bat"), 1415 "msvc_lib_path": attr.string(default = "vc_installation_error.bat"), 1416 "dbg_mode_debug_flag": attr.string(), 1417 "fastbuild_mode_debug_flag": attr.string(), 1418 "tool_bin_path": attr.string(default = "not_found"), 1419 }, 1420 provides = [CcToolchainConfigInfo], 1421 )