Files
ortools-clone/patches/pybind11_bazel.patch
2024-07-12 13:56:11 +02:00

86 lines
2.5 KiB
Diff

diff --git a/build_defs.bzl b/build_defs.bzl
index 503ce33..e233bb0 100644
--- a/build_defs.bzl
+++ b/build_defs.bzl
@@ -5,8 +5,6 @@
"""Build rules for pybind11."""
-load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
-
def register_extension_info(**kwargs):
pass
@@ -42,12 +40,19 @@ def pybind_extension(
linkopts = [],
tags = [],
deps = [],
+ py_deps = [],
+ visibility = None,
**kwargs):
# Mark common dependencies as required for build_cleaner.
tags = tags + ["req_dep=%s" % dep for dep in PYBIND_DEPS]
native.cc_binary(
name = name + ".so",
+ target_compatible_with = select({
+ "@platforms//os:windows": ["@platforms//:incompatible"],
+ "//conditions:default": [],
+ }),
+ visibility = visibility,
copts = copts + PYBIND_COPTS + select({
Label("@pybind11//:msvc_compiler"): [],
"//conditions:default": ["-fvisibility=hidden"],
@@ -64,19 +69,42 @@ def pybind_extension(
**kwargs
)
- copy_file(
- name = name + "_copy_so_to_pyd",
- src = name + ".so",
- out = name + ".pyd",
- testonly = kwargs.get("testonly")
+ native.cc_binary(
+ name = name + ".dll",
+ target_compatible_with = select({
+ "@platforms//os:windows": [],
+ "//conditions:default": ["@platforms//:incompatible"],
+ }),
+ copts = copts + PYBIND_COPTS,
+ features = features + PYBIND_FEATURES,
+ linkopts = linkopts,
+ linkshared = 1,
+ tags = tags,
+ deps = deps + PYBIND_DEPS,
+ visibility = visibility,
+ **kwargs
+ )
+
+ native.genrule(
+ name = name + "_pyd",
+ target_compatible_with = select({
+ "@platforms//os:windows": [],
+ "//conditions:default": ["@platforms//:incompatible"],
+ }),
+ srcs = [name + ".dll"],
+ outs = [name + ".pyd"],
+ cmd = "cp $< $@",
+ visibility = visibility,
)
- native.alias(
+ native.py_library(
name = name,
- actual = select({
- "@platforms//os:windows": name + ".pyd",
- "//conditions:default": name + ".so",
+ data = select({
+ "@platforms//os:windows": [":" + name + ".pyd"],
+ "//conditions:default": [":" + name + ".so"],
}),
+ deps = py_deps,
+ visibility = visibility,
)
# Builds a pybind11 compatible library. This can be linked to a pybind_extension.