Skip to content

Commit d80a5f6

Browse files
committed
[bazel] Add support for pybind
Previously these targets were disabled, but with a relatively new rules_python we can build these pointing at a hermetic python, which allows us to build these safely. Users can still access the files directly if they need to customize how these are built.
1 parent 09a275e commit d80a5f6

File tree

3 files changed

+48
-68
lines changed

3 files changed

+48
-68
lines changed

utils/bazel/WORKSPACE

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ load("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure")
2727

2828
llvm_configure(name = "llvm-project")
2929

30+
maybe(
31+
http_archive,
32+
name = "rules_python",
33+
sha256 = "778aaeab3e6cfd56d681c89f5c10d7ad6bf8d2f1a72de9de55b23081b2d31618",
34+
strip_prefix = "rules_python-0.34.0",
35+
url = "https://github.com/bazelbuild/rules_python/releases/download/0.34.0/rules_python-0.34.0.tar.gz",
36+
)
37+
3038
maybe(
3139
http_archive,
3240
name = "llvm_zlib",
@@ -129,3 +137,21 @@ maybe(
129137
"https://github.com/facebook/zstd/releases/download/v1.5.2/zstd-1.5.2.tar.gz",
130138
],
131139
)
140+
141+
maybe(
142+
http_archive,
143+
name = "pybind11",
144+
build_file = "@llvm-raw//utils/bazel/third_party_build:pybind.BUILD",
145+
sha256 = "201966a61dc826f1b1879a24a3317a1ec9214a918c8eb035be2f30c3e9cfbdcb",
146+
strip_prefix = "pybind11-2.10.3",
147+
url = "https://github.com/pybind/pybind11/archive/v2.10.3.zip",
148+
)
149+
150+
load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains")
151+
152+
py_repositories()
153+
154+
python_register_toolchains(
155+
name = "python_3_10",
156+
python_version = "3.10",
157+
)

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

Lines changed: 7 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -917,19 +917,6 @@ exports_files(
917917
glob(["lib/Bindings/Python/**/*.cpp"]),
918918
)
919919

920-
# In the targets related to Python bindings, the projects @pybind11 and
921-
# @local_config_python are defined by @pybind11_bazel. The latter contains
922-
# python headers, and can be configured in an out-of-tree bazel project via
923-
#
924-
# load("@pybind11_bazel//:python_configure.bzl", "python_configure")
925-
# python_configure(name = "local_config_python")
926-
#
927-
# For more up-to-date instructions, see
928-
# https://github.com/pybind/pybind11_bazel
929-
#
930-
# Some out-of-tree projects alias @python_runtime//:headers to
931-
# @local_config_python//:python_headers.
932-
933920
MLIR_BINDINGS_PYTHON_HEADERS = [
934921
"lib/Bindings/Python/*.h",
935922
"include/mlir-c/Bindings/Python/*.h",
@@ -942,16 +929,12 @@ cc_library(
942929
"include",
943930
"lib/Bindings/Python",
944931
],
945-
tags = [
946-
"manual", # External dependency
947-
"nobuildkite", # TODO(gcmn): Add support for this target
948-
],
949932
textual_hdrs = glob(MLIR_BINDINGS_PYTHON_HEADERS),
950933
deps = [
951934
":CAPIIRHeaders",
952935
":CAPITransformsHeaders",
953-
"@local_config_python//:python_headers",
954936
"@pybind11",
937+
"@rules_python//python/cc:current_py_cc_headers",
955938
],
956939
)
957940

@@ -961,16 +944,12 @@ cc_library(
961944
"include",
962945
"lib/Bindings/Python",
963946
],
964-
tags = [
965-
"manual", # External dependency
966-
"nobuildkite", # TODO(gcmn): Add support for this target
967-
],
968947
textual_hdrs = glob(MLIR_BINDINGS_PYTHON_HEADERS),
969948
deps = [
970949
":CAPIIR",
971950
":CAPITransforms",
972-
"@local_config_python//:python_headers",
973951
"@pybind11",
952+
"@rules_python//python/cc:current_py_cc_headers",
974953
],
975954
)
976955

@@ -1001,10 +980,6 @@ cc_library(
1001980
srcs = MLIR_PYTHON_BINDINGS_SOURCES,
1002981
copts = PYBIND11_COPTS,
1003982
features = PYBIND11_FEATURES,
1004-
tags = [
1005-
"manual", # External dependency
1006-
"nobuildkite", # TODO(gcmn): Add support for this target
1007-
],
1008983
deps = [
1009984
":CAPIAsync",
1010985
":CAPIDebug",
@@ -1014,8 +989,8 @@ cc_library(
1014989
":Support",
1015990
":config",
1016991
"//llvm:Support",
1017-
"@local_config_python//:python_headers",
1018992
"@pybind11",
993+
"@rules_python//python/cc:current_py_cc_headers",
1019994
],
1020995
)
1021996

@@ -1024,31 +999,23 @@ cc_library(
1024999
srcs = MLIR_PYTHON_BINDINGS_SOURCES,
10251000
copts = PYBIND11_COPTS,
10261001
features = PYBIND11_FEATURES,
1027-
tags = [
1028-
"manual", # External dependency
1029-
"nobuildkite", # TODO(gcmn): Add support for this target
1030-
],
10311002
deps = [
10321003
":CAPIAsyncHeaders",
10331004
":CAPIDebugHeaders",
10341005
":CAPIIRHeaders",
1035-
":config",
10361006
":MLIRBindingsPythonHeaders",
10371007
":Support",
1008+
":config",
10381009
"//llvm:Support",
1039-
"@local_config_python//:python_headers",
10401010
"@pybind11",
1011+
"@rules_python//python/cc:current_py_cc_headers",
10411012
],
10421013
)
10431014

10441015
# Target that bundles together the CAPI objects needed for
10451016
# MLIRBindingsPythonCoreNoCAPI.
10461017
cc_library(
10471018
name = "MLIRBindingsPythonCAPIObjects",
1048-
tags = [
1049-
"manual", # External dependency
1050-
"nobuildkite", # TODO(gcmn): Add support for this target
1051-
],
10521019
deps = [
10531020
":CAPIAsyncObjects",
10541021
":CAPIDebugObjects",
@@ -1067,10 +1034,6 @@ cc_binary(
10671034
features = PYBIND11_FEATURES,
10681035
linkshared = 1,
10691036
linkstatic = 0,
1070-
tags = [
1071-
"manual", # External dependency
1072-
"nobuildkite", # TODO(gcmn): Add support for this target
1073-
],
10741037
deps = [
10751038
":MLIRBindingsPythonCore",
10761039
":MLIRBindingsPythonHeadersAndDeps",
@@ -1084,10 +1047,6 @@ cc_binary(
10841047
features = PYBIND11_FEATURES,
10851048
linkshared = 1,
10861049
linkstatic = 0,
1087-
tags = [
1088-
"manual", # External dependency
1089-
"nobuildkite", # TODO(gcmn): Add support for this target
1090-
],
10911050
deps = [
10921051
":CAPIIR",
10931052
":CAPILinalg",
@@ -1102,10 +1061,6 @@ cc_binary(
11021061
features = PYBIND11_FEATURES,
11031062
linkshared = 1,
11041063
linkstatic = 0,
1105-
tags = [
1106-
"manual", # External dependency
1107-
"nobuildkite",
1108-
],
11091064
deps = [
11101065
":CAPIIR",
11111066
":CAPILLVM",
@@ -1121,10 +1076,6 @@ cc_binary(
11211076
features = PYBIND11_FEATURES,
11221077
linkshared = 1,
11231078
linkstatic = 0,
1124-
tags = [
1125-
"manual", # External dependency
1126-
"nobuildkite", # TODO(gcmn): Add support for this target
1127-
],
11281079
deps = [
11291080
":CAPIIR",
11301081
":CAPIQuant",
@@ -1140,10 +1091,6 @@ cc_binary(
11401091
features = PYBIND11_FEATURES,
11411092
linkshared = 1,
11421093
linkstatic = 0,
1143-
tags = [
1144-
"manual", # External dependency
1145-
"nobuildkite", # TODO(gcmn): Add support for this target
1146-
],
11471094
deps = [
11481095
":CAPIIR",
11491096
":CAPISparseTensor",
@@ -1160,15 +1107,11 @@ cc_binary(
11601107
features = PYBIND11_FEATURES,
11611108
linkshared = 1,
11621109
linkstatic = 0,
1163-
tags = [
1164-
"manual", # External dependency
1165-
"nobuildkite", # TODO(gcmn): Add support for this target
1166-
],
11671110
deps = [
11681111
":CAPIExecutionEngine",
11691112
":MLIRBindingsPythonHeadersAndDeps",
1170-
"@local_config_python//:python_headers",
11711113
"@pybind11",
1114+
"@rules_python//python/cc:current_py_cc_headers",
11721115
],
11731116
)
11741117

@@ -1180,15 +1123,11 @@ cc_binary(
11801123
features = PYBIND11_FEATURES,
11811124
linkshared = 1,
11821125
linkstatic = 0,
1183-
tags = [
1184-
"manual", # External dependency
1185-
"nobuildkite", # TODO(gcmn): Add support for this target
1186-
],
11871126
deps = [
11881127
":CAPILinalg",
11891128
":MLIRBindingsPythonHeadersAndDeps",
1190-
"@local_config_python//:python_headers",
11911129
"@pybind11",
1130+
"@rules_python//python/cc:current_py_cc_headers",
11921131
],
11931132
)
11941133

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
cc_library(
2+
name = "pybind11",
3+
hdrs = glob(
4+
include = ["include/pybind11/**/*.h"],
5+
exclude = [
6+
# Deprecated file that just emits a warning
7+
"include/pybind11/common.h",
8+
],
9+
),
10+
includes = ["include"],
11+
visibility = ["//visibility:public"],
12+
deps = [
13+
"@rules_python//python/cc:current_py_cc_headers",
14+
],
15+
)

0 commit comments

Comments
 (0)