Skip to content

FR: Add rust_wasm_library #771

Description

@UebelAndre

There appears to be a desire for something like this which stems from #312

An insightful bit of context can be found in #240 (comment) but essentially, it seems to be rust_binary is being used in some (now) wasm edge cases but instead, we should probably have a more first class rule for supporting these cases?

I came across this while trying to understand #604 which at first glance just seems to be a quick solution to unblock a larger set of functionality but could ultimately stand to be re-reviewed.

Activity

  1. PiotrSikora commented on Jun 25, 2021

    @PiotrSikora
    Contributor
  2. UebelAndre commented on Aug 26, 2021

    @UebelAndre
    CollaboratorAuthor

    @PiotrSikora Could you reiterate why the rust_library target needs to return an executable? It seems like you should be able to grab the file from CrateInfo::output. Could that be used in place of out_binary?

  3. PiotrSikora commented on Aug 31, 2021

    @PiotrSikora
    Contributor

    @PiotrSikora Could you reiterate why the rust_library target needs to return an executable? It seems like you should be able to grab the file from CrateInfo::output. Could that be used in place of out_binary?

    Bazel won't even build library with .wasm extension, see this #626 (comment).

  4. UebelAndre commented on Aug 31, 2021

    @UebelAndre
    CollaboratorAuthor

    Bazel won't even build library with .wasm extension, see this #626 (comment).

    Sounds like you're referring to this?

    Traceback (most recent call last):
            File ".../rules_rust/rust/private/rust.bzl", line 179, column 32, in _rust_shared_library_impl
                    return _rust_library_common(ctx, "cdylib")
            File ".../rules_rust/rust/private/rust.bzl", line 221, column 32, in _rust_library_common
                    return rustc_compile_action(
            File ".../rules_rust/rust/private/rustc.bzl", line 614, column 29, in rustc_compile_action
                    return establish_cc_info(ctx, crate_info, toolchain, cc_toolchain, feature_configuration) + [
            File ".../rules_rust/rust/private/rustc.bzl", line 671, column 59, in establish_cc_info
                    library_to_link = cc_common.create_library_to_link(
    Error in create_library_to_link: 'libhello_world-665202032.wasm' does not have any of the allowed extensions .so, .dylib or .dll
    

    If so I feel like that's part of the work that would need to be done to create some rust_wasm_* rules. But is this the basis for why wasm targets should be *_binary targets? That's the bit that's not necessarily clear to me. To me *_binary means you'd expect to pass the file to some thing else as an executable but is that true of all .wasm files?

  5. roman-kashitsyn commented on Mar 19, 2022

    @roman-kashitsyn
    Contributor

    I'd love to see this implemented as well.

    My use-case: I want to build a Wasm module and pass it as input into a test that instantiates the Wasm module.

  6. UebelAndre commented on Feb 17, 2026

    @UebelAndre
    CollaboratorAuthor

    With no clear design I'm gonna close this out. In case folks still need wasm binaries, there's some prior-art for this in rules_rust_wasm_bindgen

    "wasm_file": attr.label(
    doc = "The `.wasm` crate to generate bindings for.",
    allow_single_file = True,
    providers = [
    [rust_common.test_crate_info],
    [rust_common.crate_info],
    ],
    aspects = [
    rust_analyzer_aspect,
    rustfmt_aspect,
    rust_clippy_aspect,
    ],
    cfg = wasm_bindgen_transition,
    mandatory = True,
    ),
    "_allowlist_function_transition": attr.label(
    default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
    ),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions