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 py_cc_toolchain rule. 16 17NOTE: This is a beta-quality feature. APIs subject to change until 18https://github.com/bazelbuild/rules_python/issues/824 is considered done. 19""" 20 21load(":py_cc_toolchain_info.bzl", "PyCcToolchainInfo") 22 23def _py_cc_toolchain_impl(ctx): 24 py_cc_toolchain = PyCcToolchainInfo( 25 headers = struct( 26 providers_map = { 27 "CcInfo": ctx.attr.headers[CcInfo], 28 "DefaultInfo": ctx.attr.headers[DefaultInfo], 29 }, 30 ), 31 python_version = ctx.attr.python_version, 32 ) 33 return [platform_common.ToolchainInfo( 34 py_cc_toolchain = py_cc_toolchain, 35 )] 36 37py_cc_toolchain = rule( 38 implementation = _py_cc_toolchain_impl, 39 attrs = { 40 "headers": attr.label( 41 doc = ("Target that provides the Python headers. Typically this " + 42 "is a cc_library target."), 43 providers = [CcInfo], 44 mandatory = True, 45 ), 46 "python_version": attr.string( 47 doc = "The Major.minor Python version, e.g. 3.11", 48 mandatory = True, 49 ), 50 }, 51 doc = """\ 52A toolchain for a Python runtime's C/C++ information (e.g. headers) 53 54This rule carries information about the C/C++ side of a Python runtime, e.g. 55headers, shared libraries, etc. 56""", 57) 58