1# Copyright 2024 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_libs rule.""" 16 17load("@rules_cc//cc:defs.bzl", "CcInfo") 18 19def _current_py_cc_libs_impl(ctx): 20 py_cc_toolchain = ctx.toolchains["//python/cc:toolchain_type"].py_cc_toolchain 21 return py_cc_toolchain.libs.providers_map.values() 22 23current_py_cc_libs = rule( 24 implementation = _current_py_cc_libs_impl, 25 toolchains = ["//python/cc:toolchain_type"], 26 provides = [CcInfo], 27 doc = """\ 28Provides the currently active Python toolchain's C libraries. 29 30This is a wrapper around the underlying `cc_library()` for the 31C libraries 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 `:libpython` target: 35 36```starlark 37cc_library( 38 name = "foo", 39 deps = ["@rules_python//python/cc:current_py_cc_libs"] 40) 41``` 42""", 43) 44