Can I make a crate that asks the user to make a library exposing a custom start
function that takes parameters, and then builds a different main.rs
, which wraps around that start
function?
I'm guessing cargo-apk does something that sort-of resembles this.
That's a similar plugin architecture to what I'm doing with mdbook
, except instead of doing it at a binary level (where each library has a known entry point like start
), a "plugin" is an executable which receives input via stdin and writes output to stdout. Here's the chapter from the user guide explaining how this works.
Otherwise in my FFI guide I go through a more similar use case in great detail, where you're using dlopen()
and the plugin exposes a known C API and your application loads that DLL/Shared Object at runtime.
I think your recompiling method and calling a custom start
function may be a little inflexible, seeing as you essentially need to recompile a main.rs
for every plugin library.
2 Likes