This repo aims to be a very simple, yet complete, example of building a wasm binary using a Rust project as source, and then running that wasm within another Rust project.
The example is a Cargo workspace comprised of 2 parts - a compiler
and a runner
. The compiler
is the crate that is responsible for compiling Rust code to a wasm binary using wasm-pack. The runner
takes that wasm binary, loads it into a Rust process, and executes functions defined in the binary. The runner
uses wasmer.
You need to have the following installed:
- Install Rust (duh)
- Install wasm-pack
- Add the wasm compilation target -
rustup target add wasm32-unknown-unknown
Then, follow these steps:
cd
insidecompiler
and runwasm-pack build
cd
back into the workspace root folder and runcargo run
If all goes well, you should see The answer is 42
printed to the console.
Feel free to open an Issue if you're having trouble running this template.