• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2023 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"""Implementation of current_py_cc_headers rule."""
16
17def _current_py_cc_headers_impl(ctx):
18    py_cc_toolchain = ctx.toolchains["//python/cc:toolchain_type"].py_cc_toolchain
19    return py_cc_toolchain.headers.providers_map.values()
20
21current_py_cc_headers = rule(
22    implementation = _current_py_cc_headers_impl,
23    toolchains = ["//python/cc:toolchain_type"],
24    provides = [CcInfo],
25    doc = """\
26Provides the currently active Python toolchain's C headers.
27
28This is a wrapper around the underlying `cc_library()` for the
29C headers for the consuming target's currently active Python toolchain.
30
31To use, simply depend on this target where you would have wanted the
32toolchain's underlying `:python_headers` target:
33
34```starlark
35cc_library(
36    name = "foo",
37    deps = ["@rules_python//python/cc:current_py_cc_headers"]
38)
39```
40""",
41)
42