#implement a plugin system (call external rust scripts from rust)

13 messages · Page 1 of 1 (latest)

hushed isle
#

Hello, i want to implement a plugin system for an app i am building but i don't know exaclty how to do it, currently i am using the wasmtime crate and a simple custom abi (i don't know if it would be better to use wasm-bindgen if i will mainly call wasm code from rust and i am not interested in rust to javascript code)
(I don't really know a lot on how to do this, the implementation was mostly done by ai) I also made (with ai) a macro that i place in front of every function and creates json metadata

{
  "name": "fetch_market_price_via_host",
  "full_path": "test_wasm_full::PriceLevel::fetch_market_price_via_host",
  "callable_type": {
    "Method": {
      "owner_type": "PriceLevel"
    }
  },
  "params": [
    {
      "name": "symbol",
      "param_type": "String"
    }
  ],
  "output_signature": "Number",
  "visibility": "Public",
  "doc_comment": null,
  "is_async": true,
  "executor_type": "Wasm"
}

that i use to call the functions (as they don't have a clear signature) but i don't really know the logic in order to make a good plugin system. If i need to use wasm-bindgen (i want to support async and sync as much as possible), and i want to know how to auto create metadata like that (like how to create build.rs file that would create that kind of json metadata for all the functions so my app knows how to call the functions).
any help is welcome!!

runic sail
#

You might be interested in checking out extism

#

They provide a ready made abi and libraries to deal with making wasm plugins in many langauges (including Rust ofc)

hushed isle
#

thanks a lot, it seems really interesting, is there a way to check the signature of a function? and does it work for structs or objects?

runic sail
#

I haven't delved too deeply into it though (and my wasm knowledge is slightly lacking), so I don't think I can answer those questions in the proper detail I'd like to

#

They do have a discord you can ask that in though!

#

From what I understand, the exported functions for extism all are an pre-agreed upon signature between host and plugin (that is, you provide documentation on how to use your api, along with the signatures)

#

Which obviates the need for checking a signature

#

There is a way to check if a function exists, but I'm not seeing anything about being able to dynamically determine the signature of a fn (other than trying to call it and getting an error, which I guess would signify it's the wrong sig)

#

If that's what you need, you indeed probably have to go with your own custom implementation then

hushed isle
#

yeah it seems really interesting i may do something like a macro that uses exism and generates the signature of the functions (in order to support for more flexibility but in general it seems exactly what i wanted so thank you very much

lavish lava
#

(for extism, they do have a discord server, last time I checked they were quite helpfull)