Skip to content

Commit

Permalink
dynamic load works for linux
Browse files Browse the repository at this point in the history
  • Loading branch information
youyuanwu committed Dec 8, 2024
1 parent 77dbb33 commit 206ce5e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 31 deletions.
4 changes: 4 additions & 0 deletions crates/libs/msquic-rs/src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
use crate::Microsoft::MsQuic::QUIC_API_TABLE;

#[cfg(target_os = "windows")]
const LIB_NAME: &str = "msquic.dll";

#[cfg(target_os = "linux")]
const LIB_NAME: &str = "libmsquic.so.2";

lazy_static::lazy_static! {
static ref LIB: libloading::Library = unsafe { libloading::Library::new(LIB_NAME) }.expect("cannot load msquic shared lib");
pub static ref MsQuicOpenVersion: libloading::Symbol<'static,unsafe extern "C" fn(u32, *mut *mut QUIC_API_TABLE) -> i32>
Expand Down
31 changes: 0 additions & 31 deletions crates/samples/simple/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,34 +167,3 @@ mod tests {
api.registation_close(rh);
}
}

#[cfg(test)]
mod test2 {
use std::str::FromStr;

use msquic_rs::Microsoft::MsQuic::{QUIC_API_TABLE, QUIC_API_VERSION_2};

#[test]
fn dynamic_load() {
println!("curr dir: {:?}", std::env::current_dir().unwrap());
#[cfg(target_os = "windows")]
let lib_name = libloading::library_filename("msquic");
// This loads from the apt package.
#[cfg(target_os = "linux")]
let lib_name = std::ffi::OsString::from_str("libmsquic.so.2").unwrap();
let lib = unsafe { libloading::Library::new(lib_name) }.unwrap();
let fn_open: libloading::Symbol<
unsafe extern "C" fn(u32, *mut *mut QUIC_API_TABLE) -> i32,
> = unsafe { lib.get(b"MsQuicOpenVersion") }.unwrap();
let fn_close: libloading::Symbol<unsafe extern "C" fn(*const QUIC_API_TABLE)> =
unsafe { lib.get(b"MsQuicClose") }.unwrap();
let mut api = std::ptr::null_mut::<QUIC_API_TABLE>();
let ec = unsafe { fn_open(QUIC_API_VERSION_2, std::ptr::addr_of_mut!(api)) };
assert_eq!(
ec,
msquic_rs::Microsoft::MsQuic::Win32::QUIC_STATUS_SUCCESS.0
);
assert!(!api.is_null());
unsafe { fn_close(api) };
}
}

0 comments on commit 206ce5e

Please sign in to comment.