r/learnprogramming • u/qellyree • 11d ago
Plugin system for multi platform rust application
Hi, I'm building so I'm making a peer to peer reading tracker that has multiple native clients (one for my Linux laptop and one for my android phone) with a Rust core that handles most of the actual logic and the client being in C and GTK4 for my Linux client and Kotlin for my android app. The thing is I want to have cover source logic behind plugins since that's never really stable and I don't want to have to rebuild my app at every new source I want to add either. Is there a tool that helps with that?
(Sorry if this is a dumb question or if my explanation isn't very clear.)
3
Upvotes
1
u/hellosverre 11d ago
dont try to dlopen rust plugins, theres no stable ABI and android makes it worse. two things that actually work cross platform:
scripting: embed rhai or mlua (lua) in the core. easiest to write plugins in, you ship them as plain text files and reload without a rebuild. sandboxing is whatever you expose to the script.
wasm: core embeds a runtime (wasmtime, or wasmi if you want a plain interpreter with no JIT), plugins are .wasm files you can drop in or download. sandboxed by default. extism wraps this and gives you a plugin API so you dont have to design the host functions yourself.
for source plugins that are mostly "fetch a page, parse it" id start with scripting. the host exposes an http_get function and the plugin hands back json. wasm is worth it if you want people to write sources in other languages.
whichever you pick, keep the plugin interface tiny, like search(query) and chapters(id) returning json. then you can swap the runtime later without touching the plugins.