Skip to content

rust_binary(out_binary=True) is broken for Wasm targets. #386

Closed
@PiotrSikora

Description

@PiotrSikora

The out_binary = True feature to build Rust binaries for Wasm targets introduced in #312 is broken since #361.

$ cat BUILD
load("@io_bazel_rules_rust//rust:rust.bzl", "rust_binary")

rust_binary(
    name = "test_rust",
    srcs = ["test_rust.rs"],
    edition = "2018",
    visibility = ["//visibility:public"],
    crate_type = "cdylib",
    out_binary = True,
)
$ cat test_rust.rs
#[no_mangle]
extern "C" fn abort() {
    panic!("abort")
}

This works fine when using last commit before #361 (i.e. fda9a1ce6482973adfda022cadbfa6b300e269c3):

$ bazel build --platforms=@io_bazel_rules_rust//rust/platform:wasm //:test_rust
Starting local Bazel server and connecting to it...
INFO: Invocation ID: fdecbf32-5468-4c23-9b20-7cf6c993a24c
INFO: SHA256 (https://static.rust-lang.org/dist/rust-std-1.44.0-wasm32-unknown-unknown.tar.gz) = 8e12796a0c2fb083953042218f832bdeb78da1bfaf67b9dfe3d719920084d755
INFO: Analyzed target //:test_rust (24 packages loaded, 161 targets configured).
INFO: Found 1 target...
Target //:test_rust up-to-date:
  bazel-bin/test_rust.wasm
INFO: Elapsed time: 19.079s, Critical Path: 2.90s
INFO: 5 processes: 1 remote cache hit, 4 processwrapper-sandbox.
INFO: Build completed successfully, 11 total actions

but is broken starting from #361 until master (i.e. fdf9655ba95616e0314b4e0ebab40bb0c5fe005c):

$ bazel build --platforms=@io_bazel_rules_rust//rust/platform:wasm //:test_rust
Starting local Bazel server and connecting to it...
INFO: Invocation ID: 3d32152c-bc89-4e2c-98ef-40caa00823a7
INFO: SHA256 (https://static.rust-lang.org/dist/rust-std-1.44.0-wasm32-unknown-unknown.tar.gz) = 8e12796a0c2fb083953042218f832bdeb78da1bfaf67b9dfe3d719920084d755
ERROR: /tmp/out_binary/BUILD:15:12: in rust_binary rule //:test_rust: 
Traceback (most recent call last):
        File "/tmp/out_binary/BUILD", line 15
                rust_binary(name = 'test_rust')
        File ".../external/io_bazel_rules_rust/rust/private/rust.bzl", line 142, in _rust_binary_impl
                rustc_compile_action(ctx = ctx, <2 more arguments>)
        File ".../external/io_bazel_rules_rust/rust/private/rustc.bzl", line 510, in rustc_compile_action
                establish_cc_info(ctx, <4 more arguments>)
        File ".../external/io_bazel_rules_rust/rust/private/rustc.bzl", line 535, in establish_cc_info
                cc_common.create_library_to_link(<4 more arguments>)
'test_rust.wasm' does not have any of the allowed extensions .so, .dylib or .dll
ERROR: Analysis of target '//:test_rust' failed; build aborted: Analysis of target '//:test_rust' failed
INFO: Elapsed time: 17.614s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (25 packages loaded, 159 targets configured)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions