Actix and dynamic library

Hello,

Actually I have a monolithic actix projet. And more my project becomes bigger and more the time to compile is long.
Do you know if it's possible to add routes throw dynamics libraries (I'm on linux) ? Or better : a dynamic library that add routes to the actix App ?

Well. I don't find any solution. The execution falls in a Segfault, maybe because of the necessity to use async in the external function. It's problematic in the long term because a web project may have a lot of code.
Maybe the use of a non-async web framework allow me to use dynamic library... I will try !

Youpi!! Using dynamic library runs well with Rouille. Simple is the best :slight_smile:

lib.rs :

use rouille::Request;
use rouille::Response;

#[no_mangle]
pub fn dispatcher(request: &Request) -> Option<Response> {
    println!("inside lib");
    Some(Response::text("hello world"))
}

main.rs :

use libloading::{Library, Symbol};
use rouille::Request;
use rouille::Response;

fn main() {
    rouille::start_server("0.0.0.0:8080", move |request| dispatcher(request));
}

fn dispatcher(request: &Request) -> Response {
    let resp;
    unsafe {
        let lib = match Library::new("./liblib_test.so") {
            Ok(o) => o,
            Err(e) => {
                panic!("***erreur 1 : {e}");
            }
        };
        let func: Symbol<fn(request: &Request) -> Option<Response>> = match lib.get(b"dispatcher") {
            Ok(o) => o,
            Err(e) => {
                panic!("***erreur 2 : {e}");
            }
        };
        println!("before");
        resp = func(request);
        println!("after");
    }
    match resp {
        Some(r) => return r,
        None => Response::empty_404(),
    }
}