Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
PiotrSikora opened this issue Aug 3, 2020 · 2 comments · Fixed by #436
Closed

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

PiotrSikora opened this issue Aug 3, 2020 · 2 comments · Fixed by #436

Comments

@PiotrSikora
Copy link
Contributor

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)
@GregBowyer
Copy link
Contributor

My apologies.

I am going to assume right now that it doesnt make the most sense for you to link a wasm binary to further cc_library / cc_binary targets since the wasm support is rather bolted on at a right angle. Is this a use case for you?

@PiotrSikora
Copy link
Contributor Author

PiotrSikora commented Aug 3, 2020

Not linked, no.

But ideally, those .wasm modules could be used as data inputs in cc_{binary,library,test} targets.

Using them in rust_{binary,library,test} is going to be broken until we get dedicated rust_wasm_{binary,library} (see previous discussion in #240 (comment) and #312), since right now we're enabling Wasm target using --platforms=@io_bazel_rules_rust//rust/platform:wasm , which would also convert Rust test runners into Wasm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants