From b148a2afff82e6b6d634f524e8f10d9e5b78aa92 Mon Sep 17 00:00:00 2001 From: iphydf Date: Mon, 25 Dec 2023 12:45:19 +0000 Subject: [PATCH] chore: Simplify msvc build using vcpkg. --- .github/workflows/ci.yml | 67 +++++++++++------ .gitignore | 2 + CMakeLists.txt | 72 +++++++++++++++---- CMakePresets.json | 21 ++++++ auto_tests/CMakeLists.txt | 39 ++++++---- cmake/Dependencies.cmake | 70 ++++-------------- cmake/ModulePackage.cmake | 8 +-- other/astyle/astylerc | 1 - .../docker/tox-bootstrapd.sha256 | 2 +- testing/CMakeLists.txt | 22 ++++-- toxcore/DHT.c | 2 +- toxcore/LAN_discovery.c | 4 +- toxcore/group_announce_test.cc | 2 +- toxcore/group_moderation_test.cc | 2 +- toxcore/network.c | 21 ++++-- toxcore/network.h | 6 +- vcpkg.json | 11 +++ 17 files changed, 223 insertions(+), 129 deletions(-) create mode 100644 CMakePresets.json create mode 100644 vcpkg.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 41ef5980..b453689e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,6 +44,53 @@ jobs: - name: Run cimplefmt run: other/docker/cimplefmt/run -u $(find tox* -name "*.[ch]") + build-android: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + - run: .github/scripts/cmake-android armeabi-v7a + - run: .github/scripts/cmake-android arm64-v8a + - run: .github/scripts/cmake-android x86 + - run: .github/scripts/cmake-android x86_64 + + build-macos: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + - name: Build and test + run: .github/scripts/cmake-osx + + build-msvc: + strategy: + matrix: + version: [2019, 2022] + runs-on: windows-${{ matrix.version }} + env: + VCPKG_ROOT: "C:/vcpkg" + VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite" + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + - name: Export GitHub Actions cache environment variables + uses: actions/github-script@v6 + with: + script: | + core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); + core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); + - name: Configure CMake + run: cmake --preset windows-default + - name: Build + run: cmake --build _build + - name: Test + run: | + cd _build + ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6 --build-config Debug + build-windows: strategy: matrix: @@ -56,26 +103,6 @@ jobs: - name: Cross compilation run: .github/scripts/cmake-win${{ matrix.bits }} script - build-macos: - runs-on: macos-latest - steps: - - uses: actions/checkout@v4 - with: - submodules: recursive - - name: Build and test - run: .github/scripts/cmake-osx - - build-android: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - submodules: recursive - - run: .github/scripts/cmake-android armeabi-v7a - - run: .github/scripts/cmake-android arm64-v8a - - run: .github/scripts/cmake-android x86 - - run: .github/scripts/cmake-android x86_64 - mypy: runs-on: ubuntu-latest steps: diff --git a/.gitignore b/.gitignore index fc3cc5f7..9ed3743e 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,8 @@ Thumbs.db /_build /_install /tox-0.0.0* +/.vs +/CppProperties.json CMakeCache.txt CMakeFiles Makefile diff --git a/CMakeLists.txt b/CMakeLists.txt index 3be4afb9..4b85350f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,7 +81,7 @@ find_package(GTest) set(CMAKE_MACOSX_RPATH ON) # Set standard version for compiler. -if(MSVC) +if(MSVC AND MSVC_TOOLSET_VERSION LESS 143) # https://developercommunity.visualstudio.com/t/older-winsdk-headers-are-incompatible-with-zcprepr/1593479 set(CMAKE_C_STANDARD 99) else() @@ -94,6 +94,35 @@ set(CMAKE_CXX_EXTENSIONS OFF) message(STATUS "Supported C compiler features = ${CMAKE_C_COMPILE_FEATURES}") message(STATUS "Supported C++ compiler features = ${CMAKE_CXX_COMPILE_FEATURES}") +# Enable some warnings if we know the compiler. +if(MSVC) + add_compile_options(/W4 /analyze) + add_compile_options(/wd4100) # unreferenced formal parameter + add_compile_options(/wd4267) # narrowing conversion + add_compile_options(/wd4244) # narrowing conversion + add_compile_options(/wd4127) # conditional expression is constant + add_compile_options(/wd4995) # #pragma deprecated + add_compile_options(/wd4018) # signed/unsigned compare + add_compile_options(/wd4310) # cast truncates constant value + add_compile_options(/wd4389) # signed/unsigned compare + add_compile_options(/wd4245) # signed/unsigned assign/return/function call + add_compile_options(/wd4200) # nonstandard extension used: zero-sized array in struct/union + add_compile_options(/wd4702) # unreachable code + add_compile_options(/wd6340) # unsigned int passed to signed parameter + add_compile_options(/wd6326) # potential comparison of a constant with another constant + + # TODO(iphydf): Look into these + add_compile_options(/wd4996) # use WSAAddressToStringW() instead of WSAAddressToStringA() + add_compile_options(/wd6255) # don't use alloca + add_compile_options(/wd6385) # reading invalid data + add_compile_options(/wd6001) # using uninitialized memory + add_compile_options(/wd6101) # returning uninitialized memory + add_compile_options(/wd6386) # buffer overrun + add_compile_options(/wd6011) # NULL dereference + add_compile_options(/wd6031) # sscanf return value ignored + add_compile_options(/wd6387) # passing NULL to fwrite +endif() + set(MIN_LOGGER_LEVEL "" CACHE STRING "Logging level to use (TRACE, DEBUG, INFO, WARNING, ERROR)") if(MIN_LOGGER_LEVEL) if(("${MIN_LOGGER_LEVEL}" STREQUAL "TRACE") OR @@ -307,10 +336,14 @@ set(toxcore_SOURCES toxcore/tox_unpack.h toxcore/util.c toxcore/util.h) -set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${LIBSODIUM_LIBRARIES}) -set(toxcore_LINK_DIRECTORIES ${toxcore_LINK_DIRECTORIES} ${LIBSODIUM_LIBRARY_DIRS}) -set(toxcore_INCLUDE_DIRECTORIES ${toxcore_INCLUDE_DIRECTORIES} ${LIBSODIUM_INCLUDE_DIRS}) -set(toxcore_COMPILE_OPTIONS ${toxcore_COMPILE_OPTIONS} ${LIBSODIUM_CFLAGS_OTHER}) +if(TARGET unofficial-sodium::sodium) + set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} unofficial-sodium::sodium) +else() + set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${LIBSODIUM_LIBRARIES}) + set(toxcore_LINK_DIRECTORIES ${toxcore_LINK_DIRECTORIES} ${LIBSODIUM_LIBRARY_DIRS}) + set(toxcore_INCLUDE_DIRECTORIES ${toxcore_INCLUDE_DIRECTORIES} ${LIBSODIUM_INCLUDE_DIRS}) + set(toxcore_COMPILE_OPTIONS ${toxcore_COMPILE_OPTIONS} ${LIBSODIUM_CFLAGS_OTHER}) +endif() set(toxcore_PKGCONFIG_REQUIRES ${toxcore_PKGCONFIG_REQUIRES} libsodium) set(toxcore_API_HEADERS ${toxcore_SOURCE_DIR}/toxcore/tox.h^tox @@ -346,10 +379,14 @@ if(BUILD_TOXAV) set(toxcore_API_HEADERS ${toxcore_API_HEADERS} ${toxcore_SOURCE_DIR}/toxav/toxav.h^toxav) - set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${OPUS_LIBRARIES} ${VPX_LIBRARIES}) - set(toxcore_LINK_DIRECTORIES ${toxcore_LINK_DIRECTORIES} ${OPUS_LIBRARY_DIRS} ${VPX_LIBRARY_DIRS}) - set(toxcore_INCLUDE_DIRECTORIES ${toxcore_INCLUDE_DIRECTORIES} ${OPUS_INCLUDE_DIRS} ${VPX_INCLUDE_DIRS}) - set(toxcore_COMPILE_OPTIONS ${toxcore_COMPILE_OPTIONS} ${OPUS_CFLAGS_OTHER} ${VPX_CFLAGS_OTHER}) + if(MSVC) + set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} PkgConfig::OPUS PkgConfig::VPX) + else() + set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${OPUS_LIBRARIES} ${VPX_LIBRARIES}) + set(toxcore_LINK_DIRECTORIES ${toxcore_LINK_DIRECTORIES} ${OPUS_LIBRARY_DIRS} ${VPX_LIBRARY_DIRS}) + set(toxcore_INCLUDE_DIRECTORIES ${toxcore_INCLUDE_DIRECTORIES} ${OPUS_INCLUDE_DIRS} ${VPX_INCLUDE_DIRS}) + set(toxcore_COMPILE_OPTIONS ${toxcore_COMPILE_OPTIONS} ${OPUS_CFLAGS_OTHER} ${VPX_CFLAGS_OTHER}) + endif() set(toxcore_PKGCONFIG_REQUIRES ${toxcore_PKGCONFIG_REQUIRES} opus vpx) endif() @@ -380,7 +417,6 @@ if(CMAKE_THREAD_LIBS_INIT) set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} ${CMAKE_THREAD_LIBS_INIT}) endif() - if(NSL_LIBRARIES) set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${NSL_LIBRARIES}) set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} -lnsl) @@ -396,9 +432,13 @@ if(SOCKET_LIBRARIES) set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} -lsocket) endif() +if(TARGET PThreads4W::PThreads4W) + set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} PThreads4W::PThreads4W) +elseif(TARGET Threads::Threads) + set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} Threads::Threads) +endif() if(WIN32) - set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ws2_32 iphlpapi) - set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} -lws2_32 -liphlpapi) + set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} iphlpapi wsock32 ws2_32) endif() ################################################################################ @@ -496,6 +536,14 @@ if(DHT_BOOTSTRAP) target_link_libraries(DHT_bootstrap PRIVATE toxcore_shared) endif() target_link_libraries(DHT_bootstrap PRIVATE misc_tools) + if(TARGET unofficial-sodium::sodium) + target_link_libraries(DHT_bootstrap PRIVATE unofficial-sodium::sodium) + endif() + if(TARGET PThreads4W::PThreads4W) + target_link_libraries(DHT_bootstrap PRIVATE PThreads4W::PThreads4W) + elseif(TARGET Threads::Threads) + target_link_libraries(DHT_bootstrap PRIVATE Threads::Threads) + endif() install(TARGETS DHT_bootstrap RUNTIME DESTINATION bin) endif() diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 00000000..45caa10d --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,21 @@ +{ + "version": 3, + "configurePresets": [ + { + "name": "windows-default", + "binaryDir": "${sourceDir}/_build", + "cacheVariables": { + "ENABLE_SHARED": true, + "ENABLE_STATIC": true, + "AUTOTEST": true, + "BUILD_MISC_TESTS": true, + "BOOTSTRAP_DAEMON": false, + "MUST_BUILD_TOXAV": true, + "TEST_TIMEOUT_SECONDS": "60", + "CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS": true, + "CMAKE_COMPILE_WARNING_AS_ERROR": true, + "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" + } + } + ] +} diff --git a/auto_tests/CMakeLists.txt b/auto_tests/CMakeLists.txt index ffdf8055..1bc962df 100644 --- a/auto_tests/CMakeLists.txt +++ b/auto_tests/CMakeLists.txt @@ -9,6 +9,11 @@ if(TARGET toxcore_static) else() target_link_libraries(auto_test_support PRIVATE toxcore_shared) endif() +if(TARGET PThreads4W::PThreads4W) + target_link_libraries(auto_test_support PRIVATE PThreads4W::PThreads4W) +elseif(TARGET Threads::Threads) + target_link_libraries(auto_test_support PRIVATE Threads::Threads) +endif() function(auto_test target) add_executable(auto_${target}_test ${target}_test.c) @@ -18,12 +23,15 @@ function(auto_test target) else() target_link_libraries(auto_${target}_test PRIVATE toxcore_shared) endif() - if(NOT ARGV1 STREQUAL "DONT_RUN") - add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} auto_${target}_test) - set_tests_properties(${target} PROPERTIES TIMEOUT "${TEST_TIMEOUT_SECONDS}") - # add the source dir as environment variable, so the testdata can be found - set_tests_properties(${target} PROPERTIES ENVIRONMENT "LLVM_PROFILE_FILE=${target}.profraw;srcdir=${CMAKE_CURRENT_SOURCE_DIR}") + if(TARGET PThreads4W::PThreads4W) + target_link_libraries(auto_${target}_test PRIVATE PThreads4W::PThreads4W) + elseif(TARGET Threads::Threads) + target_link_libraries(auto_${target}_test PRIVATE Threads::Threads) endif() + add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} auto_${target}_test) + set_tests_properties(${target} PROPERTIES TIMEOUT "${TEST_TIMEOUT_SECONDS}") + # add the source dir as environment variable, so the testdata can be found + set_tests_properties(${target} PROPERTIES ENVIRONMENT "LLVM_PROFILE_FILE=${target}.profraw;srcdir=${CMAKE_CURRENT_SOURCE_DIR}") endfunction() auto_test(TCP) @@ -89,15 +97,20 @@ if(BUILD_TOXAV) auto_test(toxav_basic) auto_test(toxav_many) - target_link_libraries(auto_toxav_basic_test PRIVATE ${VPX_LIBRARIES}) - target_link_directories(auto_toxav_basic_test PRIVATE ${VPX_LIBRARY_DIRS}) - target_include_directories(auto_toxav_basic_test SYSTEM PRIVATE ${VPX_INCLUDE_DIRS}) - target_compile_options(auto_toxav_basic_test PRIVATE ${VPX_CFLAGS_OTHER}) + if(MSVC) + target_link_libraries(auto_toxav_basic_test PRIVATE PkgConfig::VPX) + target_link_libraries(auto_toxav_many_test PRIVATE PkgConfig::VPX) + else() + target_link_libraries(auto_toxav_basic_test PRIVATE ${VPX_LIBRARIES}) + target_link_directories(auto_toxav_basic_test PRIVATE ${VPX_LIBRARY_DIRS}) + target_include_directories(auto_toxav_basic_test SYSTEM PRIVATE ${VPX_INCLUDE_DIRS}) + target_compile_options(auto_toxav_basic_test PRIVATE ${VPX_CFLAGS_OTHER}) - target_link_libraries(auto_toxav_many_test PRIVATE ${VPX_LIBRARIES}) - target_link_directories(auto_toxav_many_test PRIVATE ${VPX_LIBRARY_DIRS}) - target_include_directories(auto_toxav_many_test SYSTEM PRIVATE ${VPX_INCLUDE_DIRS}) - target_compile_options(auto_toxav_many_test PRIVATE ${VPX_CFLAGS_OTHER}) + target_link_libraries(auto_toxav_many_test PRIVATE ${VPX_LIBRARIES}) + target_link_directories(auto_toxav_many_test PRIVATE ${VPX_LIBRARY_DIRS}) + target_include_directories(auto_toxav_many_test SYSTEM PRIVATE ${VPX_INCLUDE_DIRS}) + target_compile_options(auto_toxav_many_test PRIVATE ${VPX_CFLAGS_OTHER}) + endif() endif() if(PROXY_TEST) diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index 6f2ec906..900e9b18 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -1,19 +1,26 @@ ############################################################################### # -# :: For UNIX-like systems that have pkg-config. +# :: For systems that have pkg-config. # ############################################################################### -include(ModulePackage) - -find_package(Threads REQUIRED) +find_package(PkgConfig REQUIRED) find_library(NSL_LIBRARIES nsl ) find_library(RT_LIBRARIES rt ) find_library(SOCKET_LIBRARIES socket) +find_package(pthreads QUIET) +if(NOT TARGET PThreads4W::PThreads4W) + set(THREADS_PREFER_PTHREAD_FLAG ON) + find_package(Threads REQUIRED) +endif() + # For toxcore. -pkg_search_module(LIBSODIUM libsodium IMPORTED_TARGET) +pkg_search_module(LIBSODIUM libsodium IMPORTED_TARGET REQUIRED) +if(MSVC) + find_package(unofficial-sodium REQUIRED) +endif() # For toxav. pkg_search_module(OPUS opus IMPORTED_TARGET) @@ -27,56 +34,3 @@ endif() # For tox-bootstrapd. pkg_search_module(LIBCONFIG libconfig IMPORTED_TARGET) - -############################################################################### -# -# :: For MSVC Windows builds. -# -# These require specific installation paths of dependencies: -# - libsodium in third-party/libsodium/Win32/Release/v140/dynamic -# - pthreads in third-party/pthreads-win32/Pre-built.2 -# -############################################################################### - -if(MSVC) - # libsodium - # --------- - if(NOT LIBSODIUM_FOUND) - find_library(LIBSODIUM_LIBRARIES - NAMES sodium libsodium - PATHS - "third_party/libsodium/Win32/Release/v140/dynamic" - "third_party/libsodium/x64/Release/v140/dynamic" - ) - if(LIBSODIUM_LIBRARIES) - include_directories("third_party/libsodium/include") - set(LIBSODIUM_FOUND TRUE) - message("libsodium: ${LIBSODIUM_LIBRARIES}") - else() - message(FATAL_ERROR "libsodium libraries not found") - endif() - endif() - - # pthreads - # -------- - if(CMAKE_USE_WIN32_THREADS_INIT) - find_library(CMAKE_THREAD_LIBS_INIT - NAMES pthreadVC2 - PATHS - "third_party/pthreads-win32/Pre-built.2/lib/x86" - "third_party/pthreads-win32/Pre-built.2/lib/x64" - ) - if(CMAKE_THREAD_LIBS_INIT) - include_directories("third_party/pthreads-win32/Pre-built.2/include") - add_definitions(-DHAVE_STRUCT_TIMESPEC) - message("libpthreads: ${CMAKE_THREAD_LIBS_INIT}") - else() - find_package(pthreads4w) - if(NOT pthreads4w_FOUND) - message(FATAL_ERROR "libpthreads libraries not found") - endif() - include_directories(${pthreads4w_INCLUDE_DIR}) - link_libraries(${pthreads4w_LIBRARIES}) - endif() - endif() -endif() diff --git a/cmake/ModulePackage.cmake b/cmake/ModulePackage.cmake index cbc62f41..332110d7 100644 --- a/cmake/ModulePackage.cmake +++ b/cmake/ModulePackage.cmake @@ -19,18 +19,16 @@ if(FULLY_STATIC) set(ENABLE_STATIC ON) endif() -find_package(PkgConfig) - function(add_module lib) - set(${lib}_SOURCES ${ARGN} PARENT_SCOPE) - if(ENABLE_SHARED) add_library(${lib}_shared SHARED ${ARGN}) set_target_properties(${lib}_shared PROPERTIES OUTPUT_NAME ${lib}) endif() if(ENABLE_STATIC) add_library(${lib}_static STATIC ${ARGN}) - set_target_properties(${lib}_static PROPERTIES OUTPUT_NAME ${lib}) + if(NOT MSVC) + set_target_properties(${lib}_static PROPERTIES OUTPUT_NAME ${lib}) + endif() endif() endfunction() diff --git a/other/astyle/astylerc b/other/astyle/astylerc index 249747aa..9554a3e5 100644 --- a/other/astyle/astylerc +++ b/other/astyle/astylerc @@ -16,7 +16,6 @@ --align-reference=name # Formatting Options ---add-brackets --convert-tabs --max-code-length=120 diff --git a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 index 0d816e70..49fd8104 100644 --- a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 +++ b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 @@ -1 +1 @@ -0ac3f502265ed3c2a4fb2971d1f7b92ad20f900b8daa64b828fd5994c3d4af9d /usr/local/bin/tox-bootstrapd +6d2321d58fa948279b28ae28a888672164eadaa985c43ce99ed0b71a69033c5c /usr/local/bin/tox-bootstrapd diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt index 82f228bf..d664c0fa 100644 --- a/testing/CMakeLists.txt +++ b/testing/CMakeLists.txt @@ -8,10 +8,19 @@ if(TARGET toxcore_static) else() target_link_libraries(misc_tools PRIVATE toxcore_shared) endif() -target_link_libraries(misc_tools PRIVATE ${LIBSODIUM_LIBRARIES}) -target_link_directories(misc_tools PUBLIC ${LIBSODIUM_LIBRARY_DIRS}) -target_include_directories(misc_tools SYSTEM PRIVATE ${LIBSODIUM_INCLUDE_DIRS}) -target_compile_options(misc_tools PRIVATE ${LIBSODIUM_CFLAGS_OTHER}) +if(TARGET unofficial-sodium::sodium) + target_link_libraries(misc_tools PRIVATE unofficial-sodium::sodium) +else() + target_link_libraries(misc_tools PRIVATE ${LIBSODIUM_LIBRARIES}) + target_link_directories(misc_tools PUBLIC ${LIBSODIUM_LIBRARY_DIRS}) + target_include_directories(misc_tools SYSTEM PRIVATE ${LIBSODIUM_INCLUDE_DIRS}) + target_compile_options(misc_tools PRIVATE ${LIBSODIUM_CFLAGS_OTHER}) +endif() +if(TARGET PThreads4W::PThreads4W) + target_link_libraries(misc_tools PRIVATE PThreads4W::PThreads4W) +elseif(TARGET Threads::Threads) + target_link_libraries(misc_tools PRIVATE Threads::Threads) +endif() ################################################################################ # @@ -27,4 +36,9 @@ if(BUILD_MISC_TESTS) else() target_link_libraries(Messenger_test PRIVATE toxcore_shared) endif() + if(TARGET PThreads4W::PThreads4W) + target_link_libraries(Messenger_test PRIVATE PThreads4W::PThreads4W) + elseif(TARGET Threads::Threads) + target_link_libraries(Messenger_test PRIVATE Threads::Threads) + endif() endif() diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 362486fe..42b89215 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -511,7 +511,7 @@ int unpack_ip_port(IP_Port *ip_port, const uint8_t *data, uint16_t length, bool return -1; } - *ip_port = empty_ip_port; + ipport_reset(ip_port); if (is_ipv4) { const uint32_t size = 1 + SIZE_IP4 + sizeof(uint16_t); diff --git a/toxcore/LAN_discovery.c b/toxcore/LAN_discovery.c index f068814b..db995520 100644 --- a/toxcore/LAN_discovery.c +++ b/toxcore/LAN_discovery.c @@ -243,11 +243,11 @@ static IP broadcast_ip(Family family_socket, Family family_broadcast) ip.ip.v6.uint8[15] = 0x01; } else if (net_family_is_ipv4(family_broadcast)) { ip.family = net_family_ipv6(); - ip.ip.v6 = ip6_broadcast; + ip.ip.v6 = get_ip6_broadcast(); } } else if (net_family_is_ipv4(family_socket) && net_family_is_ipv4(family_broadcast)) { ip.family = net_family_ipv4(); - ip.ip.v4 = ip4_broadcast; + ip.ip.v4 = get_ip4_broadcast(); } return ip; diff --git a/toxcore/group_announce_test.cc b/toxcore/group_announce_test.cc index 12995f65..6252e426 100644 --- a/toxcore/group_announce_test.cc +++ b/toxcore/group_announce_test.cc @@ -141,7 +141,7 @@ protected: ann2.ip_port_is_set = 1; ann2.tcp_relays_count = 1; ann2.tcp_relays[0].ip_port.ip.family = net_family_ipv4(); - ann2.tcp_relays[0].ip_port.ip.ip.v4 = ip4_broadcast; + ann2.tcp_relays[0].ip_port.ip.ip.v4 = get_ip4_broadcast(); ann2.tcp_relays[0].public_key[0] = 0xea; } diff --git a/toxcore/group_moderation_test.cc b/toxcore/group_moderation_test.cc index e5512289..3524abef 100644 --- a/toxcore/group_moderation_test.cc +++ b/toxcore/group_moderation_test.cc @@ -79,7 +79,7 @@ TEST(ModList, UnpackingFromEmptyBufferFails) std::vector packed(1); Moderation mods{system_memory()}; - EXPECT_EQ(mod_list_unpack(&mods, packed.end().base(), 0, 1), -1); + EXPECT_EQ(mod_list_unpack(&mods, packed.data(), 0, 1), -1); } TEST(ModList, HashOfEmptyModListZeroesOutBuffer) diff --git a/toxcore/network.c b/toxcore/network.c index bf11a84b..b583fd2f 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -340,12 +340,20 @@ static void fill_addr6(const IP6 *ip, struct in6_addr *addr) #endif static const IP empty_ip = {{0}}; -const IP_Port empty_ip_port = {{{0}}}; -const IP4 ip4_broadcast = { INADDR_BROADCAST }; -const IP6 ip6_broadcast = { - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } -}; +IP4 get_ip4_broadcast(void) +{ + const IP4 ip4_broadcast = { INADDR_BROADCAST }; + return ip4_broadcast; +} + +IP6 get_ip6_broadcast(void) +{ + const IP6 ip6_broadcast = { + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } + }; + return ip6_broadcast; +} IP4 get_ip4_loopback(void) { @@ -357,7 +365,7 @@ IP4 get_ip4_loopback(void) IP6 get_ip6_loopback(void) { /* in6addr_loopback isn't available everywhere, so we do it ourselves. */ - IP6 loopback = empty_ip_port.ip.ip.v6; + IP6 loopback = empty_ip.ip.v6; loopback.uint8[15] = 1; return loopback; } @@ -1452,6 +1460,7 @@ void ipport_reset(IP_Port *ipport) return; } + const IP_Port empty_ip_port = {{{0}}}; *ipport = empty_ip_port; } diff --git a/toxcore/network.h b/toxcore/network.h index dbef9bc8..be7c52f7 100644 --- a/toxcore/network.h +++ b/toxcore/network.h @@ -183,7 +183,7 @@ typedef union IP4 { } IP4; IP4 get_ip4_loopback(void); -extern const IP4 ip4_broadcast; +IP4 get_ip4_broadcast(void); typedef union IP6 { uint8_t uint8[16]; @@ -193,7 +193,7 @@ typedef union IP6 { } IP6; IP6 get_ip6_loopback(void); -extern const IP6 ip6_broadcast; +IP6 get_ip6_broadcast(void); typedef union IP_Union { IP4 v4; @@ -210,8 +210,6 @@ typedef struct IP_Port { uint16_t port; } IP_Port; -extern const IP_Port empty_ip_port; - typedef struct Socket { int sock; } Socket; diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 00000000..96eb8e72 --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,11 @@ +{ + "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", + "dependencies": [ + "gtest", + "libsodium", + "libvpx", + "opus", + "pthreads", + "winsock2" + ] +}