Skip to content

Commit

Permalink
Re-add support for building Wasm libraries as executables. (#626)
Browse files Browse the repository at this point in the history
* 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 <piotrsikora@google.com>

* review: sort.

Signed-off-by: Piotr Sikora <piotrsikora@google.com>

Co-authored-by: Marcel Hlopko <hlopko@google.com>
  • Loading branch information
PiotrSikora and hlopko committed Mar 15, 2021
1 parent 40a8c9e commit 76c4420
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions rust/private/rust.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = depset(ctx.files.srcs),
deps = depset(ctx.attr.deps),
proc_macro_deps = depset(ctx.attr.proc_macro_deps),
Expand Down Expand Up @@ -793,6 +793,15 @@ rust_proc_macro = rule(
)

_rust_binary_attrs = {
"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",
),
"linker_script": attr.label(
doc = _tidy("""
Link script to forward into linker via rustc options.
Expand Down

0 comments on commit 76c4420

Please sign in to comment.