Skip to content

[Question] - How do you acess the "@rules_python//python/cc:current_py_cc_headers" when working with multiple versions? #2132

@tenspd137

Description

@tenspd137

I have C++ module that I use pybind11_bazel to compile and then pass on to python rules and eventually generate a wheel. For one version - works great. The docs and examples show that you can use multiple versions of python using the extension with multiple calls to python.toolchain:

python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
    configure_coverage_tool = True,
    python_version = "3.8",
)
python.toolchain(
    configure_coverage_tool = True,
    # Only set when you have mulitple toolchain versions.
    is_default = True,
    python_version = "3.9",
)
python.toolchain(
    configure_coverage_tool = True,
    python_version = "3.10",
)
python.toolchain(
    configure_coverage_tool = True,
    python_version = "3.11",
)
use_repo(
    python,
    python = "python_versions",
)

and then use like this:

load("@python//3.8:defs.bzl", py_binary_3_8 = "py_binary", py_test_3_8 = "py_test")
....
py_binary_3_8(
    name = "version_3_8",
    srcs = ["version.py"],
    main = "version.py",
)

This makes sense - but I can't seem to figure out how to access the equivalent of "@rules_python//python/cc:current_py_cc_headers" for different versions, which you need to pass on to pybind11 in order to have the correct headers for multi-version module builds. Any ideas? I can't seem to find any examples, and I am learning Bazel, so the source code still doesn't make sense to me yet beyond how to use it (limited).

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions