Skip to content

coffee-cup/wasm-plugins

Repository files navigation

WebAssembly Plugin Experimentation

This repo is an experimentation of using WASM modules with a shared component interface as plugins.

Features

  • Shared component interface defined in the WIT format. (wit/handler.wit)
    • Plugins load the component interface via wit-bindgen which enforces the implementation of the guest side of the component
    • Hosts load the interface via wasmtime which enforces the implementation of the host side of the component
    • The plugin and server and currently both implemented in Rust, but the interface is language agnostic. As long as the WASM component module confirms to the WIT format, it can be used by as a handler.
  • Route handlers are loaded as WASM modules. Currently the only one available is hello-handler. These handlers are compiled separately to the wasm32-wasi or wasm32-unknown-unknown targets
  • Actix server located in server/ that dynamically loads WASM modules and executes them as route handlers (currently only 1 on / but I will add more when it is not super late)

How to Use

  • Install wasm-tools
  • Compile the handlers and convert into WASM components: ./build-handlers.sh. These will show up in handlers/*.wasm
  • Run the server: cargo run --package server
  • Go to localhost:9090

The response of the request is the result of calling the WASM handler.

The handlers are also dynamically loaded on each request, which means you can change hello-handler/src/lib.rs, run ./build-handlers.sh and refresh the page to see the changes (no need to re-run the server).

TODO

  • Add more handlers and expand the API interface
  • Figure out how to run the modules with WASI available
  • Re-use the execution engine so we are not re-creating it for each request
  • Dynamically register handlers while the server is already running (possible with a request to POST /handler)
  • Implement a handler in a non-Rust language
  • See what a host and plugin in JS looks like
    • How cool would it be to have a web server and each of the route handlers be implemented in a different language!

Resources

Note: Documentation for a lot of these libraries/tools is very sparse and often outdated. I've tried to compile a list of resources here, but use at your own risk.

I've also been saving a ton of links related to wasm in my bookmarks.

About

Experiment using WASM modules as plugins

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published