Skip to content

Commit 7684e03

Browse files
committed
fix dynamic library .pyd support
* should fix bazelbuild#17117 * related to bazelbuild/rules_cc#501 * needed to fix pybind/pybind11_bazel#124
1 parent 6ce603d commit 7684e03

File tree

6 files changed

+13
-10
lines changed

6 files changed

+13
-10
lines changed

src/main/java/com/google/devtools/build/lib/rules/cpp/ArtifactCategory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
public enum ArtifactCategory {
2424
STATIC_LIBRARY("lib", ".a", ".lib"),
2525
ALWAYSLINK_STATIC_LIBRARY("lib", ".lo", ".lo.lib"),
26-
DYNAMIC_LIBRARY("lib", ".so", ".dylib", ".dll", ".wasm"),
26+
DYNAMIC_LIBRARY("lib", ".so", ".dylib", ".dll", ".pyd",".wasm"),
2727
EXECUTABLE("", "", ".exe", ".wasm"),
2828
INTERFACE_LIBRARY("lib", ".ifso", ".tbd", ".if.lib", ".lib"),
2929
PIC_FILE("", ".pic"),

src/main/starlark/builtins_bzl/common/cc/cc_binary.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ def _create_transitive_linking_actions(
315315
# entries during linking process.
316316
for libs in precompiled_files[:]:
317317
for artifact in libs:
318-
if _matches([".so", ".dylib", ".dll", ".ifso", ".tbd", ".lib", ".dll.a"], artifact.basename) or cc_helper.is_valid_shared_library_artifact(artifact):
318+
if _matches([".so", ".dylib", ".dll", ".pyd", ".ifso", ".tbd", ".lib", ".dll.a"], artifact.basename) or cc_helper.is_valid_shared_library_artifact(artifact):
319319
library_to_link = cc_common.create_library_to_link(
320320
actions = ctx.actions,
321321
feature_configuration = feature_configuration,
@@ -461,7 +461,7 @@ def cc_binary_impl(ctx, additional_linkopts, force_linkstatic = False):
461461
# the target name.
462462
# This is no longer necessary, the toolchain can figure out the correct file extensions.
463463
target_name = ctx.label.name
464-
has_legacy_link_shared_name = _is_link_shared(ctx) and (_matches([".so", ".dylib", ".dll"], target_name) or cc_helper.is_valid_shared_library_name(target_name))
464+
has_legacy_link_shared_name = _is_link_shared(ctx) and (_matches([".so", ".dylib", ".dll", ".pyd"], target_name) or cc_helper.is_valid_shared_library_name(target_name))
465465
binary = None
466466
is_dbg_build = (cc_toolchain._cpp_configuration.compilation_mode() == "dbg")
467467
if has_legacy_link_shared_name:

src/main/starlark/builtins_bzl/common/cc/cc_helper.bzl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,9 @@ def _libraries_from_linking_context(linking_context):
128128
# string.endswith() checks)
129129
def _is_valid_shared_library_name(shared_library_name):
130130
if (shared_library_name.endswith(".so") or
131-
shared_library_name.endswith(".dll") or
132131
shared_library_name.endswith(".dylib") or
132+
shared_library_name.endswith(".dll") or
133+
shared_library_name.endswith(".pyd") or
133134
shared_library_name.endswith(".wasm")):
134135
return True
135136

@@ -549,7 +550,7 @@ def _get_toolchain_global_make_variables(cc_toolchain):
549550
result["CROSSTOOLTOP"] = cc_toolchain._crosstool_top_path
550551
return result
551552

552-
_SHARED_LIBRARY_EXTENSIONS = ["so", "dll", "dylib", "wasm"]
553+
_SHARED_LIBRARY_EXTENSIONS = ["so", "dylib", "dll", "pyd", "wasm"]
553554

554555
def _is_valid_shared_library_artifact(shared_library):
555556
if (shared_library.extension in _SHARED_LIBRARY_EXTENSIONS):

src/main/starlark/builtins_bzl/common/cc/cc_helper_internal.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ _ARCHIVE = [".a", ".lib"]
101101
_PIC_ARCHIVE = [".pic.a"]
102102
_ALWAYSLINK_LIBRARY = [".lo"]
103103
_ALWAYSLINK_PIC_LIBRARY = [".pic.lo"]
104-
_SHARED_LIBRARY = [".so", ".dylib", ".dll", ".wasm"]
104+
_SHARED_LIBRARY = [".so", ".dylib", ".dll", ".pyd", ".wasm"]
105105
_INTERFACE_SHARED_LIBRARY = [".ifso", ".tbd", ".lib", ".dll.a"]
106106
_OBJECT_FILE = [".o", ".obj"]
107107
_PIC_OBJECT_FILE = [".pic.o"]
@@ -175,7 +175,7 @@ _ArtifactCategoryInfo, _unused_new_aci = provider(
175175
_artifact_categories = [
176176
_ArtifactCategoryInfo("STATIC_LIBRARY", "lib", ".a", ".lib"),
177177
_ArtifactCategoryInfo("ALWAYSLINK_STATIC_LIBRARY", "lib", ".lo", ".lo.lib"),
178-
_ArtifactCategoryInfo("DYNAMIC_LIBRARY", "lib", ".so", ".dylib", ".dll", ".wasm"),
178+
_ArtifactCategoryInfo("DYNAMIC_LIBRARY", "lib", ".so", ".dylib", ".dll", ".pyd", ".wasm"),
179179
_ArtifactCategoryInfo("EXECUTABLE", "", "", ".exe", ".wasm"),
180180
_ArtifactCategoryInfo("INTERFACE_LIBRARY", "lib", ".ifso", ".tbd", ".if.lib", ".lib"),
181181
_ArtifactCategoryInfo("PIC_FILE", "", ".pic"),

src/main/starlark/builtins_bzl/common/cc/cc_import.bzl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def _perform_error_checks(
4242

4343
if (shared_library_artifact != None and
4444
not cc_helper.is_valid_shared_library_artifact(shared_library_artifact)):
45-
fail("'shared_library' does not produce any cc_import shared_library files (expected .so, .dylib or .dll)")
45+
fail("'shared_library' does not produce any cc_import shared_library files (expected .so, .dylib, .dll or .pyd)")
4646

4747
def _create_archive_action(
4848
ctx,
@@ -339,8 +339,9 @@ A single precompiled shared library. Bazel ensures it is available to the
339339
binary that depends on it during runtime.
340340
<p> Permitted file types:
341341
<code>.so</code>,
342+
<code>.dylib</code>,
342343
<code>.dll</code>
343-
or <code>.dylib</code>
344+
or <code>.pyd</code>
344345
</p>"""),
345346
"interface_library": attr.label(
346347
allow_single_file = [".ifso", ".tbd", ".lib", ".so", ".dylib"],

src/main/starlark/builtins_bzl/common/cc/link/create_libraries_to_link_values.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ def _add_dynamic_library_to_link(
286286
# -l:libfoo.so.1 -> libfoo.so.1
287287
has_compatible_name = (
288288
name.startswith("lib") or
289-
(not name.endswith(".so") and not name.endswith(".dylib") and not name.endswith(".dll"))
289+
(not name.endswith(".so") and not name.endswith(".dylib") and
290+
not name.endswith(".dll") and not name.endswith(".pyd"))
290291
)
291292
if shared_library and has_compatible_name:
292293
lib_name = name.removeprefix("lib").removesuffix(".so").removesuffix(".dylib") \

0 commit comments

Comments
 (0)