Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cc/common/cc_helper.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def _libraries_from_linking_context(linking_context):
def _is_valid_shared_library_name(shared_library_name):
if (shared_library_name.endswith(".so") or
shared_library_name.endswith(".dll") or
shared_library_name.endswith(".pyd") or
shared_library_name.endswith(".dylib") or
shared_library_name.endswith(".wasm")):
return True
Expand Down Expand Up @@ -512,7 +513,7 @@ def _get_toolchain_global_make_variables(cc_toolchain):
result["CROSSTOOLTOP"] = cc_toolchain._crosstool_top_path
return result

_SHARED_LIBRARY_EXTENSIONS = ["so", "dll", "dylib", "wasm"]
_SHARED_LIBRARY_EXTENSIONS = ["so", "dll", "pyd", "dylib", "wasm"]

def _is_valid_shared_library_artifact(shared_library):
if (shared_library.extension in _SHARED_LIBRARY_EXTENSIONS):
Expand Down
4 changes: 2 additions & 2 deletions cc/common/cc_helper_internal.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ _ARCHIVE = [".a", ".lib"]
_PIC_ARCHIVE = [".pic.a"]
_ALWAYSLINK_LIBRARY = [".lo"]
_ALWAYSLINK_PIC_LIBRARY = [".pic.lo"]
_SHARED_LIBRARY = [".so", ".dylib", ".dll", ".wasm"]
_SHARED_LIBRARY = [".so", ".dylib", ".dll", ".pyd", ".wasm"]
_INTERFACE_SHARED_LIBRARY = [".ifso", ".tbd", ".lib", ".dll.a"]
_OBJECT_FILE = [".o", ".obj"]
_PIC_OBJECT_FILE = [".pic.o"]
Expand Down Expand Up @@ -170,7 +170,7 @@ _ArtifactCategoryInfo, _unused_new_aci = provider(
_artifact_categories = [
_ArtifactCategoryInfo("STATIC_LIBRARY", "lib", ".a", ".lib"),
_ArtifactCategoryInfo("ALWAYSLINK_STATIC_LIBRARY", "lib", ".lo", ".lo.lib"),
_ArtifactCategoryInfo("DYNAMIC_LIBRARY", "lib", ".so", ".dylib", ".dll", ".wasm"),
_ArtifactCategoryInfo("DYNAMIC_LIBRARY", "lib", ".so", ".dylib", ".dll", ".pyd", ".wasm"),
_ArtifactCategoryInfo("EXECUTABLE", "", "", ".exe", ".wasm"),
_ArtifactCategoryInfo("INTERFACE_LIBRARY", "lib", ".ifso", ".tbd", ".if.lib", ".lib"),
_ArtifactCategoryInfo("PIC_FILE", "", ".pic"),
Expand Down
5 changes: 3 additions & 2 deletions cc/private/link/create_libraries_to_link_values.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,12 @@ def _add_dynamic_library_to_link(
# -l:libfoo.so.1 -> libfoo.so.1
has_compatible_name = (
name.startswith("lib") or
(not name.endswith(".so") and not name.endswith(".dylib") and not name.endswith(".dll"))
(not name.endswith(".so") and not name.endswith(".dylib") and
not name.endswith(".dll") and not name.endswith(".pyd"))
)
if shared_library and has_compatible_name:
lib_name = name.removeprefix("lib").removesuffix(".so").removesuffix(".dylib") \
.removesuffix(".dll")
.removesuffix(".dll").removesuffix(".pyd")
libraries_to_link_values.append(
_NamedLibraryInfo(
type = _TYPE.DYNAMIC_LIBRARY,
Expand Down
4 changes: 2 additions & 2 deletions cc/private/rules_impl/cc_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def _create_transitive_linking_actions(
# entries during linking process.
for libs in precompiled_files[:]:
for artifact in libs:
if _matches([".so", ".dylib", ".dll", ".ifso", ".tbd", ".lib", ".dll.a"], artifact.basename) or cc_helper.is_valid_shared_library_artifact(artifact):
if _matches([".so", ".dylib", ".dll", ".pyd", ".ifso", ".tbd", ".lib", ".dll.a"], artifact.basename) or cc_helper.is_valid_shared_library_artifact(artifact):
library_to_link = cc_common.create_library_to_link(
actions = ctx.actions,
feature_configuration = feature_configuration,
Expand Down Expand Up @@ -477,7 +477,7 @@ def cc_binary_impl(ctx, additional_linkopts, force_linkstatic = False):
# the target name.
# This is no longer necessary, the toolchain can figure out the correct file extensions.
target_name = ctx.label.name
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))
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))
binary = None
is_dbg_build = (cc_toolchain._cpp_configuration.compilation_mode() == "dbg")
if has_legacy_link_shared_name:
Expand Down
5 changes: 5 additions & 0 deletions cc/private/toolchain/windows_cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ def _impl(ctx):
prefix = "",
extension = ".dll",
),
artifact_name_pattern(
category_name = "dynamic_library",
prefix = "",
extension = ".pyd",
),
artifact_name_pattern(
category_name = "interface_library",
prefix = "",
Expand Down
11 changes: 11 additions & 0 deletions tests/simple_binary/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ cc_binary(
linkshared = 1,
)

# On windows, python use .pyd extension for native modules.
cc_binary(
name = "foo.pyd",
srcs = ["foo.cc"],
linkshared = 1,
target_compatible_with = select({
"@platforms//os:windows": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
)

# Regression test for building C code
# https://github.com/bazelbuild/rules_cc/pull/440#issuecomment-3075519628
cc_binary(
Expand Down