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,
|