[botan] Fixes for building with clang/libc++/winpthreads. (#37283)

This commit is contained in:
Daniel Collins 2024-03-12 03:36:30 +00:00 committed by GitHub
parent f521d755a4
commit 919fd8daa7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 52 additions and 1 deletions

View File

@ -0,0 +1,23 @@
--- a/src/tests/tests.h
+++ b/src/tests/tests.h
@@ -17,6 +17,9 @@
#include <map>
#include <memory>
#include <optional>
+#ifndef __ANDROID__
+#include <ranges>
+#endif
#include <set>
#include <sstream>
#include <string>
--- a/src/lib/utils/os_utils.cpp
+++ b/src/lib/utils/os_utils.cpp
@@ -627,6 +627,8 @@
static_cast<void>(pthread_set_name_np(thread.native_handle(), name.c_str()));
#elif defined(BOTAN_TARGET_OS_IS_NETBSD)
static_cast<void>(pthread_set_name_np(thread.native_handle(), "%s", const_cast<char*>(name.c_str())));
+ #elif defined(BOTAN_TARGET_OS_HAS_WIN32) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
+ static_cast<void>(pthread_setname_np(thread.native_handle(), name.c_str()));
#elif defined(BOTAN_TARGET_OS_HAS_WIN32) && defined(BOTAN_BUILD_COMPILER_IS_MSVC)
typedef HRESULT(WINAPI * std_proc)(HANDLE, PCWSTR);
HMODULE kern = GetModuleHandleA("KernelBase.dll");

View File

@ -10,6 +10,7 @@ vcpkg_from_github(
verbose-install.patch
configure-zlib.patch
fix_android.patch
libcxx-winpthread-fixes.patch
)
file(COPY "${CMAKE_CURRENT_LIST_DIR}/configure" DESTINATION "${SOURCE_PATH}")
@ -67,6 +68,12 @@ else()
message(FATAL_ERROR "Unsupported architecture")
endif()
# Allow disabling use of WinSock2 by setting BOTAN_USE_WINSOCK2=OFF in triplet
# for targeting older Windows versions with missing APIs.
if(VCPKG_TARGET_IS_WINDOWS AND DEFINED BOTAN_USE_WINSOCK2 AND NOT BOTAN_USE_WINSOCK2)
vcpkg_list(APPEND configure_arguments --without-os-features=winsock2)
endif()
if(VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW)
vcpkg_list(APPEND configure_arguments --os=windows)
@ -74,6 +81,16 @@ if(VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW)
vcpkg_list(APPEND configure_arguments --cc=msvc)
endif()
# When compiling with Clang, -mrdrand is required to enable the RDRAND intrinsics. Botan will
# check for RDRAND at runtime before trying to use it, so we should be safe to specify this
# without triggering illegal instruction faults on older CPUs.
if(VCPKG_DETECTED_CMAKE_CXX_COMPILER MATCHES "clang-cl(\.exe)?$")
vcpkg_list(APPEND configure_arguments "--extra-cxxflags=${VCPKG_DETECTED_CMAKE_CXX_FLAGS} -mrdrnd")
else()
# ...otherwise just forward the detected CXXFLAGS.
vcpkg_list(APPEND configure_arguments "--extra-cxxflags=${VCPKG_DETECTED_CMAKE_CXX_FLAGS}")
endif()
if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic")
vcpkg_list(APPEND configure_arguments --enable-shared-library --disable-static-library)
else()
@ -103,6 +120,11 @@ if(VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW)
"--msvc-runtime=${BOTAN_MSVC_RUNTIME}d"
"--with-external-libdir=${CURRENT_INSTALLED_DIR}/debug/lib"
--debug-mode
OPTIONS
"CXX=\"${VCPKG_DETECTED_CMAKE_CXX_COMPILER}\""
"LINKER=\"${VCPKG_DETECTED_CMAKE_LINKER}\""
"AR=\"${VCPKG_DETECTED_CMAKE_AR}\""
"EXE_LINK_CMD=\"${VCPKG_DETECTED_CMAKE_LINKER}\" ${VCPKG_LINKER_FLAGS}"
OPTIONS_RELEASE
"ZLIB_LIBS=${ZLIB_LIBS_RELEASE}"
OPTIONS_DEBUG

View File

@ -1,6 +1,7 @@
{
"name": "botan",
"version": "3.2.0",
"port-version": 1,
"description": "A cryptography library written in C++11",
"homepage": "https://botan.randombit.net",
"license": "BSD-2-Clause",

View File

@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "4c689678282e82a42d29348c05a022f237e54700",
"version": "3.2.0",
"port-version": 1
},
{
"git-tree": "3482b0255e093b6d091aa4aff11992c89ec45d6e",
"version": "3.2.0",

View File

@ -1326,7 +1326,7 @@
},
"botan": {
"baseline": "3.2.0",
"port-version": 0
"port-version": 1
},
"box2d": {
"baseline": "2.4.1",