Stream: wit-bindgen

Topic: component-model for plugin system


view this post on Zulip Cameron M (Apr 25 2023 at 10:58):

Hi :wave: I'm posting here because of a note in wit-bindgen suggesting that new users post a message here if they're considering it for a projects. I'm also quite new to zulip in general, so apologies if I'm posting this in the wrong place :sweat_smile:

I'm trying to evaluate various options for a plugin system for a Rust binary we're building at $JOB. Broadly speaking, I'm looking for a way for users to provide code to run on machines that we control (for doing arbitrary modifications to data in a database). If we were just writing a Rust library, we'd expose a function like:

pub struct Server { ... }

impl Server {
  fn add_plugin(&mut self, plugin: fn(Foo, Ctx) -> Bar) {
    todo!()
  }
}

where Ctx is a type that allows the plugin to do certain operations (such as performing certain database queries). Foo and Bar are just plain-old-data types. In fact, Bar is pretty much identical to serde_json::Value.

Of course, there are 2 big issues with this for our use case: 1) it forces the plugin author to write Rust (mostly), and 2) it doesn't allow plugins to be loaded at runtime. WASM seems like an obvious choice to fix both problems.

I'm quite new to WIT/component-model, but from what I'm reading it seem like it does exactly what we're after.

The main question I have is about the maturity. I'm currently experimenting with wasmtime (though I have no particularly strong feelings about any runtime, happy to switch to another), and I've noticed it has a component-model feature flag. But everything I've seen says that support is "incomplete". Does anyone know the rough status? Is it so incomplete as to not be worth trying? Or are there some edge cases that aren't covered? My fallback plan is to just create buffers and pass CBOR encoded data across the WASM boundary, but of course this isn't without overhead. Some advice would be much appreciated.

Finally, I'm quite interested in seeing WASM components move forward, and am happy to contribute. I'm experienced with Rust, but relatively new to WASM. If there's any work that can be done by someone who fits that description, I'd be happy to help out where possible :)

Thanks :grinning:

A language binding generator for WebAssembly interface types - GitHub - bytecodealliance/wit-bindgen: A language binding generator for WebAssembly interface types

view this post on Zulip Alex Crichton (Apr 25 2023 at 14:18):

Hello and thanks for reaching out! The component-model feature flag of Wasmtime should be relatively robust at this point. I haven't had a chance to go back and update all the documentation to remove the warnings, but you won't be the first to kick the tires and rely on it at least. Support should be complete enough for your use case, although do feel free to file issues if you encounter problems.

view this post on Zulip Alex Crichton (Apr 25 2023 at 14:19):

Use cases such as your and experiences along the lines of "everything is awful" from "everything is fantastic please stabilize" are both quite useful to us!

view this post on Zulip Cameron M (Apr 25 2023 at 15:33):

Thanks :grinning_face_with_smiling_eyes: I'll be sure to report back with any issues, but so far the experience has been pretty painless


Last updated: Dec 23 2024 at 12:05 UTC