Skip to content

Commit 0e26f29

Browse files
committed
Add CcInfo to allowed providers of py_library deps.
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.
1 parent 1296c6b commit 0e26f29

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

py/private/py_library.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ _attrs = dict({
205205
),
206206
"deps": attr.label_list(
207207
doc = "Targets that produce Python code, commonly `py_library` rules.",
208-
providers = [[PyInfo], [PyVirtualInfo]],
208+
providers = [[PyInfo], [PyVirtualInfo], [CcInfo]],
209209
),
210210
"data": attr.label_list(
211211
doc = """Runtime dependencies of the program.

py/tests/cc-deps/BUILD.bazel

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
load("//py:defs.bzl", "py_test")
2+
3+
# Test that cc targets can be used as deps for py targets.
4+
# We only add a very simple test to not pull in all the deps
5+
# to build proper py-bindings.
6+
cc_library(
7+
name = "example_library",
8+
srcs = ["example_library.cpp"],
9+
)
10+
11+
py_test(
12+
name = "test_smoke",
13+
srcs = ["test_smoke.py"],
14+
deps = [":example_library"],
15+
)

py/tests/cc-deps/example_library.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
int add(int i, int j) { return i + j; }
3+

py/tests/cc-deps/test_smoke.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def main():
2+
print("Running successfully!")
3+
4+
if __name__ == "__main__":
5+
main()

0 commit comments

Comments
 (0)