forked from bazel-contrib/rules_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurrent_py_cc_headers.bzl
More file actions
82 lines (69 loc) · 2.66 KB
/
current_py_cc_headers.bzl
File metadata and controls
82 lines (69 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Copyright 2023 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Implementation of current_py_cc_headers and current_py_cc_headers_abi3 rules.
"""
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
load("//python/private:toolchain_types.bzl", "PY_CC_TOOLCHAIN_TYPE")
def _current_py_cc_headers_impl(ctx):
py_cc_toolchain = ctx.toolchains[PY_CC_TOOLCHAIN_TYPE].py_cc_toolchain
return py_cc_toolchain.headers.providers_map.values()
current_py_cc_headers = rule(
implementation = _current_py_cc_headers_impl,
toolchains = [PY_CC_TOOLCHAIN_TYPE],
provides = [CcInfo],
doc = """
Provides the currently active Python toolchain's C headers.
This is a wrapper around the underlying `cc_library()` for the
C headers for the consuming target's currently active Python toolchain.
To use, simply depend on this target where you would have wanted the
toolchain's underlying `:python_headers` target:
```starlark
cc_library(
name = "foo",
deps = ["@rules_python//python/cc:current_py_cc_headers"]
)
```
""",
)
def _current_py_cc_headers_abi3_impl(ctx):
py_cc_toolchain = ctx.toolchains[PY_CC_TOOLCHAIN_TYPE].py_cc_toolchain
if not py_cc_toolchain.headers_abi3:
fail((
"The resolved {} toolchain does not provide abi3 headers. " +
"Verify the toolchain sets `.headers_abi3`, or use the " +
"`:current_py_cc_headers` target."
).format(
PY_CC_TOOLCHAIN_TYPE,
))
return py_cc_toolchain.headers_abi3.providers_map.values()
current_py_cc_headers_abi3 = rule(
implementation = _current_py_cc_headers_abi3_impl,
toolchains = [PY_CC_TOOLCHAIN_TYPE],
provides = [CcInfo],
doc = """
Provides the currently active Python toolchain's C ABI3 headers.
This is a wrapper around the underlying `cc_library()` for the
C ABI3 headers for the consuming target's currently active Python toolchain.
To use, simply depend on this target where you would have wanted the
toolchain's underlying `:python_headers_abi3` target:
```starlark
cc_library(
name = "foo",
deps = ["@rules_python//python/cc:current_py_cc_headers_abi3"]
)
```
:::{versionadded} 1.7.0
:::
""",
)