File: pybind11_bazel.patch

package info (click to toggle)
tensorflow 2.14.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 359,396 kB
  • sloc: cpp: 2,418,453; python: 736,954; java: 20,254; ansic: 18,962; sh: 9,279; pascal: 7,941; objc: 1,584; xml: 988; ada: 727; cs: 273; perl: 150; makefile: 92
file content (37 lines) | stat: -rw-r--r-- 1,094 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
diff --git a/build_defs.bzl b/build_defs.bzl
index cde1e93..03f14a5 100644
--- a/build_defs.bzl
+++ b/build_defs.bzl
@@ -27,7 +27,9 @@ PYBIND_DEPS = [
 
 # Builds a Python extension module using pybind11.
 # This can be directly used in python with the import statement.
-# This adds rules for a .so binary file.
+# This adds rules for .so and .pyd binary files, as well as
+# a base target that selects between them depending on the platform
+# (.pyd for windows, .so otherwise).
 def pybind_extension(
         name,
         copts = [],
@@ -59,6 +61,21 @@ def pybind_extension(
         **kwargs
     )
 
+    native.genrule(
+        name = name + "_pyd",
+        srcs = [name + ".so"],
+        outs = [name + ".pyd"],
+        cmd = "cp $< $@",
+    )
+
+    native.py_library(
+        name = name,
+        data = select({
+            "@platforms//os:windows": [":" + name + ".pyd"],
+            "//conditions:default": [":" + name + ".so"],
+        }),
+    )
+
 # Builds a pybind11 compatible library. This can be linked to a pybind_extension.
 def pybind_library(
         name,