From 24ac41f4c99a51d4004003f20106d8e6bb519c28 Mon Sep 17 00:00:00 2001 From: Tal Regev Date: Sat, 28 Sep 2024 06:39:53 +0300 Subject: [PATCH] export platform --- .github/workflows/build-reuse-win.yml | 7 ++++ CMakeLists.txt | 4 +- src/bin/CMakeLists.txt | 20 +++++++--- src/core/unittest/CMakeLists.txt | 2 +- src/generated/CMakeLists.txt | 12 ++++-- src/perf/bin/CMakeLists.txt | 2 +- src/platform/CMakeLists.txt | 34 ++++++++--------- src/platform/unittest/CMakeLists.txt | 2 +- src/platform/unittest/external/CMakeLists.txt | 38 +++++++++++++++++++ src/test/bin/CMakeLists.txt | 2 +- src/tools/CMakeLists.txt | 2 +- src/tools/attack/CMakeLists.txt | 2 +- src/tools/pcp/CMakeLists.txt | 4 +- src/tools/recvfuzz/CMakeLists.txt | 2 +- submodules/CMakeLists.txt | 8 ++-- 15 files changed, 102 insertions(+), 39 deletions(-) create mode 100644 src/platform/unittest/external/CMakeLists.txt diff --git a/.github/workflows/build-reuse-win.yml b/.github/workflows/build-reuse-win.yml index f19a77372d..7b65871bdf 100644 --- a/.github/workflows/build-reuse-win.yml +++ b/.github/workflows/build-reuse-win.yml @@ -86,6 +86,13 @@ jobs: if: inputs.build == '-Test' shell: pwsh run: scripts/build.ps1 -Config ${{ inputs.config }} -Platform ${{ inputs.plat }} -Arch ${{ inputs.arch }} -Tls ${{ inputs.tls }} -DisablePerf -DynamicCRT ${{ inputs.sanitize }} + - name: Build External Platform Test + if: inputs.build == '-Test' && inputs.sanitize != '-Sanitize' + shell: pwsh + run: | + cmake --install build\${{ inputs.plat }}\${{ inputs.arch }}_${{ inputs.tls }} --config ${{ inputs.config }} + cmake src/platform/unittest/external -G "Visual Studio 17 2022" -A ${{ inputs.arch }} -B build_external "-DCMAKE_INSTALL_PREFIX:PATH=C:/Program Files/msquic" -DQUIC_TLS=${{ inputs.tls }} + cmake --build build_external --config ${{ inputs.config }} - name: Build For Perf if: inputs.build == '-Perf' shell: pwsh diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a6933b97d..718247224d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -471,7 +471,9 @@ if(WIN32) set_property(TARGET MsQuicEtw_HeaderBuild PROPERTY FOLDER "${QUIC_FOLDER_PREFIX}helpers") add_library(MsQuicEtw_Header INTERFACE) - target_include_directories(MsQuicEtw_Header INTERFACE ${QUIC_BUILD_DIR}/inc) + target_include_directories(MsQuicEtw_Header INTERFACE + $ + $) add_dependencies(MsQuicEtw_Header MsQuicEtw_HeaderBuild) add_library(MsQuicEtw_Resource OBJECT ${QUIC_BUILD_DIR}/inc/MsQuicEtw.rc) diff --git a/src/bin/CMakeLists.txt b/src/bin/CMakeLists.txt index 16cef4e31e..1262cb20b4 100644 --- a/src/bin/CMakeLists.txt +++ b/src/bin/CMakeLists.txt @@ -11,7 +11,7 @@ endif() if(BUILD_SHARED_LIBS) add_library(msquic SHARED ${SOURCES}) - target_link_libraries(msquic PRIVATE core platform inc warnings logging base_link main_binary_link_args) + 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}) if (NOT WIN32) set_target_properties(msquic PROPERTIES SOVERSION ${QUIC_MAJOR_VERSION} VERSION ${QUIC_FULL_VERSION}) @@ -21,7 +21,7 @@ if(BUILD_SHARED_LIBS) endif() else() add_library(msquic_static STATIC static/empty.c) - target_link_libraries(msquic_static PRIVATE core platform inc logging main_binary_link_args) + target_link_libraries(msquic_static PRIVATE core msquic_platform inc logging main_binary_link_args) target_compile_definitions(msquic_static PUBLIC QUIC_BUILD_STATIC) set_property(TARGET msquic_static PROPERTY FOLDER "${QUIC_FOLDER_PREFIX}libraries") @@ -150,7 +150,7 @@ else() COMMAND libtool -static -o \"${QUIC_STATIC_LIBRARY}\" @${QUIC_DEPS_FILE} DEPENDS ${QUIC_DEPS_FILE} DEPENDS core - DEPENDS platform + DEPENDS msquic_platform DEPENDS msquic_static ) elseif(WIN32) @@ -181,7 +181,7 @@ else() COMMAND ${CMAKE_COMMAND} -E copy "${QUIC_STATIC_LIBRARY}" "${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}" DEPENDS ${QUIC_DEPS_FILE} DEPENDS core - DEPENDS platform + DEPENDS msquic_platform DEPENDS msquic_static ) else() @@ -205,7 +205,7 @@ else() COMMAND ${CMAKE_AR} -M < ${QUIC_DEPS_FILE} DEPENDS ${QUIC_DEPS_FILE} DEPENDS core - DEPENDS platform + DEPENDS msquic_platform DEPENDS msquic_static ) endif() @@ -254,8 +254,16 @@ include(GNUInstallDirs) file(GLOB PUBLIC_HEADERS "../inc/*.h" "../inc/*.hpp") +if(QUIC_TLS STREQUAL "openssl" OR QUIC_TLS STREQUAL "openssl3") + list(APPEND OTHER_TARGETS OpenSSL OpenSSLQuic) +endif() + +if(WIN32) + list(APPEND OTHER_TARGETS MsQuicEtw_Header) +endif() + if(BUILD_SHARED_LIBS) - install(TARGETS msquic EXPORT msquic DESTINATION lib) + install(TARGETS msquic msquic_platform inc logging_inc warnings main_binary_link_args ${OTHER_TARGETS} EXPORT msquic DESTINATION lib) else() install(FILES ${QUIC_STATIC_LIBRARY} DESTINATION lib) endif() diff --git a/src/core/unittest/CMakeLists.txt b/src/core/unittest/CMakeLists.txt index 4f811b475e..4e4170cf99 100644 --- a/src/core/unittest/CMakeLists.txt +++ b/src/core/unittest/CMakeLists.txt @@ -27,7 +27,7 @@ set_property(TARGET msquiccoretest APPEND PROPERTY BUILD_RPATH "$ORIGIN") target_link_libraries(msquiccoretest msquic) if (BUILD_SHARED_LIBS) - target_link_libraries(msquiccoretest core platform) + target_link_libraries(msquiccoretest core msquic_platform) endif() target_link_libraries(msquiccoretest inc gtest warnings logging base_link) diff --git a/src/generated/CMakeLists.txt b/src/generated/CMakeLists.txt index 19c49f1bf3..93bd6cc9a2 100644 --- a/src/generated/CMakeLists.txt +++ b/src/generated/CMakeLists.txt @@ -23,9 +23,15 @@ if(QUIC_ENABLE_LOGGING) target_link_libraries(logging PRIVATE inc) elseif(QUIC_LOGGING_TYPE STREQUAL "lttng") - target_include_directories(logging_inc INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/common) - target_include_directories(logging_inc INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/linux) - target_include_directories(logging_inc INTERFACE ${LTTNGUST_INCLUDE_DIRS}) + target_include_directories(logging_inc INTERFACE + $ + $) + target_include_directories(logging_inc INTERFACE + $ + $) + target_include_directories(logging_inc INTERFACE + $ + $) FILE(GLOB LOGGING_FILES ${CMAKE_CURRENT_SOURCE_DIR}/linux/*.c) add_library(logging STATIC ${LOGGING_FILES}) diff --git a/src/perf/bin/CMakeLists.txt b/src/perf/bin/CMakeLists.txt index 788f15bc7b..86fa457c66 100644 --- a/src/perf/bin/CMakeLists.txt +++ b/src/perf/bin/CMakeLists.txt @@ -12,7 +12,7 @@ set_property(TARGET secnetperf PROPERTY FOLDER "${QUIC_FOLDER_PREFIX}perf") target_link_libraries(secnetperf inc warnings perflib msquic) if (BUILD_SHARED_LIBS) - target_link_libraries(secnetperf platform) + target_link_libraries(secnetperf msquic_platform) endif() target_link_libraries(secnetperf logging base_link) diff --git a/src/platform/CMakeLists.txt b/src/platform/CMakeLists.txt index 358b5f0a09..997906d0cd 100644 --- a/src/platform/CMakeLists.txt +++ b/src/platform/CMakeLists.txt @@ -59,21 +59,21 @@ else() message(FATAL_ERROR "TLS Provider not configured") endif() -add_library(platform STATIC ${SOURCES}) +add_library(msquic_platform STATIC ${SOURCES}) if("${CX_PLATFORM}" STREQUAL "windows") target_link_libraries( - platform + msquic_platform PUBLIC wbemuuid) - target_link_libraries(platform PUBLIC winmm) + target_link_libraries(msquic_platform PUBLIC winmm) elseif(QUIC_LINUX_XDP_ENABLED) find_library(NL_LIB nl-3) find_library(NL_ROUTE_LIB nl-route-3) find_library(XDP_LIB libxdp.so) find_library(BPF_LIB libbpf.so) - target_include_directories(platform PRIVATE /usr/include/xdp) - target_include_directories(platform PRIVATE /usr/include/bpf) + target_include_directories(msquic_platform PRIVATE /usr/include/xdp) + target_include_directories(msquic_platform PRIVATE /usr/include/bpf) set(XDP_PROG_INCLUDE_DIR "-I/usr/include/bpf") # building XDP program @@ -88,7 +88,7 @@ elseif(QUIC_LINUX_XDP_ENABLED) DEPENDS ${PROJECT_SOURCE_DIR}/src/platform/datapath_raw_xdp_linux_kern.c ) add_custom_target(xdp_program DEPENDS ${QUIC_OUTPUT_DIR}/datapath_raw_xdp_kern.o) - add_dependencies(platform xdp_program) + add_dependencies(msquic_platform xdp_program) if (NOT BUILD_SHARED_LIBS) find_library(ELF_LIB elf) # for static @@ -103,37 +103,37 @@ elseif(QUIC_LINUX_XDP_ENABLED) string(REPLACE ".so" ".a" BPF_LIB ${BPF_LIB}) endif() - target_link_libraries(platform PUBLIC ${XDP_LIB} ${BPF_LIB} ${NL_LIB} ${NL_ROUTE_LIB} ${ELF_LIB} ${Z_LIB} ${ZSTD_LIB}) + target_link_libraries(msquic_platform PUBLIC ${XDP_LIB} ${BPF_LIB} ${NL_LIB} ${NL_ROUTE_LIB} ${ELF_LIB} ${Z_LIB} ${ZSTD_LIB}) endif() -target_link_libraries(platform PUBLIC inc) -target_link_libraries(platform PRIVATE warnings main_binary_link_args) +target_link_libraries(msquic_platform PUBLIC inc) +target_link_libraries(msquic_platform PRIVATE warnings main_binary_link_args) -set_property(TARGET platform PROPERTY FOLDER "${QUIC_FOLDER_PREFIX}libraries") +set_property(TARGET msquic_platform PROPERTY FOLDER "${QUIC_FOLDER_PREFIX}libraries") if ("${CX_PLATFORM}" STREQUAL "windows") target_include_directories( - platform + msquic_platform PRIVATE ${EXTRA_PLATFORM_INCLUDE_DIRECTORIES} ${PROJECT_SOURCE_DIR}/submodules/xdp-for-windows/published/external) elseif(QUIC_LINUX_XDP_ENABLED) include_directories(/usr/include/libnl3) - target_include_directories(platform PRIVATE ${EXTRA_PLATFORM_INCLUDE_DIRECTORIES}) + target_include_directories(msquic_platform PRIVATE ${EXTRA_PLATFORM_INCLUDE_DIRECTORIES}) endif() if (MSVC AND (QUIC_TLS STREQUAL "openssl" OR QUIC_TLS STREQUAL "schannel") AND NOT QUIC_ENABLE_SANITIZERS) - target_compile_options(platform PRIVATE /analyze) + target_compile_options(msquic_platform PRIVATE /analyze) endif() if(QUIC_TLS STREQUAL "openssl" OR QUIC_TLS STREQUAL "openssl3") - target_link_libraries(platform PUBLIC OpenSSL) + target_link_libraries(msquic_platform PUBLIC OpenSSL) if (CX_PLATFORM STREQUAL "darwin") - target_link_libraries(platform PUBLIC "-framework CoreFoundation" "-framework Security") + target_link_libraries(msquic_platform PUBLIC "-framework CoreFoundation" "-framework Security") endif() elseif(QUIC_TLS STREQUAL "schannel") - target_link_libraries(platform PUBLIC secur32) + target_link_libraries(msquic_platform PUBLIC secur32) if (NOT QUIC_GAMECORE_BUILD) - target_link_libraries(platform PUBLIC onecore) + target_link_libraries(msquic_platform PUBLIC onecore) endif() endif() diff --git a/src/platform/unittest/CMakeLists.txt b/src/platform/unittest/CMakeLists.txt index e514d6634a..997066bb10 100644 --- a/src/platform/unittest/CMakeLists.txt +++ b/src/platform/unittest/CMakeLists.txt @@ -20,7 +20,7 @@ set_property(TARGET msquicplatformtest APPEND PROPERTY BUILD_RPATH "$ORIGIN") target_link_libraries(msquicplatformtest msquic) if (BUILD_SHARED_LIBS) - target_link_libraries(msquicplatformtest platform) + target_link_libraries(msquicplatformtest msquic_platform) endif() target_link_libraries(msquicplatformtest inc gtest warnings logging base_link) diff --git a/src/platform/unittest/external/CMakeLists.txt b/src/platform/unittest/external/CMakeLists.txt new file mode 100644 index 0000000000..d878be6b6c --- /dev/null +++ b/src/platform/unittest/external/CMakeLists.txt @@ -0,0 +1,38 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +cmake_minimum_required(VERSION 3.16) + +project(msquic_platform_external) + +find_package(msquic REQUIRED) +find_library(MSPLATFORM_LIBRARIES + NAMES msquic_platform) + +message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}") +message(STATUS "MSPLATFORM_LIBRARIES: ${MSPLATFORM_LIBRARIES}") + +include(FetchContent) +FetchContent_Declare( + googletest + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../submodules/googletest +) +FetchContent_MakeAvailable(googletest) + +set(SOURCES + ../main.cpp + ../CryptTest.cpp + ../DataPathTest.cpp + ../PlatformTest.cpp + # ../StorageTest.cpp + ../TlsTest.cpp +) + +if(QUIC_TLS STREQUAL "openssl" OR QUIC_TLS STREQUAL "openssl3") + list(APPEND OTHER_TERGETS OpenSSL) +endif() + +add_executable(msquicplatformtest ${SOURCES}) +target_include_directories(msquicplatformtest PRIVATE ${CMAKE_INSTALL_PREFIX}/include) +target_link_libraries(msquicplatformtest PRIVATE msquic ${MSPLATFORM_LIBRARIES} ${OTHER_TERGETS} gtest ws2_32 schannel ntdll bcrypt ncrypt crypt32 iphlpapi advapi32 secur32 userenv onecore winmm clang_rt.asan_dbg_dynamic-x86_64 clang_rt.asan_dynamic-x86_64) +target_compile_definitions(msquicplatformtest PRIVATE QUIC_EVENTS_STUB QUIC_LOGS_STUB _DISABLE_VECTOR_ANNOTATION _DISABLE_STRING_ANNOTATION) diff --git a/src/test/bin/CMakeLists.txt b/src/test/bin/CMakeLists.txt index 895d64d053..c4388894f5 100644 --- a/src/test/bin/CMakeLists.txt +++ b/src/test/bin/CMakeLists.txt @@ -16,7 +16,7 @@ set_property(TARGET msquictest APPEND PROPERTY BUILD_RPATH "$ORIGIN") target_link_libraries(msquictest msquic testlib) if (BUILD_SHARED_LIBS) - target_link_libraries(msquictest platform) + target_link_libraries(msquictest msquic_platform) endif() target_link_libraries(msquictest inc gtest logging base_link) diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt index 48519c06c1..14582b3d7a 100644 --- a/src/tools/CMakeLists.txt +++ b/src/tools/CMakeLists.txt @@ -9,7 +9,7 @@ function(add_quic_tool) target_link_libraries(${targetname} inc warnings msquic) if (BUILD_SHARED_LIBS) - target_link_libraries(${targetname} platform) + target_link_libraries(${targetname} msquic_platform) endif() target_link_libraries(${targetname} logging base_link) diff --git a/src/tools/attack/CMakeLists.txt b/src/tools/attack/CMakeLists.txt index 23fcf87861..04ef2eb761 100644 --- a/src/tools/attack/CMakeLists.txt +++ b/src/tools/attack/CMakeLists.txt @@ -12,7 +12,7 @@ target_include_directories(quicattack PRIVATE ${PROJECT_SOURCE_DIR}/src/core) target_link_libraries(quicattack) if (BUILD_SHARED_LIBS) - target_link_libraries(quicattack core platform) + target_link_libraries(quicattack core msquic_platform) endif() target_link_libraries(quicattack logging) diff --git a/src/tools/pcp/CMakeLists.txt b/src/tools/pcp/CMakeLists.txt index 43761a8758..f9f6d6d50e 100644 --- a/src/tools/pcp/CMakeLists.txt +++ b/src/tools/pcp/CMakeLists.txt @@ -8,5 +8,5 @@ set(SOURCES add_quic_tool(quicpcp ${SOURCES}) target_include_directories(quicpcp PRIVATE ${PROJECT_SOURCE_DIR}/src/core) -# OK to include platform a second time, will not cause multiple link issues -target_link_libraries(quicpcp core platform) +# OK to include msquic_platform a second time, will not cause multiple link issues +target_link_libraries(quicpcp core msquic_platform) diff --git a/src/tools/recvfuzz/CMakeLists.txt b/src/tools/recvfuzz/CMakeLists.txt index 60af99758c..c8d56aead8 100644 --- a/src/tools/recvfuzz/CMakeLists.txt +++ b/src/tools/recvfuzz/CMakeLists.txt @@ -7,5 +7,5 @@ endif() add_quic_tool(recvfuzz recvfuzz.cpp) target_include_directories(recvfuzz PRIVATE ${PROJECT_SOURCE_DIR}/src/core) if (BUILD_SHARED_LIBS) - target_link_libraries(recvfuzz core msquic platform) + target_link_libraries(recvfuzz core msquic msquic_platform) endif() diff --git a/submodules/CMakeLists.txt b/submodules/CMakeLists.txt index a6c5929512..4bf8117629 100644 --- a/submodules/CMakeLists.txt +++ b/submodules/CMakeLists.txt @@ -157,8 +157,9 @@ if (WIN32) target_include_directories( OpenSSLQuic INTERFACE - $<$:${OPENSSL_DIR}/debug/include> - $<$>:${OPENSSL_DIR}/release/include> + $:${OPENSSL_DIR}/debug/include> + $<$>:${OPENSSL_DIR}/release/include>> + $ ) target_link_libraries( OpenSSLQuic @@ -327,7 +328,8 @@ else() target_include_directories( OpenSSLQuic INTERFACE - ${OPENSSL_DIR}/include + $ + $ ) target_link_libraries(