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