r/rust • u/ImplementCreative106 • 1d ago
Runtime reloadable and removable plugins in rust like cordis
Hi rust community, I think I learnt rust to build webscraper that was efficient for a college project 2,3 years ago given my knowledge is almost none, let's dig into my problem and I would love to have some perspectives or opinions or anything at this point lol,
So I heard rust doesn't have a stable ABI and more and more .
I was inspired by cordis (the javascript meta framework (ik js mentioned)) I wanted to be able to do something of my own harness ik ik lot of questions on why you want to make you own blah blah but I have a potato pc comes with a fair share of problems .
Now the main question is there are implementation of cordis in rust but they truly don't do like do 0 memory waste or 0 cpuc cycle waste not truly 0 but I hope you get the point there is GC so .
I know that this is going to be a tradeoff right now my only options seems to build a binary and replace it inplace with a new one while keeping track of the old one and replacing when it's all good. But thats not really a good way given I have keep track of current binary and previous binary and my original binary just incase so how do I do this ?
TLDR: how do I achieve runtime plugin reloading the rusty way , i do not want to do wasm and all that integrations would leave the point of being rusty and not bloating it.
11
u/Emetros 1d ago
I don’t get the issue with wasm? I’ve seen quite a few videos from dev conf saying that it’s far from being as terrible as people say it is. Pretty much every blog post I read said it was one of the easiest and safest plugin implementation. Are these posts wrong?
9
u/min6char 1d ago
Runtime reloadable plugins and stable ABI are essentially the same thing, if you want reloadable plugins in a language that doesn't have stable ABI, you need to figure out how to emulate stable ABI behavior. So the communications across plugins need to use some kind of marshalling type in the middle, which means you need to accept some amount of duplicated memory. Some common strategies for this in Rust:
- plugin interfaces is FFI bindings (i.e, C bindings). This lets you lean on the fact htat C does have stable ABI
- plugin interfaces are based on some kind of IPC protocol like protobuf, cap'n' proto, flatbuffers, etc. Pick your favorite to get as little waste as you want.
1
u/gschukin 1d ago
There is a project CordisClaw that do the same as Cordis in rust.
0
u/CradleZero 1d ago
If you do end up testing WASM for the hot-reload boundary, curious where the pain actually shows up first: marshalling overhead across the ABI, or cold-start latency when swapping instances live?
0
u/addmoreice 1d ago
I've been building my own harness I call 'suspenders' which hasn't yet been regurgitated up onto my github account, but I have had to deal with this same issue.
I've got a monitoring process, I've got a tight small core that does plugin loading and it works. It's a bit clunky and I've seen a few runs early on where things failed to load when I thought it should have, but in general it *does* work. Now.
It took a *lot* of tests to get everything stable. I've basically had to wrap tests around both sides of everything and write fake plugins that fail in more and more weird ways just to nail down that everything works. *half* the code base is tests built around confirming everything can go down and come back up. It's kind of nuts.
That being said, it *does* work and now that the core is working well, the actual rest of the functionality is coming along swimmingly. Just, be warned, if this is the route you plan to go down, you will need to do a lot of testing to be confident it's working correctly. It's just the nature of the beast.