An application that renders text:
- written in Rust
- plugin-based design
- plugins are wasm modules
Based on wasmlink demo of the wit-bindgen project.
A Rust plugin-based app that renders text, where the plugins are wasm modules.
- The renderer API is defined by
renderer.wit
. - The app will search for plugins in the
plugins
directory.
Let us build the plugin that renders markdown into html.
We use cargo-wasi to compile the plugin. Install it using cargo
:
$ cargo install cargo-wasi
The renderer.wit
defines the structure of a plugin: a render
function that takes a string (the Markdown) as an argument and returns a string (the rendered HTML).
To build the markdown
plugin:
- Go to the
markdown
directory. - Build using
cargo wasi build
Take the resulting markdown.wasm
file (in markdown\target\wasm32-wasi\debug\markdown.wasm
) and put it into app\plugins
, so that the app can find it.
You may run something like cp markdown\target\wasm32-wasi\debug\markdown.wasm app\plugins
.
Let us run our app. (For now it will run only the markdown plugin)
- Go to the
app
directory. - Use
cargo run
.
- Check that
markdown.wasm
is under theplugins
folder. - Note that the
renderer.wit
is also needed for the app to interpret this wasm file.