Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider a libloading-based dynamic mode #655

Open
dtolnay opened this issue Jan 3, 2021 · 1 comment
Open

Consider a libloading-based dynamic mode #655

dtolnay opened this issue Jan 3, 2021 · 1 comment

Comments

@dtolnay
Copy link
Owner

dtolnay commented Jan 3, 2021

Imagining something like:

#[cxx::bridge]
mod ffi {
    #[dynamic_load]
    extern "C++" {
        /* as normal */
        fn demo(s: &str) -> u8;
    }
}

fn main() -> Result<()> {
    let ffi = ffi::load("/path/to/liblibrary.so")?;
    let x: u8 = ffi.demo?("...");
    println!("{}", x);
    Ok(())
}

where loading produces an appropriate wrapper struct around libloading::Library. Importantly, not all of the symbols may be available in the runtime version of the library, hence the ? when calling one.


Related discussions:

@samyak-jain
Copy link

It seems rust-bindgen has support for this. What would it take to add support for this here? Would love to contribute here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants