Skip to content

Commit ddd97e5

Browse files
committed
Re-add support for building Wasm libraries as executables.
The ability to build Wasm libraries as executables is needed to support WASI reactors (Wasm executables with multiple entrypoints). This is a temporary workaround, and we should be able to use crate-type "bin" when a proper support for WASI reactors (rust-lang/rust#79997) is stabilised is Rust. This feature was added in bazelbuild#312, and most recently broken in bazelbuild#592. Signed-off-by: Piotr Sikora <[email protected]>
1 parent 2de6496 commit ddd97e5

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

rust/private/rust.bzl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,11 @@ def _rust_binary_impl(ctx):
255255
return rustc_compile_action(
256256
ctx = ctx,
257257
toolchain = toolchain,
258-
crate_type = "bin",
258+
crate_type = ctx.attr.crate_type,
259259
crate_info = rust_common.crate_info(
260260
name = crate_name,
261-
type = "bin",
262-
root = crate_root_src(ctx.attr, ctx.files.srcs, crate_type = "bin"),
261+
type = ctx.attr.crate_type,
262+
root = crate_root_src(ctx.attr, ctx.files.srcs, ctx.attr.crate_type),
263263
srcs = ctx.files.srcs,
264264
deps = ctx.attr.deps,
265265
proc_macro_deps = ctx.attr.proc_macro_deps,
@@ -796,6 +796,15 @@ _rust_binary_attrs = {
796796
cfg = "exec",
797797
allow_single_file = True,
798798
),
799+
"crate_type": attr.string(
800+
doc = _tidy("""
801+
Crate type that will be passed to `rustc` to be used for building this crate.
802+
803+
This option is a temporary workaround and should be used only when building
804+
for WebAssembly targets (//rust/platform:wasi and //rust/platform:wasm).
805+
"""),
806+
default = "bin",
807+
),
799808
"out_binary": attr.bool(),
800809
}
801810

0 commit comments

Comments
 (0)