Skip to content

Commit fa96218

Browse files
authored
Fix wasm staticlib extensions (bazelbuild#3968)
`rust_static_library` targets fail for wasm-style platform mappings whose `staticlib_ext` is empty. This became visible after bazelbuild#3864 changed the allocator shim target to use `rust_static_library`. When building that target for the wasm platform, rules_rust computes: ``` crate_type = "staticlib" staticlib_ext = "" ``` `determine_lib_name` treats the empty extension as invalid and fails with: ``` Unknown crate_type: staticlib ``` Static library outputs for these wasm/WASI-style targets should use archive output names, e.g. libfoo.a. Binary and dylib outputs can continue using .wasm. This updates the wasm-style staticlib mappings to .a for: - threads - unknown - wasi - wasip1 - wasip2 This is easily reproducible from the rules_rust repository, before this change: ``` bazel build --platforms=//rust/platform:wasm32 //ffi/rs/allocator_library:allocator_library ``` fails during analysis with: ``` Unknown crate_type: staticlib ``` closes bazelbuild#3894
1 parent 278d31e commit fa96218

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

rust/platform/triple_mappings.bzl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,12 @@ _SYSTEM_TO_STATICLIB_EXT = {
210210
"nixos": ".a",
211211
"none": ".a",
212212
"nto": ".a",
213-
"threads": "",
213+
"threads": ".a",
214214
"uefi": ".lib",
215-
"unknown": "",
216-
"wasi": "",
217-
"wasip1": "",
218-
"wasip2": "",
215+
"unknown": ".a",
216+
"wasi": ".a",
217+
"wasip1": ".a",
218+
"wasip2": ".a",
219219
"windows": ".lib",
220220
}
221221

test/unit/platform_triple/platform_triple_test.bzl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest")
44
load("//rust/platform:triple.bzl", "triple")
5-
load("//rust/platform:triple_mappings.bzl", "SUPPORTED_PLATFORM_TRIPLES")
5+
load("//rust/platform:triple_mappings.bzl", "SUPPORTED_PLATFORM_TRIPLES", "system_to_staticlib_ext")
66

77
def _construct_platform_triple_test_impl(ctx):
88
env = unittest.begin(ctx)
@@ -152,10 +152,24 @@ def _construct_known_triples_test_impl(ctx):
152152

153153
return unittest.end(env)
154154

155+
def _wasm_staticlib_ext_test_impl(ctx):
156+
env = unittest.begin(ctx)
157+
158+
for system in ["threads", "unknown", "wasi", "wasip1", "wasip2"]:
159+
asserts.equals(
160+
env,
161+
".a",
162+
system_to_staticlib_ext(system),
163+
"{} should use a static archive extension".format(system),
164+
)
165+
166+
return unittest.end(env)
167+
155168
construct_platform_triple_test = unittest.make(_construct_platform_triple_test_impl)
156169
construct_minimal_platform_triple_test = unittest.make(_construct_minimal_platform_triple_test_impl)
157170
supported_platform_triples_test = unittest.make(_supported_platform_triples_test_impl)
158171
construct_known_triples_test = unittest.make(_construct_known_triples_test_impl)
172+
wasm_staticlib_ext_test = unittest.make(_wasm_staticlib_ext_test_impl)
159173

160174
def platform_triple_test_suite(name, **kwargs):
161175
"""Define a test suite for testing the `triple` constructor
@@ -176,6 +190,9 @@ def platform_triple_test_suite(name, **kwargs):
176190
construct_known_triples_test(
177191
name = "construct_known_triples_test",
178192
)
193+
wasm_staticlib_ext_test(
194+
name = "wasm_staticlib_ext_test",
195+
)
179196

180197
native.test_suite(
181198
name = name,
@@ -184,6 +201,7 @@ def platform_triple_test_suite(name, **kwargs):
184201
":construct_minimal_platform_triple_test",
185202
":supported_platform_triples_test",
186203
":construct_known_triples_test",
204+
":wasm_staticlib_ext_test",
187205
],
188206
**kwargs
189207
)

0 commit comments

Comments
 (0)