5
5
6
6
"""Build rules for pybind11."""
7
7
8
+ load ("@bazel_skylib//rules:copy_file.bzl" , "copy_file" )
9
+
8
10
def register_extension_info (** kwargs ):
9
11
pass
10
12
@@ -24,8 +26,15 @@ PYBIND_DEPS = [
24
26
]
25
27
26
28
# Builds a Python extension module using pybind11.
27
- # This can be directly used in python with the import statement.
28
- # This adds rules for a .so binary file.
29
+ # This can be directly used in Python with the import statement.
30
+ # Assuming the name NAME, the following targets will be defined:
31
+ # 1. NAME.so - the shared/dynamic library for the extension module
32
+ # 2. NAME.pyd - a copy of NAME.so named for Python on Windows; see
33
+ # https://github.com/pybind/pybind11_bazel/issues/74
34
+ # 3. NAME - an alias pointing to either NAME.so or NAME.pyd as per
35
+ # the platform OS (not-Windows or Windows, respectively)
36
+ # Generally, the user will "depend" on this extension module via the
37
+ # data attribute of their py_* target; specifying NAME is preferred.
29
38
def pybind_extension (
30
39
name ,
31
40
copts = [],
@@ -55,6 +64,20 @@ def pybind_extension(
55
64
** kwargs
56
65
)
57
66
67
+ copy_file (
68
+ name = name + "_copy_so_to_pyd" ,
69
+ src = name + ".so" ,
70
+ out = name + ".pyd" ,
71
+ )
72
+
73
+ native .alias (
74
+ name = name ,
75
+ actual = select ({
76
+ "@platforms//os:windows" : name + ".pyd" ,
77
+ "//conditions:default" : name + ".so" ,
78
+ }),
79
+ )
80
+
58
81
# Builds a pybind11 compatible library. This can be linked to a pybind_extension.
59
82
def pybind_library (
60
83
name ,
0 commit comments