jack_sys/
lib.rs

1#![allow(non_camel_case_types, non_upper_case_globals)]
2use lazy_static::lazy_static;
3
4mod consts;
5mod types;
6
7// Contains both static and dynamic dispatched functions.
8mod functions {
9    include!(concat!(env!("OUT_DIR"), "/functions.rs"));
10}
11
12pub use consts::*;
13pub use types::*;
14
15#[cfg(not(feature = "dynamic_loading"))]
16pub use functions::dynamic_linking::*;
17#[cfg(feature = "dynamic_loading")]
18pub use functions::dynamic_loading::*;
19
20lazy_static! {
21    static ref LIB_RESULT: Result<libloading::Library, libloading::Error> = unsafe {
22        log::info!("Loading jack from {}.", JACK_LIB);
23        libloading::Library::new(JACK_LIB)
24    };
25}
26
27/// Get the underlying library handle used for dynamic loading. Can be used to extract symbols from
28/// the library.
29///
30/// # Example
31/// ```rust
32/// let symbol = library.get::<unsafe extern "C" fn(client: *mut jack_client_t) -> ::libc::c_int>(b"jack_release_timebase").unwrap();
33/// let raw_symbol = symbol.into_raw();
34/// let func = *raw_symbol.deref() as unsafe extern "C" fn(client: *mut jack_client_t) -> ::libc::c_int;
35/// ```
36pub fn library() -> Result<&'static libloading::Library, impl std::error::Error> {
37    LIB_RESULT.as_ref()
38}