diff --git a/CMakeLists.txt b/CMakeLists.txt index 46bae23..617b2e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,17 +4,8 @@ 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}) -else() - # linux - set(release_url ${_linux_pkg_url}) - find_package(OpenSSL REQUIRED) - # openssl needs version 1.1. ubuntu 20.04 has it, 22.04 is too new. -endif(WIN32) - if(WIN32) +set(release_url ${_win_pkg_url}) message(STATUS "fetching msquic_release " ${release_url}) include(FetchContent) FetchContent_Declare( @@ -25,17 +16,6 @@ FetchContent_Declare( FetchContent_MakeAvailable(msquic_release) endif(WIN32) -# fetch linux pkg as well on windows for binding generation -if(WIN32) -message(STATUS "fetching msquic_linux_release " ${_linux_pkg_url}) -FetchContent_Declare( - msquic_linux_release - DOWNLOAD_EXTRACT_TIMESTAMP true - URL ${_linux_pkg_url} -) -FetchContent_MakeAvailable(msquic_linux_release) -endif(WIN32) - if(WIN32) # generate winmd. defer generation task in .metadata csproj. find_program ( @@ -74,34 +54,6 @@ add_custom_target(generate_rust WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) -else(WIN32) - # file(GLOB _msquic_dll - # ${msquic_release_SOURCE_DIR}/bin/libmsquic.so.* - # ) - # # create a sym link - # execute_process( - # # for build - # COMMAND ln -sf ${_msquic_dll} ${CMAKE_BINARY_DIR}/libmsquic.so # for linking - # COMMAND ln -sf ${_msquic_dll} ${CMAKE_BINARY_DIR}/libmsquic.so.2 # for loading at runtime - # # for run - # COMMAND mkdir -p ${CMAKE_SOURCE_DIR}/target/debug/deps - # COMMAND cp ${_msquic_dll} ${CMAKE_SOURCE_DIR}/target/debug/libmsquic.so.2 - # COMMAND cp ${_msquic_dll} ${CMAKE_SOURCE_DIR}/target/debug/deps/libmsquic.so.2 - # ) - # copy files to output dir - # file(COPY ${_msquic_dll} DESTINATION ${CMAKE_SOURCE_DIR}/target/debug) -endif(WIN32) - -# downloading the msquic rust manual bindings. - -# message(STATUS "download msquic_bind") -# file(DOWNLOAD -# https://raw.githubusercontent.com/microsoft/msquic/v2.3.5/src/lib.rs -# ${CMAKE_CURRENT_SOURCE_DIR}/crates/libs/c2/src/lib.rs -# TLS_VERIFY ON -# ) - -if(WIN32) # generate cert on windows: find_program(pwsh_exe NAMES pwsh.exe diff --git a/README.md b/README.md index 010a691..1b52e90 100644 --- a/README.md +++ b/README.md @@ -5,5 +5,21 @@ Experimental. Currently can run h3 client and server. +# Build +msquic lib is dynamically loaded and it is not required for building the rust code. + +# Test and run +## Posix +Install msquic pkg: +```sh +sudo apt-get install libmsquic +``` +Rust code will load the lib dynamically. +## Windows +pwsh 7 packages the msquic.dll. If you install pwsh 7, rust will load it from there. + +## Other +You can download msquic from github release [here](https://github.com/microsoft/msquic/releases) and put the lib to locations where app can load it. + # License This project is licensed under the MIT license. \ No newline at end of file diff --git a/crates/libs/msquic-rs/build.rs b/crates/libs/msquic-rs/build.rs deleted file mode 100644 index 6158e03..0000000 --- a/crates/libs/msquic-rs/build.rs +++ /dev/null @@ -1,30 +0,0 @@ -// ------------------------------------------------------------ -// Copyright 2024 Youyuan Wu -// Licensed under the MIT License (MIT). See License in the repo root for -// license information. -// ------------------------------------------------------------ - -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 msquic support lib. This is propagated to downstream targets - abs_search_dir = project_root + &pkg_dir + "/lib"; - } else if cfg!(unix) { - abs_search_dir = project_root + "build"; - // apt pkg dir - println!("cargo:rustc-link-search=native=/usr/lib/x86_64-linux-gnu"); - } 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); -} diff --git a/crates/libs/msquic-rs/src/load.rs b/crates/libs/msquic-rs/src/load.rs index 0aedfe7..368ff5e 100644 --- a/crates/libs/msquic-rs/src/load.rs +++ b/crates/libs/msquic-rs/src/load.rs @@ -15,5 +15,5 @@ lazy_static::lazy_static! { pub static ref MsQuicOpenVersion: libloading::Symbol<'static,unsafe extern "C" fn(u32, *mut *mut QUIC_API_TABLE) -> i32> = unsafe { LIB.get(b"MsQuicOpenVersion") }.expect("cannot load open fn"); pub static ref MsQuicClose: libloading::Symbol<'static, unsafe extern "C" fn(*const QUIC_API_TABLE)> - = unsafe { LIB.get(b"MsQuicClose") }.expect("cannot load open fn"); + = unsafe { LIB.get(b"MsQuicClose") }.expect("cannot load close fn"); }