Skip to content

Commit 6e4e2f8

Browse files
committed
use cc_binary to generate .pyd instead of copy file
1 parent 03de3c0 commit 6e4e2f8

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

build_defs.bzl

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,40 @@ def pybind_extension(
7575
}),
7676
linkshared = 1,
7777
tags = tags,
78+
target_compatible_with = select({
79+
"@platforms//os:windows": ["@platforms//:incompatible"],
80+
"//conditions:default": [],
81+
}),
7882
deps = deps + PYBIND_DEPS,
7983
**kwargs
8084
)
8185

82-
copy_file(
83-
name = name + "_copy_so_to_pyd",
84-
src = name + ".so",
85-
out = name + ".pyd",
86-
testonly = kwargs.get("testonly"),
87-
visibility = kwargs.get("visibility"),
86+
cc_binary(
87+
name = name + ".pyd",
88+
copts = copts + PYBIND_COPTS + select({
89+
Label("@pybind11//:msvc_compiler"): [],
90+
"//conditions:default": ["-fvisibility=hidden"],
91+
}),
92+
features = features + PYBIND_FEATURES,
93+
linkopts = linkopts + select({
94+
"@platforms//os:osx": ["-undefined", "dynamic_lookup"],
95+
Label("@pybind11//:msvc_compiler"): [],
96+
"//conditions:default": ["-Wl,-Bsymbolic"],
97+
}),
98+
linkshared = 1,
99+
tags = tags,
100+
target_compatible_with = select({
101+
"@platforms//os:windows": [],
102+
"//conditions:default": ["@platforms//:incompatible"],
103+
}),
104+
deps = deps + PYBIND_DEPS,
105+
**kwargs
88106
)
89107

90108
native.alias(
91109
name = name,
92110
actual = select({
93-
"@platforms//os:windows": name + "_copy_so_to_pyd",
111+
"@platforms//os:windows": name + ".pyd",
94112
"//conditions:default": name + ".so",
95113
}),
96114
testonly = kwargs.get("testonly"),

0 commit comments

Comments
 (0)