I’m interested in the possibility of compiling and dynamically loading small pieces of code written in (ideally) Rust at runtime. In my particular use case it’s for some complex predicates that aren’t stateful but need to hang around for some time (10s of seconds to minutes). There are potentially 1,000s of them, so compiling them makes some sense.
However, I can’t use
dlopen() and thus libloading because I’m using musl:-
- musl does not unload libraries (
dlclose()) - for quite valid reasons. However, for a long running application, this will eventually cause a crash
- When statically linked, musl’s
dlopen()is just a stub that always fails. Again, that’s quite valid (it’s a hard problem to solve) but makes
libloadingunsuitable. Static-linking is much preferred for our deployment environment
So: Does anyone know of an alternative solution? I’m aware that MS solved this somewhat when they created BitFunnel, but (a) it’s more limited and (b) it would appear to be very painful to write a Rust wrapper for it. Is something using LLVM IT bitcode and its JIT possible? As a fallback, I can use LuaJIT, but it’s not exactly what I’m after.
Help gratefully received.