Skip to content

Commit 914a00a

Browse files
authored
[bazel] Add support for pybind (#98398)
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 59441f2 commit 914a00a

File tree

3 files changed

+47
-67
lines changed

3 files changed

+47
-67
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_12",
156+
python_version = "3.12",
157+
)

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

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

921-
# In the targets related to Python bindings, the projects @pybind11 and
922-
# @local_config_python are defined by @pybind11_bazel. The latter contains
923-
# python headers, and can be configured in an out-of-tree bazel project via
924-
#
925-
# load("@pybind11_bazel//:python_configure.bzl", "python_configure")
926-
# python_configure(name = "local_config_python")
927-
#
928-
# For more up-to-date instructions, see
929-
# https://github.com/pybind/pybind11_bazel
930-
#
931-
# Some out-of-tree projects alias @python_runtime//:headers to
932-
# @local_config_python//:python_headers.
933-
934921
filegroup(
935922
name = "MLIRBindingsPythonHeaderFiles",
936923
srcs = glob([
@@ -946,16 +933,12 @@ cc_library(
946933
"include",
947934
"lib/Bindings/Python",
948935
],
949-
tags = [
950-
"manual", # External dependency
951-
"nobuildkite", # TODO(gcmn): Add support for this target
952-
],
953936
textual_hdrs = [":MLIRBindingsPythonHeaderFiles"],
954937
deps = [
955938
":CAPIIRHeaders",
956939
":CAPITransformsHeaders",
957-
"@local_config_python//:python_headers",
958940
"@pybind11",
941+
"@rules_python//python/cc:current_py_cc_headers",
959942
],
960943
)
961944

@@ -965,16 +948,12 @@ cc_library(
965948
"include",
966949
"lib/Bindings/Python",
967950
],
968-
tags = [
969-
"manual", # External dependency
970-
"nobuildkite", # TODO(gcmn): Add support for this target
971-
],
972951
textual_hdrs = [":MLIRBindingsPythonHeaderFiles"],
973952
deps = [
974953
":CAPIIR",
975954
":CAPITransforms",
976-
"@local_config_python//:python_headers",
977955
"@pybind11",
956+
"@rules_python//python/cc:current_py_cc_headers",
978957
],
979958
)
980959

@@ -1008,10 +987,6 @@ cc_library(
1008987
srcs = [":MLIRBindingsPythonSourceFiles"],
1009988
copts = PYBIND11_COPTS,
1010989
features = PYBIND11_FEATURES,
1011-
tags = [
1012-
"manual", # External dependency
1013-
"nobuildkite", # TODO(gcmn): Add support for this target
1014-
],
1015990
deps = [
1016991
":CAPIAsync",
1017992
":CAPIDebug",
@@ -1021,8 +996,8 @@ cc_library(
1021996
":Support",
1022997
":config",
1023998
"//llvm:Support",
1024-
"@local_config_python//:python_headers",
1025999
"@pybind11",
1000+
"@rules_python//python/cc:current_py_cc_headers",
10261001
],
10271002
)
10281003

@@ -1031,10 +1006,6 @@ cc_library(
10311006
srcs = [":MLIRBindingsPythonSourceFiles"],
10321007
copts = PYBIND11_COPTS,
10331008
features = PYBIND11_FEATURES,
1034-
tags = [
1035-
"manual", # External dependency
1036-
"nobuildkite", # TODO(gcmn): Add support for this target
1037-
],
10381009
deps = [
10391010
":CAPIAsyncHeaders",
10401011
":CAPIDebugHeaders",
@@ -1043,19 +1014,15 @@ cc_library(
10431014
":Support",
10441015
":config",
10451016
"//llvm:Support",
1046-
"@local_config_python//:python_headers",
10471017
"@pybind11",
1018+
"@rules_python//python/cc:current_py_cc_headers",
10481019
],
10491020
)
10501021

10511022
# Target that bundles together the CAPI objects needed for
10521023
# MLIRBindingsPythonCoreNoCAPI.
10531024
cc_library(
10541025
name = "MLIRBindingsPythonCAPIObjects",
1055-
tags = [
1056-
"manual", # External dependency
1057-
"nobuildkite", # TODO(gcmn): Add support for this target
1058-
],
10591026
deps = [
10601027
":CAPIAsyncObjects",
10611028
":CAPIDebugObjects",
@@ -1074,10 +1041,6 @@ cc_binary(
10741041
features = PYBIND11_FEATURES,
10751042
linkshared = 1,
10761043
linkstatic = 0,
1077-
tags = [
1078-
"manual", # External dependency
1079-
"nobuildkite", # TODO(gcmn): Add support for this target
1080-
],
10811044
deps = [
10821045
":MLIRBindingsPythonCore",
10831046
":MLIRBindingsPythonHeadersAndDeps",
@@ -1091,10 +1054,6 @@ cc_binary(
10911054
features = PYBIND11_FEATURES,
10921055
linkshared = 1,
10931056
linkstatic = 0,
1094-
tags = [
1095-
"manual", # External dependency
1096-
"nobuildkite", # TODO(gcmn): Add support for this target
1097-
],
10981057
deps = [
10991058
":CAPIIR",
11001059
":CAPILinalg",
@@ -1109,10 +1068,6 @@ cc_binary(
11091068
features = PYBIND11_FEATURES,
11101069
linkshared = 1,
11111070
linkstatic = 0,
1112-
tags = [
1113-
"manual", # External dependency
1114-
"nobuildkite",
1115-
],
11161071
deps = [
11171072
":CAPIIR",
11181073
":CAPILLVM",
@@ -1128,10 +1083,6 @@ cc_binary(
11281083
features = PYBIND11_FEATURES,
11291084
linkshared = 1,
11301085
linkstatic = 0,
1131-
tags = [
1132-
"manual", # External dependency
1133-
"nobuildkite", # TODO(gcmn): Add support for this target
1134-
],
11351086
deps = [
11361087
":CAPIIR",
11371088
":CAPIQuant",
@@ -1147,10 +1098,6 @@ cc_binary(
11471098
features = PYBIND11_FEATURES,
11481099
linkshared = 1,
11491100
linkstatic = 0,
1150-
tags = [
1151-
"manual", # External dependency
1152-
"nobuildkite", # TODO(gcmn): Add support for this target
1153-
],
11541101
deps = [
11551102
":CAPIIR",
11561103
":CAPISparseTensor",
@@ -1167,15 +1114,11 @@ cc_binary(
11671114
features = PYBIND11_FEATURES,
11681115
linkshared = 1,
11691116
linkstatic = 0,
1170-
tags = [
1171-
"manual", # External dependency
1172-
"nobuildkite", # TODO(gcmn): Add support for this target
1173-
],
11741117
deps = [
11751118
":CAPIExecutionEngine",
11761119
":MLIRBindingsPythonHeadersAndDeps",
1177-
"@local_config_python//:python_headers",
11781120
"@pybind11",
1121+
"@rules_python//python/cc:current_py_cc_headers",
11791122
],
11801123
)
11811124

@@ -1187,15 +1130,11 @@ cc_binary(
11871130
features = PYBIND11_FEATURES,
11881131
linkshared = 1,
11891132
linkstatic = 0,
1190-
tags = [
1191-
"manual", # External dependency
1192-
"nobuildkite", # TODO(gcmn): Add support for this target
1193-
],
11941133
deps = [
11951134
":CAPILinalg",
11961135
":MLIRBindingsPythonHeadersAndDeps",
1197-
"@local_config_python//:python_headers",
11981136
"@pybind11",
1137+
"@rules_python//python/cc:current_py_cc_headers",
11991138
],
12001139
)
12011140

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)