github.com/johnnyeven/libtools@v0.0.0-20191126065708-61829c1adf46/third_party/toolchains/preconfig/win_1803/bazel_026/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"""
    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      "feature_set",
    25      "flag_group",
    26      "flag_set",
    27      "make_variable",
    28      "tool",
    29      "tool_path",
    30      "variable_with_value",
    31      "with_feature_set",
    32  )
    33  load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
    34  
    35  all_compile_actions = [
    36      ACTION_NAMES.c_compile,
    37      ACTION_NAMES.cpp_compile,
    38      ACTION_NAMES.linkstamp_compile,
    39      ACTION_NAMES.assemble,
    40      ACTION_NAMES.preprocess_assemble,
    41      ACTION_NAMES.cpp_header_parsing,
    42      ACTION_NAMES.cpp_module_compile,
    43      ACTION_NAMES.cpp_module_codegen,
    44      ACTION_NAMES.clif_match,
    45      ACTION_NAMES.lto_backend,
    46  ]
    47  
    48  all_cpp_compile_actions = [
    49      ACTION_NAMES.cpp_compile,
    50      ACTION_NAMES.linkstamp_compile,
    51      ACTION_NAMES.cpp_header_parsing,
    52      ACTION_NAMES.cpp_module_compile,
    53      ACTION_NAMES.cpp_module_codegen,
    54      ACTION_NAMES.clif_match,
    55  ]
    56  
    57  preprocessor_compile_actions = [
    58      ACTION_NAMES.c_compile,
    59      ACTION_NAMES.cpp_compile,
    60      ACTION_NAMES.linkstamp_compile,
    61      ACTION_NAMES.preprocess_assemble,
    62      ACTION_NAMES.cpp_header_parsing,
    63      ACTION_NAMES.cpp_module_compile,
    64      ACTION_NAMES.clif_match,
    65  ]
    66  
    67  codegen_compile_actions = [
    68      ACTION_NAMES.c_compile,
    69      ACTION_NAMES.cpp_compile,
    70      ACTION_NAMES.linkstamp_compile,
    71      ACTION_NAMES.assemble,
    72      ACTION_NAMES.preprocess_assemble,
    73      ACTION_NAMES.cpp_module_codegen,
    74      ACTION_NAMES.lto_backend,
    75  ]
    76  
    77  all_link_actions = [
    78      ACTION_NAMES.cpp_link_executable,
    79      ACTION_NAMES.cpp_link_dynamic_library,
    80      ACTION_NAMES.cpp_link_nodeps_dynamic_library,
    81  ]
    82  
    83  def _windows_msvc_impl(ctx):
    84      toolchain_identifier = "msvc_x64"
    85      host_system_name = "local"
    86      target_system_name = "local"
    87      target_cpu = "x64_windows"
    88      target_libc = "msvcrt"
    89      compiler = "msvc-cl"
    90      abi_version = "local"
    91      abi_libc_version = "local"
    92      cc_target_os = None
    93      builtin_sysroot = None
    94  
    95      cxx_builtin_include_directories = [
    96          # This is a workaround for https://github.com/bazelbuild/bazel/issues/5087.
    97          "C:\\botcode\\w",
    98          "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\include",
    99          "C:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.6.1\\include\\um",
   100          "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\ucrt",
   101          "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\shared",
   102          "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\um",
   103          "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\winrt",
   104          "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\cppwinrt",
   105      ]
   106  
   107      cpp_link_nodeps_dynamic_library_action = action_config(
   108          action_name = ACTION_NAMES.cpp_link_nodeps_dynamic_library,
   109          implies = [
   110              "nologo",
   111              "shared_flag",
   112              "linkstamps",
   113              "output_execpath_flags",
   114              "input_param_flags",
   115              "user_link_flags",
   116              "default_link_flags",
   117              "linker_subsystem_flag",
   118              "linker_param_file",
   119              "msvc_env",
   120              "no_stripping",
   121              "has_configured_linker_path",
   122              "def_file",
   123          ],
   124          tools = [tool(path = "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/link.exe")],
   125      )
   126  
   127      cpp_link_static_library_action = action_config(
   128          action_name = ACTION_NAMES.cpp_link_static_library,
   129          implies = [
   130              "nologo",
   131              "archiver_flags",
   132              "input_param_flags",
   133              "linker_param_file",
   134              "msvc_env",
   135          ],
   136          tools = [tool(path = "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/lib.exe")],
   137      )
   138  
   139      assemble_action = action_config(
   140          action_name = ACTION_NAMES.assemble,
   141          implies = [
   142              "compiler_input_flags",
   143              "compiler_output_flags",
   144              "nologo",
   145              "msvc_env",
   146              "sysroot",
   147          ],
   148          tools = [tool(path = "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/ml64.exe")],
   149      )
   150  
   151      preprocess_assemble_action = action_config(
   152          action_name = ACTION_NAMES.preprocess_assemble,
   153          implies = [
   154              "compiler_input_flags",
   155              "compiler_output_flags",
   156              "nologo",
   157              "msvc_env",
   158              "sysroot",
   159          ],
   160          tools = [tool(path = "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/ml64.exe")],
   161      )
   162  
   163      c_compile_action = action_config(
   164          action_name = ACTION_NAMES.c_compile,
   165          implies = [
   166              "compiler_input_flags",
   167              "compiler_output_flags",
   168              "default_compile_flags",
   169              "nologo",
   170              "msvc_env",
   171              "parse_showincludes",
   172              "user_compile_flags",
   173              "sysroot",
   174              "unfiltered_compile_flags",
   175          ],
   176          tools = [tool(path = "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/cl.exe")],
   177      )
   178  
   179      cpp_compile_action = action_config(
   180          action_name = ACTION_NAMES.cpp_compile,
   181          implies = [
   182              "compiler_input_flags",
   183              "compiler_output_flags",
   184              "default_compile_flags",
   185              "nologo",
   186              "msvc_env",
   187              "parse_showincludes",
   188              "user_compile_flags",
   189              "sysroot",
   190              "unfiltered_compile_flags",
   191          ],
   192          tools = [tool(path = "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/cl.exe")],
   193      )
   194  
   195      cpp_link_executable_action = action_config(
   196          action_name = ACTION_NAMES.cpp_link_executable,
   197          implies = [
   198              "nologo",
   199              "linkstamps",
   200              "output_execpath_flags",
   201              "input_param_flags",
   202              "user_link_flags",
   203              "default_link_flags",
   204              "linker_subsystem_flag",
   205              "linker_param_file",
   206              "msvc_env",
   207              "no_stripping",
   208          ],
   209          tools = [tool(path = "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/link.exe")],
   210      )
   211  
   212      cpp_link_dynamic_library_action = action_config(
   213          action_name = ACTION_NAMES.cpp_link_dynamic_library,
   214          implies = [
   215              "nologo",
   216              "shared_flag",
   217              "linkstamps",
   218              "output_execpath_flags",
   219              "input_param_flags",
   220              "user_link_flags",
   221              "default_link_flags",
   222              "linker_subsystem_flag",
   223              "linker_param_file",
   224              "msvc_env",
   225              "no_stripping",
   226              "has_configured_linker_path",
   227              "def_file",
   228          ],
   229          tools = [tool(path = "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/link.exe")],
   230      )
   231  
   232      action_configs = [
   233          assemble_action,
   234          preprocess_assemble_action,
   235          c_compile_action,
   236          cpp_compile_action,
   237          cpp_link_executable_action,
   238          cpp_link_dynamic_library_action,
   239          cpp_link_nodeps_dynamic_library_action,
   240          cpp_link_static_library_action,
   241      ]
   242  
   243      msvc_link_env_feature = feature(
   244          name = "msvc_link_env",
   245          env_sets = [
   246              env_set(
   247                  actions = all_link_actions +
   248                            [ACTION_NAMES.cpp_link_static_library],
   249                  env_entries = [env_entry(key = "LIB", value = "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\lib\\x64;C:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.6.1\\lib\\um\\x64;C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.17763.0\\ucrt\\x64;C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.17763.0\\um\\x64;")],
   250              ),
   251          ],
   252      )
   253  
   254      shared_flag_feature = feature(
   255          name = "shared_flag",
   256          flag_sets = [
   257              flag_set(
   258                  actions = [
   259                      ACTION_NAMES.cpp_link_dynamic_library,
   260                      ACTION_NAMES.cpp_link_nodeps_dynamic_library,
   261                  ],
   262                  flag_groups = [flag_group(flags = ["/DLL"])],
   263              ),
   264          ],
   265      )
   266  
   267      determinism_feature = feature(
   268          name = "determinism",
   269          enabled = True,
   270          flag_sets = [
   271              flag_set(
   272                  actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],
   273                  flag_groups = [
   274                      flag_group(
   275                          flags = [
   276                              "/wd4117",
   277                              "-D__DATE__=\"redacted\"",
   278                              "-D__TIMESTAMP__=\"redacted\"",
   279                              "-D__TIME__=\"redacted\"",
   280                          ],
   281                      ),
   282                  ],
   283              ),
   284          ],
   285      )
   286  
   287      sysroot_feature = feature(
   288          name = "sysroot",
   289          flag_sets = [
   290              flag_set(
   291                  actions = [
   292                      ACTION_NAMES.assemble,
   293                      ACTION_NAMES.preprocess_assemble,
   294                      ACTION_NAMES.c_compile,
   295                      ACTION_NAMES.cpp_compile,
   296                      ACTION_NAMES.cpp_header_parsing,
   297                      ACTION_NAMES.cpp_module_compile,
   298                      ACTION_NAMES.cpp_module_codegen,
   299                      ACTION_NAMES.cpp_link_executable,
   300                      ACTION_NAMES.cpp_link_dynamic_library,
   301                      ACTION_NAMES.cpp_link_nodeps_dynamic_library,
   302                  ],
   303                  flag_groups = [
   304                      flag_group(
   305                          flags = ["--sysroot=%{sysroot}"],
   306                          iterate_over = "sysroot",
   307                          expand_if_available = "sysroot",
   308                      ),
   309                  ],
   310              ),
   311          ],
   312      )
   313  
   314      unfiltered_compile_flags_feature = feature(
   315          name = "unfiltered_compile_flags",
   316          flag_sets = [
   317              flag_set(
   318                  actions = [
   319                      ACTION_NAMES.preprocess_assemble,
   320                      ACTION_NAMES.c_compile,
   321                      ACTION_NAMES.cpp_compile,
   322                      ACTION_NAMES.cpp_header_parsing,
   323                      ACTION_NAMES.cpp_module_compile,
   324                      ACTION_NAMES.cpp_module_codegen,
   325                  ],
   326                  flag_groups = [
   327                      flag_group(
   328                          flags = ["%{unfiltered_compile_flags}"],
   329                          iterate_over = "unfiltered_compile_flags",
   330                          expand_if_available = "unfiltered_compile_flags",
   331                      ),
   332                  ],
   333              ),
   334          ],
   335      )
   336  
   337      compiler_param_file_feature = feature(
   338          name = "compiler_param_file",
   339      )
   340  
   341      copy_dynamic_libraries_to_binary_feature = feature(name = "copy_dynamic_libraries_to_binary")
   342  
   343      input_param_flags_feature = feature(
   344          name = "input_param_flags",
   345          flag_sets = [
   346              flag_set(
   347                  actions = [
   348                      ACTION_NAMES.cpp_link_dynamic_library,
   349                      ACTION_NAMES.cpp_link_nodeps_dynamic_library,
   350                  ],
   351                  flag_groups = [
   352                      flag_group(
   353                          flags = ["/IMPLIB:%{interface_library_output_path}"],
   354                          expand_if_available = "interface_library_output_path",
   355                      ),
   356                  ],
   357              ),
   358              flag_set(
   359                  actions = all_link_actions,
   360                  flag_groups = [
   361                      flag_group(
   362                          flags = ["%{libopts}"],
   363                          iterate_over = "libopts",
   364                          expand_if_available = "libopts",
   365                      ),
   366                  ],
   367              ),
   368              flag_set(
   369                  actions = all_link_actions +
   370                            [ACTION_NAMES.cpp_link_static_library],
   371                  flag_groups = [
   372                      flag_group(
   373                          iterate_over = "libraries_to_link",
   374                          flag_groups = [
   375                              flag_group(
   376                                  iterate_over = "libraries_to_link.object_files",
   377                                  flag_groups = [flag_group(flags = ["%{libraries_to_link.object_files}"])],
   378                                  expand_if_equal = variable_with_value(
   379                                      name = "libraries_to_link.type",
   380                                      value = "object_file_group",
   381                                  ),
   382                              ),
   383                              flag_group(
   384                                  flag_groups = [flag_group(flags = ["%{libraries_to_link.name}"])],
   385                                  expand_if_equal = variable_with_value(
   386                                      name = "libraries_to_link.type",
   387                                      value = "object_file",
   388                                  ),
   389                              ),
   390                              flag_group(
   391                                  flag_groups = [flag_group(flags = ["%{libraries_to_link.name}"])],
   392                                  expand_if_equal = variable_with_value(
   393                                      name = "libraries_to_link.type",
   394                                      value = "interface_library",
   395                                  ),
   396                              ),
   397                              flag_group(
   398                                  flag_groups = [
   399                                      flag_group(
   400                                          flags = ["%{libraries_to_link.name}"],
   401                                          expand_if_false = "libraries_to_link.is_whole_archive",
   402                                      ),
   403                                      flag_group(
   404                                          flags = ["/WHOLEARCHIVE:%{libraries_to_link.name}"],
   405                                          expand_if_true = "libraries_to_link.is_whole_archive",
   406                                      ),
   407                                  ],
   408                                  expand_if_equal = variable_with_value(
   409                                      name = "libraries_to_link.type",
   410                                      value = "static_library",
   411                                  ),
   412                              ),
   413                          ],
   414                          expand_if_available = "libraries_to_link",
   415                      ),
   416                  ],
   417              ),
   418          ],
   419      )
   420  
   421      fastbuild_feature = feature(
   422          name = "fastbuild",
   423          flag_sets = [
   424              flag_set(
   425                  actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],
   426                  flag_groups = [flag_group(flags = ["/Od", "/Z7"])],
   427              ),
   428              flag_set(
   429                  actions = all_link_actions,
   430                  flag_groups = [
   431                      flag_group(
   432                          flags = ["/DEBUG:FASTLINK", "/INCREMENTAL:NO"],
   433                      ),
   434                  ],
   435              ),
   436          ],
   437          implies = ["generate_pdb_file"],
   438      )
   439  
   440      user_compile_flags_feature = feature(
   441          name = "user_compile_flags",
   442          flag_sets = [
   443              flag_set(
   444                  actions = [
   445                      ACTION_NAMES.preprocess_assemble,
   446                      ACTION_NAMES.c_compile,
   447                      ACTION_NAMES.cpp_compile,
   448                      ACTION_NAMES.cpp_header_parsing,
   449                      ACTION_NAMES.cpp_module_compile,
   450                      ACTION_NAMES.cpp_module_codegen,
   451                  ],
   452                  flag_groups = [
   453                      flag_group(
   454                          flags = ["%{user_compile_flags}"],
   455                          iterate_over = "user_compile_flags",
   456                          expand_if_available = "user_compile_flags",
   457                      ),
   458                  ],
   459              ),
   460          ],
   461      )
   462  
   463      archiver_flags_feature = feature(
   464          name = "archiver_flags",
   465          flag_sets = [
   466              flag_set(
   467                  actions = [ACTION_NAMES.cpp_link_static_library],
   468                  flag_groups = [
   469                      flag_group(
   470                          flags = ["/OUT:%{output_execpath}"],
   471                          expand_if_available = "output_execpath",
   472                      ),
   473                      flag_group(
   474                          flags = ["/MACHINE:X64"],
   475                      ),
   476                  ],
   477              ),
   478          ],
   479      )
   480  
   481      default_link_flags_feature = feature(
   482          name = "default_link_flags",
   483          enabled = True,
   484          flag_sets = [
   485              flag_set(
   486                  actions = all_link_actions,
   487                  flag_groups = [flag_group(flags = ["/MACHINE:X64"])],
   488              ),
   489          ],
   490      )
   491  
   492      static_link_msvcrt_feature = feature(name = "static_link_msvcrt")
   493  
   494      dynamic_link_msvcrt_debug_feature = feature(
   495          name = "dynamic_link_msvcrt_debug",
   496          flag_sets = [
   497              flag_set(
   498                  actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],
   499                  flag_groups = [flag_group(flags = ["/MDd"])],
   500              ),
   501              flag_set(
   502                  actions = all_link_actions,
   503                  flag_groups = [flag_group(flags = ["/DEFAULTLIB:msvcrtd.lib"])],
   504              ),
   505          ],
   506          requires = [feature_set(features = ["dbg"])],
   507      )
   508  
   509      dbg_feature = feature(
   510          name = "dbg",
   511          flag_sets = [
   512              flag_set(
   513                  actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],
   514                  flag_groups = [flag_group(flags = ["/Od", "/Z7"])],
   515              ),
   516              flag_set(
   517                  actions = all_link_actions,
   518                  flag_groups = [
   519                      flag_group(
   520                          flags = ["/DEBUG:FULL", "/INCREMENTAL:NO"],
   521                      ),
   522                  ],
   523              ),
   524          ],
   525          implies = ["generate_pdb_file"],
   526      )
   527  
   528      opt_feature = feature(
   529          name = "opt",
   530          flag_sets = [
   531              flag_set(
   532                  actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],
   533                  flag_groups = [flag_group(flags = ["/O2"])],
   534              ),
   535          ],
   536          implies = ["frame_pointer"],
   537      )
   538  
   539      supports_interface_shared_libraries_feature = feature(
   540          name = "supports_interface_shared_libraries",
   541          enabled = True,
   542      )
   543  
   544      user_link_flags_feature = feature(
   545          name = "user_link_flags",
   546          flag_sets = [
   547              flag_set(
   548                  actions = all_link_actions,
   549                  flag_groups = [
   550                      flag_group(
   551                          flags = ["%{user_link_flags}"],
   552                          iterate_over = "user_link_flags",
   553                          expand_if_available = "user_link_flags",
   554                      ),
   555                  ],
   556              ),
   557          ],
   558      )
   559  
   560      default_compile_flags_feature = feature(
   561          name = "default_compile_flags",
   562          enabled = True,
   563          flag_sets = [
   564              flag_set(
   565                  actions = [
   566                      ACTION_NAMES.assemble,
   567                      ACTION_NAMES.preprocess_assemble,
   568                      ACTION_NAMES.linkstamp_compile,
   569                      ACTION_NAMES.c_compile,
   570                      ACTION_NAMES.cpp_compile,
   571                      ACTION_NAMES.cpp_header_parsing,
   572                      ACTION_NAMES.cpp_module_compile,
   573                      ACTION_NAMES.cpp_module_codegen,
   574                      ACTION_NAMES.lto_backend,
   575                      ACTION_NAMES.clif_match,
   576                  ],
   577                  flag_groups = [
   578                      flag_group(
   579                          flags = [
   580                              "/DCOMPILER_MSVC",
   581                              "/DNOMINMAX",
   582                              "/D_WIN32_WINNT=0x0601",
   583                              "/D_CRT_SECURE_NO_DEPRECATE",
   584                              "/D_CRT_SECURE_NO_WARNINGS",
   585                              "/bigobj",
   586                              "/Zm500",
   587                              "/EHsc",
   588                              "/wd4351",
   589                              "/wd4291",
   590                              "/wd4250",
   591                              "/wd4996",
   592                          ],
   593                      ),
   594                  ],
   595              ),
   596          ],
   597      )
   598  
   599      msvc_compile_env_feature = feature(
   600          name = "msvc_compile_env",
   601          env_sets = [
   602              env_set(
   603                  actions = [
   604                      ACTION_NAMES.c_compile,
   605                      ACTION_NAMES.cpp_compile,
   606                      ACTION_NAMES.cpp_module_compile,
   607                      ACTION_NAMES.cpp_module_codegen,
   608                      ACTION_NAMES.cpp_header_parsing,
   609                      ACTION_NAMES.assemble,
   610                      ACTION_NAMES.preprocess_assemble,
   611                  ],
   612                  env_entries = [env_entry(key = "INCLUDE", value = "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\include;C:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.6.1\\include\\um;C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\ucrt;C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\shared;C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\um;C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\winrt;C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\cppwinrt")],
   613              ),
   614          ],
   615      )
   616  
   617      preprocessor_defines_feature = feature(
   618          name = "preprocessor_defines",
   619          enabled = True,
   620          flag_sets = [
   621              flag_set(
   622                  actions = [
   623                      ACTION_NAMES.assemble,
   624                      ACTION_NAMES.preprocess_assemble,
   625                      ACTION_NAMES.c_compile,
   626                      ACTION_NAMES.cpp_compile,
   627                      ACTION_NAMES.cpp_header_parsing,
   628                      ACTION_NAMES.cpp_module_compile,
   629                  ],
   630                  flag_groups = [
   631                      flag_group(
   632                          flags = ["/D%{preprocessor_defines}"],
   633                          iterate_over = "preprocessor_defines",
   634                      ),
   635                  ],
   636              ),
   637          ],
   638      )
   639  
   640      generate_pdb_file_feature = feature(
   641          name = "generate_pdb_file",
   642          requires = [
   643              feature_set(features = ["dbg"]),
   644              feature_set(features = ["fastbuild"]),
   645          ],
   646      )
   647  
   648      output_execpath_flags_feature = feature(
   649          name = "output_execpath_flags",
   650          flag_sets = [
   651              flag_set(
   652                  actions = all_link_actions,
   653                  flag_groups = [
   654                      flag_group(
   655                          flags = ["/OUT:%{output_execpath}"],
   656                          expand_if_available = "output_execpath",
   657                      ),
   658                  ],
   659              ),
   660          ],
   661      )
   662  
   663      dynamic_link_msvcrt_no_debug_feature = feature(
   664          name = "dynamic_link_msvcrt_no_debug",
   665          flag_sets = [
   666              flag_set(
   667                  actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],
   668                  flag_groups = [flag_group(flags = ["/MD"])],
   669              ),
   670              flag_set(
   671                  actions = all_link_actions,
   672                  flag_groups = [flag_group(flags = ["/DEFAULTLIB:msvcrt.lib"])],
   673              ),
   674          ],
   675          requires = [
   676              feature_set(features = ["fastbuild"]),
   677              feature_set(features = ["opt"]),
   678          ],
   679      )
   680  
   681      disable_assertions_feature = feature(
   682          name = "disable_assertions",
   683          enabled = True,
   684          flag_sets = [
   685              flag_set(
   686                  actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],
   687                  flag_groups = [flag_group(flags = ["/DNDEBUG"])],
   688                  with_features = [with_feature_set(features = ["opt"])],
   689              ),
   690          ],
   691      )
   692  
   693      has_configured_linker_path_feature = feature(name = "has_configured_linker_path")
   694  
   695      supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True)
   696  
   697      no_stripping_feature = feature(name = "no_stripping")
   698  
   699      linker_param_file_feature = feature(
   700          name = "linker_param_file",
   701          flag_sets = [
   702              flag_set(
   703                  actions = all_link_actions +
   704                            [ACTION_NAMES.cpp_link_static_library],
   705                  flag_groups = [
   706                      flag_group(
   707                          flags = ["@%{linker_param_file}"],
   708                          expand_if_available = "linker_param_file",
   709                      ),
   710                  ],
   711              ),
   712          ],
   713      )
   714  
   715      ignore_noisy_warnings_feature = feature(
   716          name = "ignore_noisy_warnings",
   717          enabled = True,
   718          flag_sets = [
   719              flag_set(
   720                  actions = [ACTION_NAMES.cpp_link_static_library],
   721                  flag_groups = [flag_group(flags = ["/ignore:4221"])],
   722              ),
   723          ],
   724      )
   725  
   726      no_legacy_features_feature = feature(name = "no_legacy_features")
   727  
   728      parse_showincludes_feature = feature(
   729          name = "parse_showincludes",
   730          flag_sets = [
   731              flag_set(
   732                  actions = [
   733                      ACTION_NAMES.preprocess_assemble,
   734                      ACTION_NAMES.c_compile,
   735                      ACTION_NAMES.cpp_compile,
   736                      ACTION_NAMES.cpp_module_compile,
   737                      ACTION_NAMES.cpp_header_parsing,
   738                  ],
   739                  flag_groups = [flag_group(flags = ["/showIncludes"])],
   740              ),
   741          ],
   742      )
   743  
   744      static_link_msvcrt_no_debug_feature = feature(
   745          name = "static_link_msvcrt_no_debug",
   746          flag_sets = [
   747              flag_set(
   748                  actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],
   749                  flag_groups = [flag_group(flags = ["/MT"])],
   750              ),
   751              flag_set(
   752                  actions = all_link_actions,
   753                  flag_groups = [flag_group(flags = ["/DEFAULTLIB:libcmt.lib"])],
   754              ),
   755          ],
   756          requires = [
   757              feature_set(features = ["fastbuild"]),
   758              feature_set(features = ["opt"]),
   759          ],
   760      )
   761  
   762      treat_warnings_as_errors_feature = feature(
   763          name = "treat_warnings_as_errors",
   764          flag_sets = [
   765              flag_set(
   766                  actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],
   767                  flag_groups = [flag_group(flags = ["/WX"])],
   768              ),
   769          ],
   770      )
   771  
   772      windows_export_all_symbols_feature = feature(name = "windows_export_all_symbols")
   773  
   774      no_windows_export_all_symbols_feature = feature(name = "no_windows_export_all_symbols")
   775  
   776      include_paths_feature = feature(
   777          name = "include_paths",
   778          enabled = True,
   779          flag_sets = [
   780              flag_set(
   781                  actions = [
   782                      ACTION_NAMES.assemble,
   783                      ACTION_NAMES.preprocess_assemble,
   784                      ACTION_NAMES.c_compile,
   785                      ACTION_NAMES.cpp_compile,
   786                      ACTION_NAMES.cpp_header_parsing,
   787                      ACTION_NAMES.cpp_module_compile,
   788                  ],
   789                  flag_groups = [
   790                      flag_group(
   791                          flags = ["/I%{quote_include_paths}"],
   792                          iterate_over = "quote_include_paths",
   793                      ),
   794                      flag_group(
   795                          flags = ["/I%{include_paths}"],
   796                          iterate_over = "include_paths",
   797                      ),
   798                      flag_group(
   799                          flags = ["/I%{system_include_paths}"],
   800                          iterate_over = "system_include_paths",
   801                      ),
   802                  ],
   803              ),
   804          ],
   805      )
   806  
   807      linkstamps_feature = feature(
   808          name = "linkstamps",
   809          flag_sets = [
   810              flag_set(
   811                  actions = all_link_actions,
   812                  flag_groups = [
   813                      flag_group(
   814                          flags = ["%{linkstamp_paths}"],
   815                          iterate_over = "linkstamp_paths",
   816                          expand_if_available = "linkstamp_paths",
   817                      ),
   818                  ],
   819              ),
   820          ],
   821      )
   822  
   823      targets_windows_feature = feature(
   824          name = "targets_windows",
   825          enabled = True,
   826          implies = ["copy_dynamic_libraries_to_binary"],
   827      )
   828  
   829      linker_subsystem_flag_feature = feature(
   830          name = "linker_subsystem_flag",
   831          flag_sets = [
   832              flag_set(
   833                  actions = all_link_actions,
   834                  flag_groups = [flag_group(flags = ["/SUBSYSTEM:CONSOLE"])],
   835              ),
   836          ],
   837      )
   838  
   839      static_link_msvcrt_debug_feature = feature(
   840          name = "static_link_msvcrt_debug",
   841          flag_sets = [
   842              flag_set(
   843                  actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],
   844                  flag_groups = [flag_group(flags = ["/MTd"])],
   845              ),
   846              flag_set(
   847                  actions = all_link_actions,
   848                  flag_groups = [flag_group(flags = ["/DEFAULTLIB:libcmtd.lib"])],
   849              ),
   850          ],
   851          requires = [feature_set(features = ["dbg"])],
   852      )
   853  
   854      frame_pointer_feature = feature(
   855          name = "frame_pointer",
   856          flag_sets = [
   857              flag_set(
   858                  actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],
   859                  flag_groups = [flag_group(flags = ["/Oy-"])],
   860              ),
   861          ],
   862      )
   863  
   864      compiler_output_flags_feature = feature(
   865          name = "compiler_output_flags",
   866          flag_sets = [
   867              flag_set(
   868                  actions = [ACTION_NAMES.assemble],
   869                  flag_groups = [
   870                      flag_group(
   871                          flag_groups = [
   872                              flag_group(
   873                                  flags = ["/Fo%{output_file}", "/Zi"],
   874                                  expand_if_available = "output_file",
   875                                  expand_if_not_available = "output_assembly_file",
   876                              ),
   877                          ],
   878                          expand_if_not_available = "output_preprocess_file",
   879                      ),
   880                  ],
   881              ),
   882              flag_set(
   883                  actions = [
   884                      ACTION_NAMES.preprocess_assemble,
   885                      ACTION_NAMES.c_compile,
   886                      ACTION_NAMES.cpp_compile,
   887                      ACTION_NAMES.cpp_header_parsing,
   888                      ACTION_NAMES.cpp_module_compile,
   889                      ACTION_NAMES.cpp_module_codegen,
   890                  ],
   891                  flag_groups = [
   892                      flag_group(
   893                          flag_groups = [
   894                              flag_group(
   895                                  flags = ["/Fo%{output_file}"],
   896                                  expand_if_not_available = "output_preprocess_file",
   897                              ),
   898                          ],
   899                          expand_if_available = "output_file",
   900                          expand_if_not_available = "output_assembly_file",
   901                      ),
   902                      flag_group(
   903                          flag_groups = [
   904                              flag_group(
   905                                  flags = ["/Fa%{output_file}"],
   906                                  expand_if_available = "output_assembly_file",
   907                              ),
   908                          ],
   909                          expand_if_available = "output_file",
   910                      ),
   911                      flag_group(
   912                          flag_groups = [
   913                              flag_group(
   914                                  flags = ["/P", "/Fi%{output_file}"],
   915                                  expand_if_available = "output_preprocess_file",
   916                              ),
   917                          ],
   918                          expand_if_available = "output_file",
   919                      ),
   920                  ],
   921              ),
   922          ],
   923      )
   924  
   925      nologo_feature = feature(
   926          name = "nologo",
   927          flag_sets = [
   928              flag_set(
   929                  actions = [
   930                      ACTION_NAMES.c_compile,
   931                      ACTION_NAMES.cpp_compile,
   932                      ACTION_NAMES.cpp_module_compile,
   933                      ACTION_NAMES.cpp_module_codegen,
   934                      ACTION_NAMES.cpp_header_parsing,
   935                      ACTION_NAMES.assemble,
   936                      ACTION_NAMES.preprocess_assemble,
   937                      ACTION_NAMES.cpp_link_executable,
   938                      ACTION_NAMES.cpp_link_dynamic_library,
   939                      ACTION_NAMES.cpp_link_nodeps_dynamic_library,
   940                      ACTION_NAMES.cpp_link_static_library,
   941                  ],
   942                  flag_groups = [flag_group(flags = ["/nologo"])],
   943              ),
   944          ],
   945      )
   946  
   947      smaller_binary_feature = feature(
   948          name = "smaller_binary",
   949          enabled = True,
   950          flag_sets = [
   951              flag_set(
   952                  actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],
   953                  flag_groups = [flag_group(flags = ["/Gy", "/Gw"])],
   954                  with_features = [with_feature_set(features = ["opt"])],
   955              ),
   956              flag_set(
   957                  actions = all_link_actions,
   958                  flag_groups = [flag_group(flags = ["/OPT:ICF", "/OPT:REF"])],
   959                  with_features = [with_feature_set(features = ["opt"])],
   960              ),
   961          ],
   962      )
   963  
   964      compiler_input_flags_feature = feature(
   965          name = "compiler_input_flags",
   966          flag_sets = [
   967              flag_set(
   968                  actions = [
   969                      ACTION_NAMES.assemble,
   970                      ACTION_NAMES.preprocess_assemble,
   971                      ACTION_NAMES.c_compile,
   972                      ACTION_NAMES.cpp_compile,
   973                      ACTION_NAMES.cpp_header_parsing,
   974                      ACTION_NAMES.cpp_module_compile,
   975                      ACTION_NAMES.cpp_module_codegen,
   976                  ],
   977                  flag_groups = [
   978                      flag_group(
   979                          flags = ["/c", "%{source_file}"],
   980                          expand_if_available = "source_file",
   981                      ),
   982                  ],
   983              ),
   984          ],
   985      )
   986  
   987      def_file_feature = feature(
   988          name = "def_file",
   989          flag_sets = [
   990              flag_set(
   991                  actions = all_link_actions,
   992                  flag_groups = [
   993                      flag_group(
   994                          flags = ["/DEF:%{def_file_path}", "/ignore:4070"],
   995                          expand_if_available = "def_file_path",
   996                      ),
   997                  ],
   998              ),
   999          ],
  1000      )
  1001  
  1002      msvc_env_feature = feature(
  1003          name = "msvc_env",
  1004          env_sets = [
  1005              env_set(
  1006                  actions = [
  1007                      ACTION_NAMES.c_compile,
  1008                      ACTION_NAMES.cpp_compile,
  1009                      ACTION_NAMES.cpp_module_compile,
  1010                      ACTION_NAMES.cpp_module_codegen,
  1011                      ACTION_NAMES.cpp_header_parsing,
  1012                      ACTION_NAMES.assemble,
  1013                      ACTION_NAMES.preprocess_assemble,
  1014                      ACTION_NAMES.cpp_link_executable,
  1015                      ACTION_NAMES.cpp_link_dynamic_library,
  1016                      ACTION_NAMES.cpp_link_nodeps_dynamic_library,
  1017                      ACTION_NAMES.cpp_link_static_library,
  1018                  ],
  1019                  env_entries = [
  1020                      env_entry(key = "PATH", value = "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX64\\x64;C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\Common7\\IDE\\VC\\VCPackages;C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer;C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\MSBuild\\15.0\\bin\\Roslyn;C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v10.0A\\bin\\NETFX 4.6.1 Tools\\x64\\;C:\\Program Files (x86)\\Windows Kits\\10\\bin\\10.0.17763.0\\x64;C:\\Program Files (x86)\\Windows Kits\\10\\bin\\x64;C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\\\MSBuild\\15.0\\bin;C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319;C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\Common7\\IDE\\;C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\Common7\\Tools\\;;C:\\Windows\\system32"),
  1021                      env_entry(key = "TMP", value = "C:\\Users\\ContainerAdministrator\\AppData\\Local\\Temp"),
  1022                      env_entry(key = "TEMP", value = "C:\\Users\\ContainerAdministrator\\AppData\\Local\\Temp"),
  1023                  ],
  1024              ),
  1025          ],
  1026          implies = ["msvc_compile_env", "msvc_link_env"],
  1027      )
  1028  
  1029      features = [
  1030          no_legacy_features_feature,
  1031          nologo_feature,
  1032          has_configured_linker_path_feature,
  1033          no_stripping_feature,
  1034          targets_windows_feature,
  1035          copy_dynamic_libraries_to_binary_feature,
  1036          default_compile_flags_feature,
  1037          msvc_env_feature,
  1038          msvc_compile_env_feature,
  1039          msvc_link_env_feature,
  1040          include_paths_feature,
  1041          preprocessor_defines_feature,
  1042          parse_showincludes_feature,
  1043          generate_pdb_file_feature,
  1044          shared_flag_feature,
  1045          linkstamps_feature,
  1046          output_execpath_flags_feature,
  1047          archiver_flags_feature,
  1048          input_param_flags_feature,
  1049          linker_subsystem_flag_feature,
  1050          user_link_flags_feature,
  1051          default_link_flags_feature,
  1052          linker_param_file_feature,
  1053          static_link_msvcrt_feature,
  1054          static_link_msvcrt_no_debug_feature,
  1055          dynamic_link_msvcrt_no_debug_feature,
  1056          static_link_msvcrt_debug_feature,
  1057          dynamic_link_msvcrt_debug_feature,
  1058          dbg_feature,
  1059          fastbuild_feature,
  1060          opt_feature,
  1061          frame_pointer_feature,
  1062          disable_assertions_feature,
  1063          determinism_feature,
  1064          treat_warnings_as_errors_feature,
  1065          smaller_binary_feature,
  1066          ignore_noisy_warnings_feature,
  1067          user_compile_flags_feature,
  1068          sysroot_feature,
  1069          unfiltered_compile_flags_feature,
  1070          compiler_param_file_feature,
  1071          compiler_output_flags_feature,
  1072          compiler_input_flags_feature,
  1073          def_file_feature,
  1074          windows_export_all_symbols_feature,
  1075          no_windows_export_all_symbols_feature,
  1076          supports_dynamic_linker_feature,
  1077          supports_interface_shared_libraries_feature,
  1078      ]
  1079  
  1080      artifact_name_patterns = [
  1081          artifact_name_pattern(
  1082              category_name = "object_file",
  1083              prefix = "",
  1084              extension = ".obj",
  1085          ),
  1086          artifact_name_pattern(
  1087              category_name = "static_library",
  1088              prefix = "",
  1089              extension = ".lib",
  1090          ),
  1091          artifact_name_pattern(
  1092              category_name = "alwayslink_static_library",
  1093              prefix = "",
  1094              extension = ".lo.lib",
  1095          ),
  1096          artifact_name_pattern(
  1097              category_name = "executable",
  1098              prefix = "",
  1099              extension = ".exe",
  1100          ),
  1101          artifact_name_pattern(
  1102              category_name = "dynamic_library",
  1103              prefix = "",
  1104              extension = ".dll",
  1105          ),
  1106          artifact_name_pattern(
  1107              category_name = "interface_library",
  1108              prefix = "",
  1109              extension = ".if.lib",
  1110          ),
  1111      ]
  1112  
  1113      make_variables = []
  1114  
  1115      tool_paths = [
  1116          tool_path(name = "ar", path = "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/lib.exe"),
  1117          tool_path(name = "ml", path = "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/ml64.exe"),
  1118          tool_path(name = "cpp", path = "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/cl.exe"),
  1119          tool_path(name = "gcc", path = "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/cl.exe"),
  1120          tool_path(name = "gcov", path = "wrapper/bin/msvc_nop.bat"),
  1121          tool_path(name = "ld", path = "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/link.exe"),
  1122          tool_path(name = "nm", path = "wrapper/bin/msvc_nop.bat"),
  1123          tool_path(
  1124              name = "objcopy",
  1125              path = "wrapper/bin/msvc_nop.bat",
  1126          ),
  1127          tool_path(
  1128              name = "objdump",
  1129              path = "wrapper/bin/msvc_nop.bat",
  1130          ),
  1131          tool_path(
  1132              name = "strip",
  1133              path = "wrapper/bin/msvc_nop.bat",
  1134          ),
  1135      ]
  1136  
  1137      return cc_common.create_cc_toolchain_config_info(
  1138          ctx = ctx,
  1139          features = features,
  1140          action_configs = action_configs,
  1141          artifact_name_patterns = artifact_name_patterns,
  1142          cxx_builtin_include_directories = cxx_builtin_include_directories,
  1143          toolchain_identifier = toolchain_identifier,
  1144          host_system_name = host_system_name,
  1145          target_system_name = target_system_name,
  1146          target_cpu = target_cpu,
  1147          target_libc = target_libc,
  1148          compiler = compiler,
  1149          abi_version = abi_version,
  1150          abi_libc_version = abi_libc_version,
  1151          tool_paths = tool_paths,
  1152          make_variables = make_variables,
  1153          builtin_sysroot = builtin_sysroot,
  1154          cc_target_os = None,
  1155      )
  1156  
  1157  def _windows_msys_mingw_impl(ctx):
  1158      toolchain_identifier = "msys_x64_mingw"
  1159      host_system_name = "local"
  1160      target_system_name = "local"
  1161      target_cpu = "x64_windows"
  1162      target_libc = "mingw"
  1163      compiler = "mingw-gcc"
  1164      abi_version = "local"
  1165      abi_libc_version = "local"
  1166      cc_target_os = None
  1167      builtin_sysroot = None
  1168      action_configs = []
  1169  
  1170      targets_windows_feature = feature(
  1171          name = "targets_windows",
  1172          implies = ["copy_dynamic_libraries_to_binary"],
  1173          enabled = True,
  1174      )
  1175  
  1176      copy_dynamic_libraries_to_binary_feature = feature(name = "copy_dynamic_libraries_to_binary")
  1177  
  1178      gcc_env_feature = feature(
  1179          name = "gcc_env",
  1180          enabled = True,
  1181          env_sets = [
  1182              env_set(
  1183                  actions = [
  1184                      ACTION_NAMES.c_compile,
  1185                      ACTION_NAMES.cpp_compile,
  1186                      ACTION_NAMES.cpp_module_compile,
  1187                      ACTION_NAMES.cpp_module_codegen,
  1188                      ACTION_NAMES.cpp_header_parsing,
  1189                      ACTION_NAMES.assemble,
  1190                      ACTION_NAMES.preprocess_assemble,
  1191                      ACTION_NAMES.cpp_link_executable,
  1192                      ACTION_NAMES.cpp_link_dynamic_library,
  1193                      ACTION_NAMES.cpp_link_nodeps_dynamic_library,
  1194                      ACTION_NAMES.cpp_link_static_library,
  1195                  ],
  1196                  env_entries = [
  1197                      env_entry(key = "PATH", value = "c:/tools/msys64/mingw64/bin"),
  1198                  ],
  1199              ),
  1200          ],
  1201      )
  1202  
  1203      msys_mingw_flags = [
  1204          "-std=gnu++0x",
  1205      ]
  1206      msys_mingw_link_flags = [
  1207          "-lstdc++",
  1208      ]
  1209  
  1210      default_compile_flags_feature = feature(
  1211          name = "default_compile_flags",
  1212          enabled = True,
  1213          flag_sets = [
  1214              flag_set(
  1215                  actions = [
  1216                      ACTION_NAMES.assemble,
  1217                      ACTION_NAMES.preprocess_assemble,
  1218                      ACTION_NAMES.linkstamp_compile,
  1219                      ACTION_NAMES.c_compile,
  1220                      ACTION_NAMES.cpp_compile,
  1221                      ACTION_NAMES.cpp_header_parsing,
  1222                      ACTION_NAMES.cpp_module_compile,
  1223                      ACTION_NAMES.cpp_module_codegen,
  1224                      ACTION_NAMES.lto_backend,
  1225                      ACTION_NAMES.clif_match,
  1226                  ],
  1227              ),
  1228              flag_set(
  1229                  actions = [
  1230                      ACTION_NAMES.linkstamp_compile,
  1231                      ACTION_NAMES.cpp_compile,
  1232                      ACTION_NAMES.cpp_header_parsing,
  1233                      ACTION_NAMES.cpp_module_compile,
  1234                      ACTION_NAMES.cpp_module_codegen,
  1235                      ACTION_NAMES.lto_backend,
  1236                      ACTION_NAMES.clif_match,
  1237                  ],
  1238                  flag_groups = ([flag_group(flags = msys_mingw_flags)] if msys_mingw_flags else []),
  1239              ),
  1240          ],
  1241      )
  1242  
  1243      compiler_param_file_feature = feature(
  1244          name = "compiler_param_file",
  1245      )
  1246  
  1247      default_link_flags_feature = feature(
  1248          name = "default_link_flags",
  1249          enabled = True,
  1250          flag_sets = [
  1251              flag_set(
  1252                  actions = all_link_actions,
  1253                  flag_groups = ([flag_group(flags = msys_mingw_link_flags)] if msys_mingw_link_flags else []),
  1254              ),
  1255          ],
  1256      )
  1257  
  1258      supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True)
  1259  
  1260      features = [
  1261          targets_windows_feature,
  1262          copy_dynamic_libraries_to_binary_feature,
  1263          gcc_env_feature,
  1264          default_compile_flags_feature,
  1265          compiler_param_file_feature,
  1266          default_link_flags_feature,
  1267          supports_dynamic_linker_feature,
  1268      ]
  1269  
  1270      cxx_builtin_include_directories = [
  1271          # This is a workaround for https://github.com/bazelbuild/bazel/issues/5087.
  1272          "C:\\botcode\\w",
  1273          "c:/tools/msys64/mingw64/",
  1274          "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\include",
  1275          "C:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.6.1\\include\\um",
  1276          "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\ucrt",
  1277          "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\shared",
  1278          "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\um",
  1279          "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\winrt",
  1280          "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\cppwinrt",
  1281      ]
  1282  
  1283      artifact_name_patterns = [
  1284          artifact_name_pattern(
  1285              category_name = "executable",
  1286              prefix = "",
  1287              extension = ".exe",
  1288          ),
  1289      ]
  1290  
  1291      make_variables = []
  1292      tool_paths = [
  1293          tool_path(name = "ar", path = "c:/tools/msys64/mingw64/bin/ar"),
  1294          tool_path(name = "compat-ld", path = "c:/tools/msys64/mingw64/bin/ld"),
  1295          tool_path(name = "cpp", path = "c:/tools/msys64/mingw64/bin/cpp"),
  1296          tool_path(name = "dwp", path = "c:/tools/msys64/mingw64/bin/dwp"),
  1297          tool_path(name = "gcc", path = "c:/tools/msys64/mingw64/bin/gcc"),
  1298          tool_path(name = "gcov", path = "c:/tools/msys64/mingw64/bin/gcov"),
  1299          tool_path(name = "ld", path = "c:/tools/msys64/mingw64/bin/ld"),
  1300          tool_path(name = "nm", path = "c:/tools/msys64/mingw64/bin/nm"),
  1301          tool_path(name = "objcopy", path = "c:/tools/msys64/mingw64/bin/objcopy"),
  1302          tool_path(name = "objdump", path = "c:/tools/msys64/mingw64/bin/objdump"),
  1303          tool_path(name = "strip", path = "c:/tools/msys64/mingw64/bin/strip"),
  1304      ]
  1305  
  1306      return cc_common.create_cc_toolchain_config_info(
  1307          ctx = ctx,
  1308          features = features,
  1309          action_configs = action_configs,
  1310          artifact_name_patterns = artifact_name_patterns,
  1311          cxx_builtin_include_directories = cxx_builtin_include_directories,
  1312          toolchain_identifier = toolchain_identifier,
  1313          host_system_name = host_system_name,
  1314          target_system_name = target_system_name,
  1315          target_cpu = target_cpu,
  1316          target_libc = target_libc,
  1317          compiler = compiler,
  1318          abi_version = abi_version,
  1319          abi_libc_version = abi_libc_version,
  1320          tool_paths = tool_paths,
  1321          make_variables = make_variables,
  1322          builtin_sysroot = builtin_sysroot,
  1323          cc_target_os = cc_target_os,
  1324      )
  1325  
  1326  def _armeabi_impl(ctx):
  1327      toolchain_identifier = "stub_armeabi-v7a"
  1328      host_system_name = "armeabi-v7a"
  1329      target_system_name = "armeabi-v7a"
  1330      target_cpu = "armeabi-v7a"
  1331      target_libc = "armeabi-v7a"
  1332      compiler = "compiler"
  1333      abi_version = "armeabi-v7a"
  1334      abi_libc_version = "armeabi-v7a"
  1335      cc_target_os = None
  1336      builtin_sysroot = None
  1337      action_configs = []
  1338  
  1339      supports_pic_feature = feature(name = "supports_pic", enabled = True)
  1340      supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True)
  1341      features = [supports_dynamic_linker_feature, supports_pic_feature]
  1342  
  1343      cxx_builtin_include_directories = [
  1344          # This is a workaround for https://github.com/bazelbuild/bazel/issues/5087.
  1345          "C:\\botcode\\w",
  1346      ]
  1347      artifact_name_patterns = []
  1348      make_variables = []
  1349  
  1350      tool_paths = [
  1351          tool_path(name = "ar", path = "/bin/false"),
  1352          tool_path(name = "compat-ld", path = "/bin/false"),
  1353          tool_path(name = "cpp", path = "/bin/false"),
  1354          tool_path(name = "dwp", path = "/bin/false"),
  1355          tool_path(name = "gcc", path = "/bin/false"),
  1356          tool_path(name = "gcov", path = "/bin/false"),
  1357          tool_path(name = "ld", path = "/bin/false"),
  1358          tool_path(name = "nm", path = "/bin/false"),
  1359          tool_path(name = "objcopy", path = "/bin/false"),
  1360          tool_path(name = "objdump", path = "/bin/false"),
  1361          tool_path(name = "strip", path = "/bin/false"),
  1362      ]
  1363  
  1364      return cc_common.create_cc_toolchain_config_info(
  1365          ctx = ctx,
  1366          features = features,
  1367          action_configs = action_configs,
  1368          artifact_name_patterns = artifact_name_patterns,
  1369          cxx_builtin_include_directories = cxx_builtin_include_directories,
  1370          toolchain_identifier = toolchain_identifier,
  1371          host_system_name = host_system_name,
  1372          target_system_name = target_system_name,
  1373          target_cpu = target_cpu,
  1374          target_libc = target_libc,
  1375          compiler = compiler,
  1376          abi_version = abi_version,
  1377          abi_libc_version = abi_libc_version,
  1378          tool_paths = tool_paths,
  1379          make_variables = make_variables,
  1380          builtin_sysroot = builtin_sysroot,
  1381          cc_target_os = cc_target_os,
  1382      )
  1383  
  1384  def _impl(ctx):
  1385      if ctx.attr.cpu == "armeabi-v7a":
  1386          return _armeabi_impl(ctx)
  1387      elif ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "msvc-cl":
  1388          return _windows_msvc_impl(ctx)
  1389      elif ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "mingw-gcc":
  1390          return _windows_msys_mingw_impl(ctx)
  1391  
  1392      tool_paths = [
  1393          tool_path(name = "ar", path = "c:/tools/msys64/usr/bin/ar"),
  1394          tool_path(name = "compat-ld", path = "c:/tools/msys64/usr/bin/ld"),
  1395          tool_path(name = "cpp", path = "c:/tools/msys64/usr/bin/cpp"),
  1396          tool_path(name = "dwp", path = "c:/tools/msys64/usr/bin/dwp"),
  1397          tool_path(name = "gcc", path = "c:/tools/msys64/usr/bin/gcc"),
  1398          tool_path(name = "gcov", path = "c:/tools/msys64/usr/bin/gcov"),
  1399          tool_path(name = "ld", path = "c:/tools/msys64/usr/bin/ld"),
  1400          tool_path(name = "nm", path = "c:/tools/msys64/usr/bin/nm"),
  1401          tool_path(name = "objcopy", path = "c:/tools/msys64/usr/bin/objcopy"),
  1402          tool_path(name = "objdump", path = "c:/tools/msys64/usr/bin/objdump"),
  1403          tool_path(name = "strip", path = "c:/tools/msys64/usr/bin/strip"),
  1404      ]
  1405  
  1406      cxx_builtin_include_directories = [
  1407          # This is a workaround for https://github.com/bazelbuild/bazel/issues/5087.
  1408          "C:\\botcode\\w",
  1409          "c:/tools/msys64/usr/",
  1410          "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\include",
  1411          "C:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.6.1\\include\\um",
  1412          "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\ucrt",
  1413          "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\shared",
  1414          "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\um",
  1415          "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\winrt",
  1416          "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\cppwinrt",
  1417      ]
  1418  
  1419      action_configs = []
  1420  
  1421      compile_flags = [
  1422      ]
  1423  
  1424      dbg_compile_flags = [
  1425      ]
  1426  
  1427      opt_compile_flags = [
  1428      ]
  1429  
  1430      cxx_flags = [
  1431          "-std=gnu++0x",
  1432      ]
  1433  
  1434      link_flags = [
  1435          "-lstdc++",
  1436      ]
  1437  
  1438      opt_link_flags = [
  1439      ]
  1440  
  1441      unfiltered_compile_flags = [
  1442      ]
  1443  
  1444      targets_windows_feature = feature(
  1445          name = "targets_windows",
  1446          implies = ["copy_dynamic_libraries_to_binary"],
  1447          enabled = True,
  1448      )
  1449  
  1450      copy_dynamic_libraries_to_binary_feature = feature(name = "copy_dynamic_libraries_to_binary")
  1451  
  1452      gcc_env_feature = feature(
  1453          name = "gcc_env",
  1454          enabled = True,
  1455          env_sets = [
  1456              env_set(
  1457                  actions = [
  1458                      ACTION_NAMES.c_compile,
  1459                      ACTION_NAMES.cpp_compile,
  1460                      ACTION_NAMES.cpp_module_compile,
  1461                      ACTION_NAMES.cpp_module_codegen,
  1462                      ACTION_NAMES.cpp_header_parsing,
  1463                      ACTION_NAMES.assemble,
  1464                      ACTION_NAMES.preprocess_assemble,
  1465                      ACTION_NAMES.cpp_link_executable,
  1466                      ACTION_NAMES.cpp_link_dynamic_library,
  1467                      ACTION_NAMES.cpp_link_nodeps_dynamic_library,
  1468                      ACTION_NAMES.cpp_link_static_library,
  1469                  ],
  1470                  env_entries = [
  1471                      env_entry(key = "PATH", value = "c:/tools/msys64/usr/bin"),
  1472                  ],
  1473              ),
  1474          ],
  1475      )
  1476  
  1477      windows_features = [
  1478          targets_windows_feature,
  1479          copy_dynamic_libraries_to_binary_feature,
  1480          gcc_env_feature,
  1481      ]
  1482  
  1483      supports_pic_feature = feature(
  1484          name = "supports_pic",
  1485          enabled = True,
  1486      )
  1487      supports_start_end_lib_feature = feature(
  1488          name = "supports_start_end_lib",
  1489          enabled = True,
  1490      )
  1491  
  1492      default_compile_flags_feature = feature(
  1493          name = "default_compile_flags",
  1494          enabled = True,
  1495          flag_sets = [
  1496              flag_set(
  1497                  actions = [
  1498                      ACTION_NAMES.assemble,
  1499                      ACTION_NAMES.preprocess_assemble,
  1500                      ACTION_NAMES.linkstamp_compile,
  1501                      ACTION_NAMES.c_compile,
  1502                      ACTION_NAMES.cpp_compile,
  1503                      ACTION_NAMES.cpp_header_parsing,
  1504                      ACTION_NAMES.cpp_module_compile,
  1505                      ACTION_NAMES.cpp_module_codegen,
  1506                      ACTION_NAMES.lto_backend,
  1507                      ACTION_NAMES.clif_match,
  1508                  ],
  1509                  flag_groups = ([flag_group(flags = compile_flags)] if compile_flags else []),
  1510              ),
  1511              flag_set(
  1512                  actions = [
  1513                      ACTION_NAMES.assemble,
  1514                      ACTION_NAMES.preprocess_assemble,
  1515                      ACTION_NAMES.linkstamp_compile,
  1516                      ACTION_NAMES.c_compile,
  1517                      ACTION_NAMES.cpp_compile,
  1518                      ACTION_NAMES.cpp_header_parsing,
  1519                      ACTION_NAMES.cpp_module_compile,
  1520                      ACTION_NAMES.cpp_module_codegen,
  1521                      ACTION_NAMES.lto_backend,
  1522                      ACTION_NAMES.clif_match,
  1523                  ],
  1524                  flag_groups = ([flag_group(flags = dbg_compile_flags)] if dbg_compile_flags else []),
  1525                  with_features = [with_feature_set(features = ["dbg"])],
  1526              ),
  1527              flag_set(
  1528                  actions = [
  1529                      ACTION_NAMES.assemble,
  1530                      ACTION_NAMES.preprocess_assemble,
  1531                      ACTION_NAMES.linkstamp_compile,
  1532                      ACTION_NAMES.c_compile,
  1533                      ACTION_NAMES.cpp_compile,
  1534                      ACTION_NAMES.cpp_header_parsing,
  1535                      ACTION_NAMES.cpp_module_compile,
  1536                      ACTION_NAMES.cpp_module_codegen,
  1537                      ACTION_NAMES.lto_backend,
  1538                      ACTION_NAMES.clif_match,
  1539                  ],
  1540                  flag_groups = ([flag_group(flags = opt_compile_flags)] if opt_compile_flags else []),
  1541                  with_features = [with_feature_set(features = ["opt"])],
  1542              ),
  1543              flag_set(
  1544                  actions = [
  1545                      ACTION_NAMES.linkstamp_compile,
  1546                      ACTION_NAMES.cpp_compile,
  1547                      ACTION_NAMES.cpp_header_parsing,
  1548                      ACTION_NAMES.cpp_module_compile,
  1549                      ACTION_NAMES.cpp_module_codegen,
  1550                      ACTION_NAMES.lto_backend,
  1551                      ACTION_NAMES.clif_match,
  1552                  ],
  1553                  flag_groups = ([flag_group(flags = cxx_flags)] if cxx_flags else []),
  1554              ),
  1555          ],
  1556      )
  1557  
  1558      default_link_flags_feature = feature(
  1559          name = "default_link_flags",
  1560          enabled = True,
  1561          flag_sets = [
  1562              flag_set(
  1563                  actions = all_link_actions,
  1564                  flag_groups = ([flag_group(flags = link_flags)] if link_flags else []),
  1565              ),
  1566              flag_set(
  1567                  actions = all_link_actions,
  1568                  flag_groups = ([flag_group(flags = opt_link_flags)] if opt_link_flags else []),
  1569                  with_features = [with_feature_set(features = ["opt"])],
  1570              ),
  1571          ],
  1572      )
  1573  
  1574      dbg_feature = feature(name = "dbg")
  1575  
  1576      opt_feature = feature(name = "opt")
  1577  
  1578      sysroot_feature = feature(
  1579          name = "sysroot",
  1580          enabled = True,
  1581          flag_sets = [
  1582              flag_set(
  1583                  actions = [
  1584                      ACTION_NAMES.preprocess_assemble,
  1585                      ACTION_NAMES.linkstamp_compile,
  1586                      ACTION_NAMES.c_compile,
  1587                      ACTION_NAMES.cpp_compile,
  1588                      ACTION_NAMES.cpp_header_parsing,
  1589                      ACTION_NAMES.cpp_module_compile,
  1590                      ACTION_NAMES.cpp_module_codegen,
  1591                      ACTION_NAMES.lto_backend,
  1592                      ACTION_NAMES.clif_match,
  1593                      ACTION_NAMES.cpp_link_executable,
  1594                      ACTION_NAMES.cpp_link_dynamic_library,
  1595                      ACTION_NAMES.cpp_link_nodeps_dynamic_library,
  1596                  ],
  1597                  flag_groups = [
  1598                      flag_group(
  1599                          flags = ["--sysroot=%{sysroot}"],
  1600                          expand_if_available = "sysroot",
  1601                      ),
  1602                  ],
  1603              ),
  1604          ],
  1605      )
  1606  
  1607      fdo_optimize_feature = feature(
  1608          name = "fdo_optimize",
  1609          flag_sets = [
  1610              flag_set(
  1611                  actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],
  1612                  flag_groups = [
  1613                      flag_group(
  1614                          flags = [
  1615                              "-fprofile-use=%{fdo_profile_path}",
  1616                              "-fprofile-correction",
  1617                          ],
  1618                          expand_if_available = "fdo_profile_path",
  1619                      ),
  1620                  ],
  1621              ),
  1622          ],
  1623          provides = ["profile"],
  1624      )
  1625  
  1626      supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True)
  1627  
  1628      user_compile_flags_feature = feature(
  1629          name = "user_compile_flags",
  1630          enabled = True,
  1631          flag_sets = [
  1632              flag_set(
  1633                  actions = [
  1634                      ACTION_NAMES.assemble,
  1635                      ACTION_NAMES.preprocess_assemble,
  1636                      ACTION_NAMES.linkstamp_compile,
  1637                      ACTION_NAMES.c_compile,
  1638                      ACTION_NAMES.cpp_compile,
  1639                      ACTION_NAMES.cpp_header_parsing,
  1640                      ACTION_NAMES.cpp_module_compile,
  1641                      ACTION_NAMES.cpp_module_codegen,
  1642                      ACTION_NAMES.lto_backend,
  1643                      ACTION_NAMES.clif_match,
  1644                  ],
  1645                  flag_groups = [
  1646                      flag_group(
  1647                          flags = ["%{user_compile_flags}"],
  1648                          iterate_over = "user_compile_flags",
  1649                          expand_if_available = "user_compile_flags",
  1650                      ),
  1651                  ],
  1652              ),
  1653          ],
  1654      )
  1655  
  1656      unfiltered_compile_flags_feature = feature(
  1657          name = "unfiltered_compile_flags",
  1658          enabled = True,
  1659          flag_sets = [
  1660              flag_set(
  1661                  actions = [
  1662                      ACTION_NAMES.assemble,
  1663                      ACTION_NAMES.preprocess_assemble,
  1664                      ACTION_NAMES.linkstamp_compile,
  1665                      ACTION_NAMES.c_compile,
  1666                      ACTION_NAMES.cpp_compile,
  1667                      ACTION_NAMES.cpp_header_parsing,
  1668                      ACTION_NAMES.cpp_module_compile,
  1669                      ACTION_NAMES.cpp_module_codegen,
  1670                      ACTION_NAMES.lto_backend,
  1671                      ACTION_NAMES.clif_match,
  1672                  ],
  1673                  flag_groups = ([flag_group(flags = unfiltered_compile_flags)] if unfiltered_compile_flags else []),
  1674              ),
  1675          ],
  1676      )
  1677  
  1678      features = windows_features + [
  1679          supports_pic_feature,
  1680          default_compile_flags_feature,
  1681          default_link_flags_feature,
  1682          fdo_optimize_feature,
  1683          supports_dynamic_linker_feature,
  1684          dbg_feature,
  1685          opt_feature,
  1686          user_compile_flags_feature,
  1687          sysroot_feature,
  1688          unfiltered_compile_flags_feature,
  1689      ]
  1690  
  1691      artifact_name_patterns = [
  1692          artifact_name_pattern(category_name = "executable", prefix = "", extension = ".exe"),
  1693      ]
  1694  
  1695      make_variables = []
  1696  
  1697      return cc_common.create_cc_toolchain_config_info(
  1698          ctx = ctx,
  1699          features = features,
  1700          action_configs = action_configs,
  1701          artifact_name_patterns = artifact_name_patterns,
  1702          cxx_builtin_include_directories = cxx_builtin_include_directories,
  1703          toolchain_identifier = "msys_x64",
  1704          host_system_name = "local",
  1705          target_system_name = "local",
  1706          target_cpu = "x64_windows",
  1707          target_libc = "msys",
  1708          compiler = "msys-gcc",
  1709          abi_version = "local",
  1710          abi_libc_version = "local",
  1711          tool_paths = tool_paths,
  1712          make_variables = make_variables,
  1713          builtin_sysroot = "",
  1714          cc_target_os = None,
  1715      )
  1716  
  1717  cc_toolchain_config = rule(
  1718      implementation = _impl,
  1719      attrs = {
  1720          "cpu": attr.string(mandatory = True),
  1721          "compiler": attr.string(),
  1722      },
  1723      provides = [CcToolchainConfigInfo],
  1724  )