Setting Up Our WASM Build
We must setup a Rust workspace in our frontend that can house the Rust code that we want to compile to a WASM target to be served. In our ingress/frontend
directory, we can create a new Rust workspace with the following command:
cargo new rust-interface --lib
Now that we have a workspace, we must configure our | of this workspace with the following code:
# ingress/frontend/rust-interface/Cargo.toml
. . .
[lib]
crate-type = ["cdylib"]
[dependencies]
wasm-bindgen = "0.2.92"
Here, we can see that we are relying on the wasm-bindgen
crate to make the WASM to JavaScript bindings and simplify our Rust functions that act as entry points to the WASM program. In the last section of the chapter, we will build our own code to enable us to pass complex data types over the WASM boundary. This is going to involve directly accessing raw unsafe data pointers. However, for our frontend example, the wasm-bindgen
crate is going to do all the heavy lifting...