Skip to main content

jack_sys/
lib.rs

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