Rust WebAssembly Bindgen Rules

Overview

These rules are for using Wasm Bindgen to generate Rust bindings to.

See the wasm bindgen example for a more complete example of use.

Setup

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("@io_bazel_rules_rust//wasm_bindgen:repositories.bzl", "rust_wasm_bindgen_repositories")

rust_wasm_bindgen_repositories()

This makes the default toolchain defined in @io_bazel_rules_rust available.

It will load crate dependencies of bindgen that are generated using cargo raze inside the rules_rust repository. However, using those dependencies might conflict with other uses of cargo raze. If you need to change those dependencies, please see the dedicated section below.

For additional information, see the Bazel toolchains documentation.

Customizing toolchains

You can also use your own version of wasm-bindgen using the toolchain rules below:

load("@io_bazel_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 = "@io_bazel_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")