kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/cxx/extractor/toolchain.bzl (about)

     1  #
     2  # Copyright 2019 The Kythe Authors. All rights reserved.
     3  #
     4  # Licensed under the Apache License, Version 2.0 (the "License");
     5  # you may not use this file except in compliance with the License.
     6  # You may obtain a copy of the License at
     7  #
     8  #   http://www.apache.org/licenses/LICENSE-2.0
     9  #
    10  # Unless required by applicable law or agreed to in writing, software
    11  # distributed under the License is distributed on an "AS IS" BASIS,
    12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  #
    16  """C++ Verifier toolchain support rules and macros."""
    17  
    18  load("//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain", "use_cpp_toolchain")
    19  
    20  CxxExtractorToolchainInfo = provider(
    21      doc = "Provides required information for C++/ObjectiveC extractors.",
    22      fields = [
    23          "cc_toolchain",
    24          "extractor_binary",
    25          "compiler_executable",
    26      ],
    27  )
    28  
    29  CXX_EXTRACTOR_TOOLCHAINS = ["@io_kythe//kythe/cxx/extractor:toolchain_type"]
    30  
    31  def _cxx_extractor_toolchain_impl(ctx):
    32      cc_toolchain = find_cpp_toolchain(ctx)
    33      if ctx.attr.compiler_executable:
    34          compiler_executable = ctx.attr.compiler_executable
    35      else:
    36          compiler_executable = cc_toolchain.compiler_executable
    37      cxx_extractor = CxxExtractorToolchainInfo(
    38          cc_toolchain = cc_toolchain,
    39          compiler_executable = compiler_executable,
    40          extractor_binary = ctx.attr.extractor.files_to_run,
    41      )
    42      return [
    43          platform_common.ToolchainInfo(
    44              cxx_extractor_info = cxx_extractor,
    45          ),
    46          cxx_extractor,
    47      ]
    48  
    49  cxx_extractor_toolchain = rule(
    50      attrs = {
    51          "extractor": attr.label(
    52              executable = True,
    53              default = Label("//kythe/cxx/extractor:cxx_extractor"),
    54              cfg = "exec",
    55          ),
    56          "compiler_executable": attr.string(),
    57          "_cc_toolchain": attr.label(
    58              default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"),
    59          ),
    60      },
    61      fragments = ["cpp"],
    62      provides = [
    63          CxxExtractorToolchainInfo,
    64          platform_common.ToolchainInfo,
    65      ],
    66      toolchains = use_cpp_toolchain(),
    67      implementation = _cxx_extractor_toolchain_impl,
    68  )
    69  
    70  def register_toolchains():
    71      native.register_toolchains(
    72          "@io_kythe//kythe/cxx/extractor:linux_toolchain",
    73          "@io_kythe//kythe/cxx/extractor:macos_toolchain",
    74      )
    75  
    76  def find_extractor_toolchains(ctx):
    77      runtimes_deps = []  # The default toolchain has no runtime dependencies.
    78      if "@io_kythe//kythe/cxx/extractor:toolchain_type" in ctx.toolchains:
    79          return ctx.toolchains["@io_kythe//kythe/cxx/extractor:toolchain_type"].cxx_extractor_info, runtimes_deps
    80      return ctx.attr._cxx_extractor_toolchain[CxxExtractorToolchainInfo], runtimes_deps