Skip to content

Commit 6fc9bed

Browse files
ShreeM01zaucy
andauthored
Fix wasm dynamic library extension crash (bazelbuild#17765)
This is an amendment to bazelbuild#17374 We have a C++ toolchain config that's being developed to support standalone wasm. We discovered that bazelbuild#17374 wasn't complete. Our example was poorly written and didn't actually create a wasm dynamic library. These changes allow us to successfully create a standalone wasm dynamic library. Sorry for the botched attempt previously. I would like to add tests, but I'm unsure how to approach such a tests considering the automatic toolchain doesn't support wasm AFAICT. Closes bazelbuild#17698. PiperOrigin-RevId: 516204125 Change-Id: Iced5cc80a3151ffde7116b6264c89eaf40466ff5 Co-authored-by: Ezekiel Warren <[email protected]>
1 parent b874e5f commit 6fc9bed

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ public ImmutableList<String> getExtensions() {
206206

207207
// TODO(bazel-team): File types should not be read from this hard-coded list but should come from
208208
// the toolchain instead. See https://github.com/bazelbuild/bazel/issues/17117
209-
public static final FileType SHARED_LIBRARY = FileType.of(".so", ".dylib", ".dll", ".pyd");
209+
public static final FileType SHARED_LIBRARY =
210+
FileType.of(".so", ".dylib", ".dll", ".pyd", ".wasm");
210211
// Unix shared libraries can be passed to linker, but not .dll on Windows
211212
public static final FileType UNIX_SHARED_LIBRARY = FileType.of(".so", ".dylib");
212213
public static final FileType INTERFACE_SHARED_LIBRARY =

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ ARCHIVE = [".a", ".lib"]
350350
PIC_ARCHIVE = [".pic.a"]
351351
ALWAYSLINK_LIBRARY = [".lo"]
352352
ALWAYSLINK_PIC_LIBRARY = [".pic.lo"]
353-
SHARED_LIBRARY = [".so", ".dylib", ".dll"]
353+
SHARED_LIBRARY = [".so", ".dylib", ".dll", ".wasm"]
354+
INTERFACE_SHARED_LIBRARY = [".ifso", ".tbd", ".lib", ".dll.a"]
354355
OBJECT_FILE = [".o", ".obj"]
355356
PIC_OBJECT_FILE = [".pic.o"]
356357

@@ -539,12 +540,13 @@ def _is_versioned_shared_library_extension_valid(shared_library_name):
539540
def _is_valid_shared_library_name(shared_library_name):
540541
if (shared_library_name.endswith(".so") or
541542
shared_library_name.endswith(".dll") or
542-
shared_library_name.endswith(".dylib")):
543+
shared_library_name.endswith(".dylib") or
544+
shared_library_name.endswith(".wasm")):
543545
return True
544546

545547
return _is_versioned_shared_library_extension_valid(shared_library_name)
546548

547-
_SHARED_LIBRARY_EXTENSIONS = ["so", "dll", "dylib"]
549+
_SHARED_LIBRARY_EXTENSIONS = ["so", "dll", "dylib", "wasm"]
548550

549551
def _is_valid_shared_library_artifact(shared_library):
550552
if (shared_library.extension in _SHARED_LIBRARY_EXTENSIONS):

src/test/java/com/google/devtools/build/lib/rules/cpp/StarlarkCcCommonTest.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -5296,10 +5296,13 @@ public void testWrongExtensionThrowsError() throws Exception {
52965296
"'a.pic.o' does not have any of the allowed extensions .a, .lib, .pic.a or .rlib");
52975297
assertThat(e)
52985298
.hasMessageThat()
5299-
.contains("'a.ifso' does not have any of the allowed extensions .so, .dylib, .dll or .pyd");
5299+
.contains(
5300+
"'a.ifso' does not have any of the allowed extensions .so, .dylib, .dll, .pyd or"
5301+
+ " .wasm");
53005302
assertThat(e)
53015303
.hasMessageThat()
5302-
.contains("'a.lib' does not have any of the allowed extensions .so, .dylib, .dll or .pyd");
5304+
.contains(
5305+
"'a.lib' does not have any of the allowed extensions .so, .dylib, .dll, .pyd or .wasm");
53035306
assertThat(e)
53045307
.hasMessageThat()
53055308
.contains(

0 commit comments

Comments
 (0)