Skip to content

Commit

Permalink
Merge branch 'microsoft:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
iiztp authored Jan 8, 2025
2 parents 0090326 + 39c6b52 commit 91475bb
Show file tree
Hide file tree
Showing 40 changed files with 12,543 additions and 1,013 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/cargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-xlarge]
features: ["", "--features static", "--features schannel", "--features schannel,static"]
features: ["", "--features static", "--features schannel", "--features schannel,static", "--features overwrite"]
exclude:
- os: ubuntu-latest
features: "--features schannel"
Expand Down Expand Up @@ -60,6 +60,8 @@ jobs:
run: cargo clippy --all-targets -- -D warnings
- name: Cargo build
run: cargo build --all ${{ matrix.features }}
- name: Check all generated files with git
run: git diff --exit-code
- name: Cargo test
run: cargo test --all ${{ matrix.features }}
- name: Cargo Publish (dry run)
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${QUIC_OUTPUT_DIR})

set(QUIC_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/inc)

include(GNUInstallDirs)

if (WIN32)
set(QUIC_WARNING_FLAGS /WX /W4 /sdl /wd4206 CACHE INTERNAL "")
set(QUIC_COMMON_FLAGS "")
Expand Down
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ include = [
"/submodules/openssl/VMS",
"/submodules/xdp-for-windows/published/external",
"/scripts/build.rs",
"/src/*.rs",
"/src/**/*.rs",
"/src/bin",
"/src/core",
"/src/inc",
Expand All @@ -49,9 +49,12 @@ default = []
schannel = []
static = []
preview-api = []
# Overwrite generated binding by reruning the bindgen
overwrite = [ "dep:bindgen" ]

[build-dependencies]
cmake = "0.1"
bindgen = { version = "0.71", optional = true }

[dependencies]
bitfield = "0.17.0"
Expand Down
43 changes: 43 additions & 0 deletions scripts/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,47 @@ fn main() {
}
println!("cargo:rustc-link-lib=static=msquic");
}

#[cfg(all(feature = "overwrite", not(target_os = "macos")))]
overwrite_bindgen();
}

/// Read the c header and generate rust bindings.
/// TODO: macos currently uses linux bindings.
#[cfg(all(feature = "overwrite", not(target_os = "macos")))]
fn overwrite_bindgen() {
let manifest_dir = std::path::PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
let root_dir = manifest_dir;
// include msquic headers
let inc_dir = root_dir.join("src").join("inc");

// The bindgen::Builder is the main entry point
// to bindgen, and lets you build up options for
// the resulting bindings.
let bindings = bindgen::Builder::default()
// The input header we would like to generate
// bindings for.
.header(root_dir.join("src/ffi/wrapper.hpp").to_str().unwrap())
.clang_arg(format!("-I{}", inc_dir.to_string_lossy()))
.allowlist_recursively(false)
.allowlist_item("QUIC.*|BOOLEAN|BYTE|HQUIC|HRESULT")
.blocklist_type("QUIC_ADDR")
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
// Finish the builder and generate the bindings.
.generate()
// Unwrap the Result and panic on failure.
.expect("Unable to generate bindings");

// Write bindings to the sys mod.
let out_path = root_dir.join("src/ffi");
#[cfg(target_os = "windows")]
let binding_file = "win_bindings.rs";
#[cfg(target_os = "linux")]
let binding_file = "linux_bindings.rs";
// TODO: support macos.
bindings
.write_to_file(out_path.join(binding_file))
.expect("Couldn't write bindings!");
}
16 changes: 11 additions & 5 deletions src/bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ endif()

if(BUILD_SHARED_LIBS)
add_library(msquic SHARED ${SOURCES})
add_library(msquic::msquic ALIAS msquic)
target_include_directories(msquic PUBLIC $<INSTALL_INTERFACE:include>)
target_link_libraries(msquic PRIVATE core msquic_platform inc warnings logging base_link main_binary_link_args)
set_target_properties(msquic PROPERTIES OUTPUT_NAME ${QUIC_LIBRARY_NAME})
Expand Down Expand Up @@ -251,8 +252,6 @@ elseif (CX_PLATFORM STREQUAL "darwin")
PROPERTIES LINK_FLAGS "-exported_symbols_list \"${CMAKE_CURRENT_SOURCE_DIR}/darwin/exports.txt\"")
endif()

include(GNUInstallDirs)

file(GLOB PUBLIC_HEADERS "../inc/*.h" "../inc/*.hpp")

if(QUIC_TLS STREQUAL "openssl" OR QUIC_TLS STREQUAL "openssl3")
Expand All @@ -264,11 +263,18 @@ if(WIN32)
endif()

if(BUILD_SHARED_LIBS)
install(TARGETS msquic msquic_platform inc logging_inc warnings main_binary_link_args ${OTHER_TARGETS} EXPORT msquic DESTINATION lib)
install(TARGETS msquic msquic_platform inc logging_inc warnings main_binary_link_args ${OTHER_TARGETS}
EXPORT msquic
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
else()
install(FILES ${QUIC_STATIC_LIBRARY} DESTINATION lib)
install(FILES "${QUIC_STATIC_LIBRARY}"
DESTINATION lib
)
endif()
install(FILES ${PUBLIC_HEADERS} DESTINATION include)
install(FILES ${PUBLIC_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")

configure_file(msquic-config.cmake.in ${CMAKE_BINARY_DIR}/msquic-config.cmake @ONLY)

Expand Down
12 changes: 7 additions & 5 deletions src/bin/msquic-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ include(CMakeFindDependencyMacro)

include("${CMAKE_CURRENT_LIST_DIR}/msquic.cmake")

foreach(_t IN ITEMS msquic msquic_platform)
if(TARGET msquic::${_t} AND NOT TARGET ${_t})
add_library(${_t} ALIAS msquic::${_t})
endif()
endforeach()
# Legacy names
if(NOT TARGET msquic)
add_library(msquic ALIAS msquic::msquic)
endif()
if(NOT TARGET msquic_platform)
add_library(msquic_platform ALIAS msquic::platform)
endif()
Loading

0 comments on commit 91475bb

Please sign in to comment.