1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15- """Implementation of current_py_cc_headers rule."""
15+ """Implementation of current_py_cc_headers and current_py_cc_headers_abi3 rules.
16+ """
1617
1718load ("@rules_cc//cc/common:cc_info.bzl" , "CcInfo" )
1819
@@ -24,7 +25,7 @@ current_py_cc_headers = rule(
2425 implementation = _current_py_cc_headers_impl ,
2526 toolchains = ["//python/cc:toolchain_type" ],
2627 provides = [CcInfo ],
27- doc = """\
28+ doc = """
2829Provides the currently active Python toolchain's C headers.
2930
3031This is a wrapper around the underlying `cc_library()` for the
@@ -41,3 +42,35 @@ cc_library(
4142```
4243""" ,
4344)
45+
46+ def _current_py_cc_headers_abi3_impl (ctx ):
47+ py_cc_toolchain = ctx .toolchains ["//python/cc:toolchain_type" ].py_cc_toolchain
48+ if not py_cc_toolchain .headers_abi3 :
49+ fail (
50+ "The current python toolchain does not provide ABI3 headers" .format (
51+ py_cc_toolchain .python_version ,
52+ ),
53+ )
54+ return py_cc_toolchain .headers_abi3 .providers_map .values ()
55+
56+ current_py_cc_headers_abi3 = rule (
57+ implementation = _current_py_cc_headers_abi3_impl ,
58+ toolchains = ["//python/cc:toolchain_type" ],
59+ provides = [CcInfo ],
60+ doc = """
61+ Provides the currently active Python toolchain's C ABI3 headers.
62+
63+ This is a wrapper around the underlying `cc_library()` for the
64+ C ABI3 headers for the consuming target's currently active Python toolchain.
65+
66+ To use, simply depend on this target where you would have wanted the
67+ toolchain's underlying `:python_headers_abi3` target:
68+
69+ ```starlark
70+ cc_library(
71+ name = "foo",
72+ deps = ["@rules_python//python/cc:current_py_cc_headers_abi3"]
73+ )
74+ ```
75+ """ ,
76+ )
0 commit comments