Skip to content

Commit

Permalink
refactor on win
Browse files Browse the repository at this point in the history
  • Loading branch information
youyuanwu committed Dec 8, 2024
1 parent 206ce5e commit dfe2ca4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 80 deletions.
50 changes: 1 addition & 49 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 (
Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
30 changes: 0 additions & 30 deletions crates/libs/msquic-rs/build.rs

This file was deleted.

2 changes: 1 addition & 1 deletion crates/libs/msquic-rs/src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

0 comments on commit dfe2ca4

Please sign in to comment.