plugy empowers you to construct agnostic dynamic plugin systems using Rust and WebAssembly.

Overview

GitHub Actions GitHub Releases

plugy

plugy is a plugin system designed to enable the seamless integration of Rust-based plugins into your application. It provides a runtime environment for loading and executing plugins written in WebAssembly (Wasm), enabling dynamic extensibility and modularity in your Rust projects.

Features

  • Load and execute plugins compiled to WASM.
  • Flexible runtime management of plugins.
  • Calls to plugin functions are async.
  • Easy-to-use macros for generating plugin interfaces.

Getting Started

To use plugy in your Rust project, follow these steps:

  1. Write your plugin trait:
#[plugy::plugin]
trait Greeter {
    fn greet(&self) -> String;
}
  1. Write your first plugin implementation
#[derive(Debug, Deserialize)]
struct FooPlugin;

#[plugin_impl]
impl Greeter for FooPlugin {
    fn greet(&self) -> String {
        "Hello From Foo Plugin".to_owned()
    }
}

Compile it!

cargo build --target wasm32-unknown-unknown
  1. Import and run
#[plugin_import(file = "target/wasm32-unknown-unknown/debug/foo_plugin.wasm")]
struct FooPlugin;

#[tokio::main]
async fn main() {
    let runtime = Runtime::<Box<dyn Greeter>>::new().unwrap();
    let handle = runtime.load(FooPlugin).await.unwrap();
    let res = handle.greet().await;
    assert_eq!(res, "Hello From Foo Plugin")
}

And you are set!

Examples

Check out the examples directory for sample usage of plugy.

Milestones

Status Goal Labels
βœ… accept multiple arity (n-ary) in plugin functions complete
βœ… pass down context between host and guest complete

Functionality

Plugy comprises three fundamental crates, each serving a distinct role in crafting dynamic plugin systems with Rust and WebAssembly:

  • core: This crate houses essential components such as bitwise utilities and the guest module, forming the foundation of Plugy's functionality.

  • runtime: The runtime crate orchestrates the execution of your plugin system, allowing seamless integration of plugins into your applications.

  • macros: The macros crate offers a collection of macros that simplify the generation of bindings and interfaces, streamlining the process of working with dynamic plugins.

Contributing

Contributions to plugy are welcome! If you find a bug or want to propose a new feature, feel free to create an issue or submit a pull request.

Thanks to

License

This project is licensed under the GNU General Public License.

You might also like...
Let's pretend that life-before-main exists for Rust targeting WebAssembly

Let's pretend that life-before-main exists for Rust targeting WebAssembly. Installation Add a dependency on wasm-init. This crate intentionally provid

Code for my workshop
Code for my workshop "Production-ready WebAssembly with Rust" presented at RustLab 2023 in Florence

Workshop: Production-ready WebAssembly with Rust A workshop on Rust for WebAssembly by Alberto Schiabel (@jkomyno). πŸ€“ This workshop was first present

A 3D bin packing library in Rust/WebAssembly.

packme-wasm Demo https://packme.vercel.app This repository hosts an implementation of Dube, E., & Kanavathy L. (2006). Optimizing Three-Dimensional Bi

NPM package distributing biscuit in WebAssembly for web components

Biscuit playground This is an example application for Biscuit tokens, where you can manipulate tokens and their verification in your browser. build wi

`wasm-snip` replaces a WebAssembly function's body with an `unreachable`

wasm-snip wasm-snip replaces a Wasm function's body with an unreachable instruction. API Docs | Contributing | Chat Built with πŸ¦€ πŸ•Έ by The Rust and W

WebAssembly (Wasm) interpreter.

Continuous Integration Test Coverage Documentation Crates.io wasmi- WebAssembly (Wasm) Interpreter wasmi was conceived as a component of parity-ethere

Dependency solver for Elm, made in WebAssembly

Dependency solver for Elm, made in WebAssembly This repo holds a dependency solver for the elm ecosystem compiled to a WebAssembly module. The wasm mo

A simple code for checking crate 'prost' on WebAssembly (πŸ¦€ + πŸ•ΈοΈ = πŸ’–)

rust-wasm-prost This repository is a simple code for checking crate 'prost' on WebAssembly ( πŸ¦€ + πŸ•ΈοΈ = πŸ’– ). What is prost? prost is a Protocol Buffe

Version of Clue made to be compilable in WebAssembly (WIP)
Version of Clue made to be compilable in WebAssembly (WIP)

Clue is a programming language that compiles into Lua code with a syntax similar to languages like C or Rust. Clue tries to be almost as simple as Lua

Comments
  • example to use diverse plugins

    example to use diverse plugins

    there are dog.wasm, cat.wasm and much more plugins, these are provided by community, and keep growing. the host app is fixed, so it's impossible to define struct for each plugin in host app code, like current example in repo.

    the host app needs to use plugin based on user input. i tried a bit but fail. image

    opened by tkkcc 1
  • Pass down context between host and guest

    Pass down context between host and guest

    Imagine doing this:

    let context = Context::new(); // Context shared by plugins
    let runtime = Runtime::new(context);
    

    Then on guest:

    #[plugy::plugin]
    trait Greeter {
        fn greet(&self, ctx:Context) -> String;
    }
    

    Context can expose methods like fetch etc which would have external access for guests.

    opened by geofmureithi 0
  • Accept multiple arity in plugin functions.

    Accept multiple arity in plugin functions.

    Currently this works:

    #[plugy::plugin]
    trait Greeter {
        fn greet(&self) -> String;
    }
    

    This may not:

    #[plugy::plugin]
    trait Greeter {
        fn greet(&self, name:String) -> String;
    }
    
    opened by geofmureithi 0
  • Enforce structure of the plugin.

    Enforce structure of the plugin.

    Currently we dont have any way of differentiating between plugins that are rightly done eg have all methods defined and a junk wasm file. This causes a panic at calltime and rightly so.

    Is there a way to add some signature or check to prevent loading a wasm file that doesn't conform.

    opened by geofmureithi 0
Releases(v0.2.0)
  • v0.2.0(Aug 16, 2023)

    What's Changed

    • feat: context sharable with plugins by @geofmureithi in https://github.com/geofmureithi/plugy/pull/11
    • chore: bump up version by @geofmureithi in https://github.com/geofmureithi/plugy/pull/12

    Full Changelog: https://github.com/geofmureithi/plugy/compare/v0.1.1...v0.2.0

    Source code(tar.gz)
    Source code(zip)
  • v0.1.1(Aug 9, 2023)

    What's Changed

    • chore: fix failing parts of ci by @geofmureithi in https://github.com/geofmureithi/plugy/pull/6
    • chore: introduce ci for tests and clippy by @geofmureithi in https://github.com/geofmureithi/plugy/pull/5
    • feat: plugin functions can have multiple arity by @geofmureithi in https://github.com/geofmureithi/plugy/pull/7
    • update: n-ary for functions and docs by @geofmureithi in https://github.com/geofmureithi/plugy/pull/8

    New Contributors

    • @geofmureithi made their first contribution in https://github.com/geofmureithi/plugy/pull/6

    Full Changelog: https://github.com/geofmureithi/plugy/compare/v0.1.0...v0.1.1

    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(Aug 8, 2023)

Owner
Geoffrey Mureithi
Hi!, I am Njuguna Mureithi, a #Rust and #WASM enthusiast from Nairobi Kenya.
Geoffrey Mureithi
CosmWasm Contract for Dynamic CW721 NFTs on Terra

CosmWasm Starter Pack This is a template to build smart contracts in Rust to run inside a Cosmos SDK module on all chains that enable it.

null 9 Sep 12, 2022
Build a python wheel from a dynamic library

build_wheel Small utility to create a Python wheel given a pre-built dynamic library (.so, .dylib, .dll). If you are just trying to produce a wheel fr

Tangram 1 Dec 2, 2021
Low level tooling for WebAssembly in JavaScript using wasm-tools

js-wasm-tools js-wasm-tools compiles some of the API of wasm-tools to JavaScript and WebAssembly via wasm-bindgen. This offers low level tooling for W

Dominic Elm 59 Dec 19, 2022
A notebook app integrated with todo lists utility. Developed with Rust, WebAssembly, Yew and Trunk.

Flow.er A notebook app integrated with todo-list utility. Project flow.er is a Rust WASM app running in browser. Taking advantage of Yew and Trunk, it

null 45 Dec 31, 2022
πŸš€ An OSS project to develop and run serverless applications on WebAssembly

Wasm Workers Server Wasm Workers Server (wws) is a framework to develop and run serverless applications server in WebAssembly. These applications are

VMware  Labs 300 Apr 26, 2023
A Zellij plugin to fuzzy find file names and contents in style 🧐

About This Zellij plugin is a fuzzy finder for file names and their contents. It can open results in your $EDITOR (scrolled to the correct line), as f

Aram Drevekenin 11 Jun 22, 2023
WebAssembly implementation from scratch in Safe Rust with zero dependencies

wain wain is a WebAssembly INterpreter written in Rust from scratch with zero dependencies. An implementation of WebAssembly. Features: No unsafe code

Linda_pp 328 Jan 2, 2023
witgen is a library to generate .wit files for WebAssembly in Rust

witgen witgen is a library to help you generate wit definitions in a wit file for WebAssembly. Using this lib in addition to wit-bindgen will help you

Coenen Benjamin 28 Nov 9, 2022
Build frontend browser apps with Rust + WebAssembly. Supports server side rendering.

Percy Build frontend browser apps with Rust + WebAssembly. Supports server side rendering. The Percy Book This README gives a light introduction to Pe

Chinedu Francis Nwafili 2.1k Jan 1, 2023
Rust bindings for Supabase JavaScript library via WebAssembly.

supabase-js-rs Rust bindings for Supabase JavaScript library via WebAssembly. Usage Add supabase-js-rs to Cargo.toml supabase-js-rs = { version = "0.1

Valery Stepanov 8 Jan 13, 2023