xref: /aosp_15_r20/external/bazelbuild-rules_rust/docs/rust_wasm_bindgen.vm (revision d4726bddaa87cc4778e7472feed243fa4b6c267f)
1#[[
2## Overview
3
4Bazel rules for generating wasm modules for Javascript using [wasm-bindgen][wb].
5
6## Setup
7
8To begin using the `wasm-bindgen` rules, users can load the necessary dependencies
9in their workspace by adding the following to their `WORKSPACE.bazel` file.
10
11```starlark
12load("@rules_rust//wasm_bindgen:repositories.bzl", "rust_wasm_bindgen_dependencies", "rust_wasm_bindgen_register_toolchains")
13
14rust_wasm_bindgen_dependencies()
15
16rust_wasm_bindgen_register_toolchains()
17```
18
19This should enable users to start using the [rust_wasm_bindgen](#rust_wasm_bindgen)
20rule. However, it's common to want to control the version of `wasm-bindgen` in the
21workspace instead of relying on the one provided by `rules_rust`. In this case, users
22should avoid calling `rust_wasm_bindgen_register_toolchains` and instead use the
23[rust_wasm_bindgen_toolchain](#rust_wasm_bindgen_toolchain) rule to define their own
24toolchains to register in the workspace.
25
26### Interfacing with Javascript rules
27
28While it's recommended for users to mantain their own , in the
29`@rules_rust//wasm_bindgen` package there exists interface sub-packages for various
30Javascript Bazel rules. E.g. `build_bazel_rules_nodejs` or `aspect_rules_js`. The
31rules defined there are a more convenient way to use `rust_wasm_bindgen` with the
32associated javascript rules due to the inclusion of additional providers. Each
33directory contains a `defs.bzl` file that defines the different variants of
34`rust_wasm_bindgen`. (e.g. `nodejs_rust_wasm_bindgen` for the `rules_nodejs` submodule).
35
36
37[wb]: https://github.com/rustwasm/wasm-bindgen
38]]#
39