Coder Social home page Coder Social logo

plugy's Introduction

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 MIT OR Apache-2.0 License.

plugy's People

Contributors

geofmureithi avatar heraclito-q-saldanha avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

plugy's Issues

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.

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

Ability to do generics

Is generics a worthy cause?
Currently they can work on guest but the warpper code generated doesn't

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

cargo
Cargo.toml
crates/plugy-core/Cargo.toml
  • serde 1
  • bincode 1.3.3
  • anyhow 1
crates/plugy-macros/Cargo.toml
  • quote 1.0
  • syn 2.0
  • proc-macro2 1
  • darling 0.20.3
  • convert_case 0.6.0
crates/plugy-runtime/Cargo.toml
  • anyhow 1
  • bincode 1.3.3
  • dashmap 5.5.3
  • serde 1
  • wasmtime 15.0.1
  • async-lock 3.2.0
github-actions
.github/workflows/build.yml
  • actions/checkout v4
  • actions/checkout v4

  • Check this box to trigger a request for Renovate to run again on this repository

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.

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;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.