This is a bit of a strange question... but its not easy to find the relevant information I'm looking for. I'm doing some research and just wanting to know if I'm in the right direction. Am I thinking about this the right way? is it worth trying to build something like this or am I totally misunderstanding how roc, dynamic libraries and rust etc work.
// load the roc app
use libloading::{Library, library_filename, Symbol};
unsafe {
// roc app built into a dylib using `roc build --lib color.roc`
let lib = Library::new(library_filename("colors")).unwrap();
// I expect the following signature
// pub unsafe extern "C" fn roc__mainForHost_1_exposed_generic(*RocStr, *(u8,u8,u8,u8)) { ... etc }
let func: Symbol<fn()> = lib.get(b"roc__mainForHost_1_exposed_generic").unwrap();
// can I now simply call roc?? is it that easy
let rgba : *(u8,u8,u8,u8) = func(&RocStr.from("Hello World"));
}
Yeah, something along those line should work just fine. We do it for glue
Probably need to put the right type in the symbol line though
You labeled it as a function that takes no args and returns nothing
Alright then, I'll make a minimal demo to test it out
Can see an example here: https://github.com/roc-lang/roc/blob/main/crates/glue/src/load.rs
Thank you for sharing that ❤
Last updated: Jul 06 2025 at 12:14 UTC