Skip to content

Add CcInfo to allowed providers of py_library deps. #550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2025

Conversation

lgulich
Copy link
Contributor

@lgulich lgulich commented Apr 10, 2025

Hi Aspect Team

This PR enables better compatibility with pybind11_bazel and makes the aspect py rules more of a drop-in replacement of the official rules_python. Please let me know if you are open to this contribution, then I can also add tests for it.

More specifically: This change is useful when using a
pybind_extension in the deps of a py_libary as the pybind_extension is just a cc_binary under the hood. This PR enables using it like so:

load("@pybind11_bazel//:build_defs.bzl", "pybind_extension")
load("@aspect_rules_python//python:defs.bzl", aspect_py_library="py_library")


pybind_extension(
    name = "my_pybind_extension",
    srcs = ["my_binding.cpp"],
)

aspect_py_library(
    name = "my_python_library",
    srcs = [":my_python_library.py"],
    deps = [":my_pybind_extension"],
)

The py_libary from the official rules_python also already supports using CcInfo providers in the deps attribute.

Without this change a workaround is to wrap the pybind_extension in a py_library from the official rules_python:

load("@pybind11_bazel//:build_defs.bzl", "pybind_extension")
load("@rules_python//python:defs.bzl", official_py_library="py_library")
load("@aspect_rules_python//python:defs.bzl", aspect_py_library="py_library")


pybind_extension(
    name = "my_pybind_extension",
    srcs = ["my_binding.cpp"],
)

official_py_library(
    name = "my_pybind_extension_wrapper",
    srcs = [],
    deps = [":my_pybind_extension"],
)

aspect_py_library(
    name = "my_python_library",
    srcs = [":my_python_library.py"],
    deps = [":my_pybind_extension_wrapper"],
)

Changes are visible to end-users: no

Test plan

TODO

@CLAassistant
Copy link

CLAassistant commented Apr 10, 2025

CLA assistant check
All committers have signed the CLA.

Copy link

aspect-workflows bot commented Apr 10, 2025

Test

1 test target passed

Targets
//py/tests/cc-deps:test_smoke [k8-fastbuild]                 1s

Total test execution time was 1s. 30 tests (96.8%) were fully cached saving 1m 14s.

@thesayyn
Copy link
Member

This sounds a like a reasonable addition. go for it.

This is required in order to use a
[pybind_extension](https://github.com/pybind/pybind11_bazel/blob/2b6082a4d9d163a52299718113fa41e4b7978db5/build_defs.bzl#L28)
in the `deps` of a `py_libary` as the `pybind_extension` is just a
`cc_binary` under the hood.

The `py_libary` from the official `rules_python` also supports this.
@thesayyn thesayyn merged commit 1043735 into aspect-build:main May 13, 2025
16 checks passed
@thesayyn
Copy link
Member

Thank you for this :)

@lgulich
Copy link
Contributor Author

lgulich commented May 15, 2025

@thesayyn thanks for merging this! When is the next release planned that will include this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants