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,
