From 073f54b9a7c46afd2c28b4a99a235bdd6b63bb5f Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 4 Jan 2023 01:03:45 -0800 Subject: [PATCH] Allow pyd in extensions of dynamic libraries Long term fix should be to read the extensions from the toolchain. RELNOTES:none PiperOrigin-RevId: 499418087 Change-Id: I710285966cec5eff937c2fb7be728e5e93503cc7 --- .../google/devtools/build/lib/rules/cpp/CppFileTypes.java | 4 +++- .../test_cc_shared_library/BUILD.builtin_test | 7 +++++++ .../devtools/build/lib/rules/cpp/StarlarkCcCommonTest.java | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java index 7becb65247b599..c4b502e8c8d089 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java @@ -204,7 +204,9 @@ public ImmutableList getExtensions() { // Minimized bitcode file emitted by the ThinLTO compile step and used just for LTO indexing. public static final FileType LTO_INDEXING_OBJECT_FILE = FileType.of(".indexing.o"); - public static final FileType SHARED_LIBRARY = FileType.of(".so", ".dylib", ".dll"); + // TODO(bazel-team): File types should not be read from this hard-coded list but should come from + // the toolchain instead. See https://github.com/bazelbuild/bazel/issues/17117 + public static final FileType SHARED_LIBRARY = FileType.of(".so", ".dylib", ".dll", ".pyd"); // Unix shared libraries can be passed to linker, but not .dll on Windows public static final FileType UNIX_SHARED_LIBRARY = FileType.of(".so", ".dylib"); public static final FileType INTERFACE_SHARED_LIBRARY = diff --git a/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/BUILD.builtin_test b/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/BUILD.builtin_test index 2449c9148cf6e2..a55cf8fc9f9839 100644 --- a/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/BUILD.builtin_test +++ b/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/BUILD.builtin_test @@ -49,6 +49,13 @@ cc_binary( deps = ["foo"], ) +cc_shared_library( + name = "python_module", + features = ["windows_export_all_symbols"], + roots = [":a_suffix"], + shared_lib_name = "python_module.pyd", +) + cc_shared_library( name = "a_so", features = ["windows_export_all_symbols"], diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/StarlarkCcCommonTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/StarlarkCcCommonTest.java index de037162408846..5b72c55c395f80 100755 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/StarlarkCcCommonTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/StarlarkCcCommonTest.java @@ -5296,10 +5296,10 @@ public void testWrongExtensionThrowsError() throws Exception { "'a.pic.o' does not have any of the allowed extensions .a, .lib, .pic.a or .rlib"); assertThat(e) .hasMessageThat() - .contains("'a.ifso' does not have any of the allowed extensions .so, .dylib or .dll"); + .contains("'a.ifso' does not have any of the allowed extensions .so, .dylib, .dll or .pyd"); assertThat(e) .hasMessageThat() - .contains("'a.lib' does not have any of the allowed extensions .so, .dylib or .dll"); + .contains("'a.lib' does not have any of the allowed extensions .so, .dylib, .dll or .pyd"); assertThat(e) .hasMessageThat() .contains(