xref: /aosp_15_r20/external/bazelbuild-rules_python/python/private/current_py_cc_headers.bzl (revision 60517a1edbc8ecf509223e9af94a7adec7d736b8)
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
17load("@rules_cc//cc:defs.bzl", "CcInfo")
18
19def _current_py_cc_headers_impl(ctx):
20    py_cc_toolchain = ctx.toolchains["//python/cc:toolchain_type"].py_cc_toolchain
21    return py_cc_toolchain.headers.providers_map.values()
22
23current_py_cc_headers = rule(
24    implementation = _current_py_cc_headers_impl,
25    toolchains = ["//python/cc:toolchain_type"],
26    provides = [CcInfo],
27    doc = """\
28Provides the currently active Python toolchain's C headers.
29
30This is a wrapper around the underlying `cc_library()` for the
31C headers for the consuming target's currently active Python toolchain.
32
33To use, simply depend on this target where you would have wanted the
34toolchain's underlying `:python_headers` target:
35
36```starlark
37cc_library(
38    name = "foo",
39    deps = ["@rules_python//python/cc:current_py_cc_headers"]
40)
41```
42""",
43)
44