Skip to content

Commit

Permalink
linux can link
Browse files Browse the repository at this point in the history
  • Loading branch information
youyuanwu committed Dec 8, 2024
1 parent dfe2ca4 commit 849e02b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
7 changes: 3 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ project(msquic-asio LANGUAGES)

set(_msquic_version "v2.4.5")
set(_win_pkg_url "https://github.com/microsoft/msquic/releases/download/${_msquic_version}/msquic_windows_x64_Release_schannel.zip")
set(_linux_pkg_url "https://github.com/microsoft/msquic/releases/download/${_msquic_version}/msquic_linux_x64_Release_openssl.zip")
if(WIN32)
set(release_url ${_win_pkg_url})
# windows downloads release for winmd generation.
set(release_url ${_win_pkg_url})
message(STATUS "fetching msquic_release " ${release_url})
include(FetchContent)
FetchContent_Declare(
Expand All @@ -14,9 +16,6 @@ FetchContent_Declare(
URL ${release_url}
)
FetchContent_MakeAvailable(msquic_release)
endif(WIN32)

if(WIN32)
# generate winmd. defer generation task in .metadata csproj.
find_program (
dotnet_exe
Expand Down
36 changes: 18 additions & 18 deletions crates/libs/msquic-sys2/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@
// license information.
// ------------------------------------------------------------

use std::{env, path::Path};
// use std::{env, path::Path};

fn main() {
let pkg_dir = String::from("build/_deps/msquic_release-src");
let package_root = env::var("CARGO_MANIFEST_DIR").unwrap();
let project_root = package_root + "/../../../";
let abs_search_dir;
if cfg!(windows) {
// add link dir for fabric support libs. This is propagated to downstream targets
abs_search_dir = project_root + &pkg_dir + "/lib";
} else if cfg!(unix) {
abs_search_dir = project_root + "build"; // hack: we create a symlink in the build dir to let ld not deal with .so versions
//println!("cargo:rustc-link-arg=-Wl,-rpath,{}",abs_search_dir)
} else {
panic!("unsupport platform")
}
println!(
"cargo:rustc-link-search=native={}",
Path::new(&abs_search_dir).display()
);
// let pkg_dir = String::from("build/_deps/msquic_release-src");
// let package_root = env::var("CARGO_MANIFEST_DIR").unwrap();
// let project_root = package_root + "/../../../";
// let abs_search_dir;
// if cfg!(windows) {
// // add link dir for fabric support libs. This is propagated to downstream targets
// abs_search_dir = project_root + &pkg_dir + "/lib";
// } else if cfg!(unix) {
// abs_search_dir = project_root + "build"; // hack: we create a symlink in the build dir to let ld not deal with .so versions
// //println!("cargo:rustc-link-arg=-Wl,-rpath,{}",abs_search_dir)
// } else {
// panic!("unsupport platform")
// }
// println!(
// "cargo:rustc-link-search=native={}",
// Path::new(&abs_search_dir).display()
// );
// This does not work for cargo test
// println!("cargo:rustc-env=LD_LIBRARY_PATH={}", abs_search_dir);
}
10 changes: 10 additions & 0 deletions crates/libs/msquic-sys2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,16 @@ struct ApiTable {
extern "C" fn(connection: Handle, result: BOOLEAN, tls_alert: TlsAlertCode) -> u32,
}

// For apt target which has version suffix
// #[link(name = "msquic")]
#[cfg(target_os = "linux")]
#[link(name = ":libmsquic.so.2")]
extern "C" {
fn MsQuicOpenVersion(version: u32, api: &*const ApiTable) -> u32;
fn MsQuicClose(api: *const ApiTable);
}

#[cfg(target_os = "windows")]
#[link(name = "msquic")]
extern "C" {
fn MsQuicOpenVersion(version: u32, api: &*const ApiTable) -> u32;
Expand Down

0 comments on commit 849e02b

Please sign in to comment.