Skip to content

Commit 5585ddd

Browse files
authored
[bazel]: de-alias pybind11 headers target (#79676)
In trying to set up python headers in an out-of-tree bazel MLIR project, I encountered the `pybind11_bazel` project, and found that the `@python_runtime` target used here is not defined by it. Instead, it seems that `@python_runtime` is an alias used in some projects like Tensorflow (see https://github.com/tensorflow/tensorflow/blob/322936ffdd96ee59e27d028467fe458859cf3855/third_party/python_runtime/BUILD#L7-L7), where it is aliased to `@local_config_python`. In fact, `@local_config_python` is defined by `@pybind11_bazel`, and so it seems that this layer of indirection no longer serves a purpose, and instead just prevents anyone who doesn't clone Tensorflow's config from using the python bindings here. This commit updates the dependent targets to their canonical de-aliased equivalents, and I suspect this will not even break any downstream users since the new target is defined in those projects already. Without this change, running, for example ``` bazel build @llvm-project//mlir:MLIRBindingsPythonCore ``` gives the error ``` no such package '@python_runtime//': The repository '@python_runtime' could not be resolved: Repository '@python_runtime' is not defined and referenced by '@llvm-project//mlir:MLIRBindingsPythonCore' ``` Minimal reproduction in https://github.com/j2kun/test_mlir_bazel_pybind, which, when pointing to a local LLVM repository that has this change (see `bazel/import_llvm.bzl` in that repository), results in that build succeeding. Hat tip to Maksim Levental for going on an hours-long investigation with me to figure this out.
1 parent 7595287 commit 5585ddd

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

utils/bazel/llvm-project-overlay/mlir/BUILD.bazel

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,19 @@ exports_files(
870870
glob(["lib/Bindings/Python/**/*.cpp"]),
871871
)
872872

873+
# In the targets related to Python bindings, the projects @pybind11 and
874+
# @local_config_python are defined by @pybind11_bazel. The latter contains
875+
# python headers, and can be configured in an out-of-tree bazel project via
876+
#
877+
# load("@pybind11_bazel//:python_configure.bzl", "python_configure")
878+
# python_configure(name = "local_config_python")
879+
#
880+
# For more up-to-date instructions, see
881+
# https://github.com/pybind/pybind11_bazel
882+
#
883+
# Some out-of-tree projects alias @python_runtime//:headers to
884+
# @local_config_python//:python_headers.
885+
873886
MLIR_BINDINGS_PYTHON_HEADERS = [
874887
"lib/Bindings/Python/*.h",
875888
"include/mlir-c/Bindings/Python/*.h",
@@ -890,7 +903,7 @@ cc_library(
890903
deps = [
891904
":CAPIIRHeaders",
892905
"@pybind11",
893-
"@python_runtime//:headers",
906+
"@local_config_python//:python_headers",
894907
],
895908
)
896909

@@ -908,7 +921,7 @@ cc_library(
908921
deps = [
909922
":CAPIIR",
910923
"@pybind11",
911-
"@python_runtime//:headers",
924+
"@local_config_python//:python_headers",
912925
],
913926
)
914927

@@ -951,7 +964,7 @@ cc_library(
951964
":Support",
952965
"//llvm:Support",
953966
"@pybind11",
954-
"@python_runtime//:headers",
967+
"@local_config_python//:python_headers",
955968
],
956969
)
957970

@@ -971,7 +984,7 @@ cc_library(
971984
":MLIRBindingsPythonHeaders",
972985
"//llvm:Support",
973986
"@pybind11",
974-
"@python_runtime//:headers",
987+
"@local_config_python//:python_headers",
975988
],
976989
)
977990

@@ -1082,7 +1095,7 @@ cc_binary(
10821095
":CAPIExecutionEngine",
10831096
":MLIRBindingsPythonHeadersAndDeps",
10841097
"@pybind11",
1085-
"@python_runtime//:headers",
1098+
"@local_config_python//:python_headers",
10861099
],
10871100
)
10881101

@@ -1102,7 +1115,7 @@ cc_binary(
11021115
":CAPILinalg",
11031116
":MLIRBindingsPythonHeadersAndDeps",
11041117
"@pybind11",
1105-
"@python_runtime//:headers",
1118+
"@local_config_python//:python_headers",
11061119
],
11071120
)
11081121

0 commit comments

Comments
 (0)