Generates javascript and typescript bindings for a webassembly module.
To use the Rust WebAssembly bindgen rules, add the following to your WORKSPACE
file to add the external repositories for the Rust bindgen toolchain (in addition to the Rust rules setup):
load("@rules_rust//wasm_bindgen:repositories.bzl", "rust_wasm_bindgen_repositories") rust_wasm_bindgen_repositories()
An example of this rule in use can be seen at @rules_rust//examples/wasm/...
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
bindgen_flags | Flags to pass directly to the bindgen executable. See https://github.com/rustwasm/wasm-bindgen/ for details. | List of strings | optional | [] |
wasm_file | The .wasm file to generate bindings for. | Label | optional | None |
The tools required for the rust_wasm_bindgen
rule.
You can also use your own version of wasm-bindgen using the toolchain rules below:
load("@rules_rust//bindgen:bindgen.bzl", "rust_bindgen_toolchain") rust_bindgen_toolchain( bindgen = "//my/raze:cargo_bin_wasm_bindgen", ) toolchain( name = "wasm-bindgen-toolchain", toolchain = "wasm-bindgen-toolchain-impl", toolchain_type = "@rules_rust//wasm_bindgen:wasm_bindgen_toolchain", )
Now that you have your own toolchain, you need to register it by inserting the following statement in your WORKSPACE
file:
register_toolchains("//my/toolchains:wasm-bindgen-toolchain")
For additional information, see the Bazel toolchains documentation.
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
bindgen | The label of a wasm-bindgen executable. | Label | optional | None |
Declare dependencies needed for wasm-bindgen.
This macro will load crate dependencies of wasm-bindgen
that are generated using [cargo raze][raze] inside the rules_rust repository. This makes the default toolchain @rules_rust//wasm_bindgen:default_wasm_bindgen_toolchain
available. For more information on wasm_bindgen
toolchains, see rust_wasm_bindgen_toolchain.