From ddd97e5ac6829e55066fd223329fc275ab5c3d12 Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Sat, 6 Mar 2021 05:55:21 +0000 Subject: [PATCH 1/2] 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 #312, and most recently broken in #592. Signed-off-by: Piotr Sikora --- rust/private/rust.bzl | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/rust/private/rust.bzl b/rust/private/rust.bzl index 1d84d45106..16c2ad3064 100644 --- a/rust/private/rust.bzl +++ b/rust/private/rust.bzl @@ -255,11 +255,11 @@ def _rust_binary_impl(ctx): return rustc_compile_action( ctx = ctx, toolchain = toolchain, - crate_type = "bin", + crate_type = ctx.attr.crate_type, crate_info = rust_common.crate_info( name = crate_name, - type = "bin", - root = crate_root_src(ctx.attr, ctx.files.srcs, crate_type = "bin"), + type = ctx.attr.crate_type, + root = crate_root_src(ctx.attr, ctx.files.srcs, ctx.attr.crate_type), srcs = ctx.files.srcs, deps = ctx.attr.deps, proc_macro_deps = ctx.attr.proc_macro_deps, @@ -796,6 +796,15 @@ _rust_binary_attrs = { cfg = "exec", allow_single_file = True, ), + "crate_type": attr.string( + doc = _tidy(""" + Crate type that will be passed to `rustc` to be used for building this crate. + + This option is a temporary workaround and should be used only when building + for WebAssembly targets (//rust/platform:wasi and //rust/platform:wasm). + """), + default = "bin", + ), "out_binary": attr.bool(), } From 89e21729efd22b5c9c9bf539b2e44473c0c1ff75 Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Sat, 6 Mar 2021 06:25:33 +0000 Subject: [PATCH 2/2] review: sort. Signed-off-by: Piotr Sikora --- rust/private/rust.bzl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/rust/private/rust.bzl b/rust/private/rust.bzl index 16c2ad3064..da9bb7a024 100644 --- a/rust/private/rust.bzl +++ b/rust/private/rust.bzl @@ -789,13 +789,6 @@ rust_proc_macro = rule( ) _rust_binary_attrs = { - "linker_script": attr.label( - doc = _tidy(""" - Link script to forward into linker via rustc options. - """), - cfg = "exec", - allow_single_file = True, - ), "crate_type": attr.string( doc = _tidy(""" Crate type that will be passed to `rustc` to be used for building this crate. @@ -805,6 +798,13 @@ _rust_binary_attrs = { """), default = "bin", ), + "linker_script": attr.label( + doc = _tidy(""" + Link script to forward into linker via rustc options. + """), + cfg = "exec", + allow_single_file = True, + ), "out_binary": attr.bool(), }