-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(server): build cpprestsdk against libc++ >= 16 via overlay port #1593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Ansh-Karnwal
wants to merge
3
commits into
rocketride-org:develop
Choose a base branch
from
Ansh-Karnwal:fix/RR-1438-cpprestsdk-libcxx16-char-traits
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
3ff5ee9
fix(server): build cpprestsdk against libc++ >= 16 via overlay port
Ansh-Karnwal be8e0d7
fix(server): include <cstdio> explicitly for EOF in cpprestsdk char_t…
Ansh-Karnwal 0fe143d
fix(server): drop constexpr from char_traits assign for C++11 builds
Ansh-Karnwal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| This is a vcpkg overlay port for `cpprestsdk`. | ||
|
|
||
| It is a copy of the upstream vcpkg port (vcpkg `2026.04.27`, cpprestsdk `2.10.19`, | ||
| commit `411a109`) with one extra patch, `fix-libcxx16-char-traits.patch`, layered | ||
| on top of the stock patch set. | ||
|
|
||
| Why it exists: `cpprestsdk` was archived by Microsoft in 2022 and its | ||
| `Value2StringFormatter<uint8_t>` (`Release/include/cpprest/streams.h`) uses | ||
| `std::basic_string<uint8_t>`, which needs `std::char_traits<unsigned char>`. | ||
| libc++ 16 removed that non-standard specialization, so the engine fails to link | ||
| against any modern libc++ (Fedora 40+, Ubuntu 24.04, clang/libc++ 16-22). See | ||
| issue RR-1438. | ||
|
|
||
| The patch reintroduces a minimal, standard-conforming `std::char_traits<unsigned char>` | ||
| in `astreambuf.h`, guarded by `_LIBCPP_VERSION >= 160000` so it is a no-op on | ||
| libstdc++ and on libc++ < 16 (which still ship the extension) and does not cause | ||
| a redefinition there. | ||
|
|
||
| When bumping the pinned vcpkg version, re-sync `portfile.cmake`, `vcpkg.json`, and | ||
| the stock `.patch` files from upstream and re-verify this patch still applies. | ||
| Longer term this port can be dropped once the engine migrates off `cpprestsdk` | ||
| (see RR-1468). |
367 changes: 367 additions & 0 deletions
367
packages/server/cmake/ports/cpprestsdk/fix-asio-error.patch
Large diffs are not rendered by default.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
packages/server/cmake/ports/cpprestsdk/fix-clang-dllimport.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| diff --git a/Release/include/cpprest/details/cpprest_compat.h b/Release/include/cpprest/details/cpprest_compat.h | ||
| index bf107479..00581371 100644 | ||
| --- a/Release/include/cpprest/details/cpprest_compat.h | ||
| +++ b/Release/include/cpprest/details/cpprest_compat.h | ||
| @@ -29,7 +29,6 @@ | ||
| #else // ^^^ _WIN32 ^^^ // vvv !_WIN32 vvv | ||
|
|
||
| #define __declspec(x) __attribute__((x)) | ||
| -#define dllimport | ||
| #define novtable /* no novtable equivalent */ | ||
| #define __assume(x) \ | ||
| do \ | ||
| @@ -74,9 +73,17 @@ | ||
| #define _ASYNCRTIMP_TYPEINFO | ||
| #else // ^^^ _NO_ASYNCRTIMP ^^^ // vvv !_NO_ASYNCRTIMP vvv | ||
| #ifdef _ASYNCRT_EXPORT | ||
| +#ifdef _WIN32 | ||
| #define _ASYNCRTIMP __declspec(dllexport) | ||
| +#else | ||
| +#define _ASYNCRTIMP __attribute__((visibility("default"))) | ||
| +#endif | ||
| #else // ^^^ _ASYNCRT_EXPORT ^^^ // vvv !_ASYNCRT_EXPORT vvv | ||
| +#ifdef _WIN32 | ||
| #define _ASYNCRTIMP __declspec(dllimport) | ||
| +#else | ||
| +#define _ASYNCRTIMP | ||
| +#endif | ||
| #endif // _ASYNCRT_EXPORT | ||
|
|
||
| #if defined(_WIN32) | ||
| diff --git a/Release/include/pplx/pplx.h b/Release/include/pplx/pplx.h | ||
| index d9ba9c61..8d36252c 100644 | ||
| --- a/Release/include/pplx/pplx.h | ||
| +++ b/Release/include/pplx/pplx.h | ||
| @@ -30,9 +30,17 @@ | ||
| #define _PPLXIMP | ||
| #else | ||
| #ifdef _PPLX_EXPORT | ||
| +#ifdef _WIN32 | ||
| #define _PPLXIMP __declspec(dllexport) | ||
| #else | ||
| +#define _PPLXIMP __attribute__((visibility("default"))) | ||
| +#endif | ||
| +#else | ||
| +#ifdef _WIN32 | ||
| #define _PPLXIMP __declspec(dllimport) | ||
| +#else | ||
| +#define _PPLXIMP | ||
| +#endif | ||
| #endif | ||
| #endif | ||
|
|
18 changes: 18 additions & 0 deletions
18
packages/server/cmake/ports/cpprestsdk/fix-find-openssl.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| diff --git a/Release/cmake/cpprest_find_openssl.cmake b/Release/cmake/cpprest_find_openssl.cmake | ||
| index 9333663..c1df089 100644 | ||
| --- a/Release/cmake/cpprest_find_openssl.cmake | ||
| +++ b/Release/cmake/cpprest_find_openssl.cmake | ||
| @@ -36,8 +36,11 @@ function(cpprest_find_openssl) | ||
| # Prefer a homebrew version of OpenSSL over the one in /usr/lib | ||
| file(GLOB OPENSSL_ROOT_DIR /usr/local/Cellar/openssl*/*) | ||
| # Prefer the latest (make the latest one first) | ||
| - list(REVERSE OPENSSL_ROOT_DIR) | ||
| - list(GET OPENSSL_ROOT_DIR 0 OPENSSL_ROOT_DIR) | ||
| + if(OPENSSL_ROOT_DIR) | ||
| + # Prefer the latest (make the latest one first) | ||
| + list(REVERSE OPENSSL_ROOT_DIR) | ||
| + list(GET OPENSSL_ROOT_DIR 0 OPENSSL_ROOT_DIR) | ||
| + endif() | ||
| endif() | ||
| # This should prevent linking against the system provided 0.9.8y | ||
| message(STATUS "OPENSSL_ROOT_DIR = ${OPENSSL_ROOT_DIR}") |
74 changes: 74 additions & 0 deletions
74
packages/server/cmake/ports/cpprestsdk/fix-libcxx16-char-traits.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| diff --git a/Release/include/cpprest/astreambuf.h b/Release/include/cpprest/astreambuf.h | ||
| index 1dcb285..c5e126b 100644 | ||
| --- a/Release/include/cpprest/astreambuf.h | ||
| +++ b/Release/include/cpprest/astreambuf.h | ||
| @@ -22,6 +22,69 @@ | ||
| #include <math.h> | ||
| #include <memory> | ||
|
|
||
| +// libc++ >= 16 removed the non-standard std::char_traits<unsigned char> | ||
| +// specialization (see https://reviews.llvm.org/D157058). cpprestsdk's | ||
| +// Value2StringFormatter<uint8_t> in streams.h uses std::basic_string<uint8_t> | ||
| +// (uint8_t == unsigned char), which requires it, so the engine link fails on | ||
| +// any modern-libc++ host. Reintroduce a minimal, standard-conforming | ||
| +// specialization, but only on affected libc++: libstdc++ and libc++ < 16 still | ||
| +// provide the extension, so the guard avoids a redefinition there. The <string> | ||
| +// include precedes the guard so _LIBCPP_VERSION is defined when it is evaluated. | ||
| +#include <cstdint> | ||
| +#include <cstdio> | ||
| +#include <cstring> | ||
| +#include <string> | ||
| +#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION >= 160000 | ||
| +namespace std | ||
| +{ | ||
| +template<> | ||
| +struct char_traits<unsigned char> | ||
| +{ | ||
| + using char_type = unsigned char; | ||
| + using int_type = int; | ||
| + using off_type = streamoff; | ||
| + using pos_type = streampos; | ||
| + using state_type = mbstate_t; | ||
| + | ||
| + // Not constexpr: a constexpr function returning void is ill-formed pre-C++14, | ||
| + // and macOS builds cpprestsdk as -std=gnu++11. CharTraits does not require | ||
| + // assign to be constexpr (libc++ only makes it so since C++17), so we omit it. | ||
| + static void assign(char_type& a, const char_type& b) noexcept { a = b; } | ||
| + static constexpr bool eq(char_type a, char_type b) noexcept { return a == b; } | ||
| + static constexpr bool lt(char_type a, char_type b) noexcept { return a < b; } | ||
| + static int compare(const char_type* a, const char_type* b, size_t n) { return n == 0 ? 0 : memcmp(a, b, n); } | ||
| + static size_t length(const char_type* s) | ||
| + { | ||
| + size_t i = 0; | ||
| + while (s[i]) | ||
| + ++i; | ||
| + return i; | ||
| + } | ||
| + static const char_type* find(const char_type* s, size_t n, const char_type& c) | ||
| + { | ||
| + return static_cast<const char_type*>(memchr(s, c, n)); | ||
| + } | ||
| + static char_type* move(char_type* d, const char_type* s, size_t n) | ||
| + { | ||
| + return n == 0 ? d : static_cast<char_type*>(memmove(d, s, n)); | ||
| + } | ||
| + static char_type* copy(char_type* d, const char_type* s, size_t n) | ||
| + { | ||
| + return n == 0 ? d : static_cast<char_type*>(memcpy(d, s, n)); | ||
| + } | ||
| + static char_type* assign(char_type* s, size_t n, char_type c) | ||
| + { | ||
| + return n == 0 ? s : static_cast<char_type*>(memset(s, c, n)); | ||
| + } | ||
| + static constexpr int_type not_eof(int_type c) noexcept { return eq_int_type(c, eof()) ? ~eof() : c; } | ||
| + static constexpr char_type to_char_type(int_type c) noexcept { return char_type(c); } | ||
| + static constexpr int_type to_int_type(char_type c) noexcept { return int_type(c); } | ||
| + static constexpr bool eq_int_type(int_type a, int_type b) noexcept { return a == b; } | ||
| + static constexpr int_type eof() noexcept { return int_type(EOF); } | ||
| +}; | ||
| +} // namespace std | ||
| +#endif | ||
| + | ||
| #if (defined(_MSC_VER) && (_MSC_VER >= 1800)) && !CPPREST_FORCE_PPLX | ||
| namespace Concurrency // since namespace pplx = Concurrency | ||
| #else | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| diff --git a/Release/CMakeLists.txt b/Release/CMakeLists.txt | ||
| index b8f3809..3857cfc 100644 | ||
| --- a/Release/CMakeLists.txt | ||
| +++ b/Release/CMakeLists.txt | ||
| @@ -187,7 +187,7 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") | ||
| set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /profile /OPT:REF /OPT:ICF") | ||
|
|
||
| if (WINDOWS_STORE OR WINDOWS_PHONE) | ||
| - add_compile_options(/ZW) | ||
| + # add_compile_options(/ZW) | ||
| else() | ||
| if (NOT (MSVC_VERSION LESS 1920)) | ||
| add_compile_options(/permissive-) | ||
| diff --git a/Release/src/CMakeLists.txt b/Release/src/CMakeLists.txt | ||
| index 128f6d6..098d33f 100644 | ||
| --- a/Release/src/CMakeLists.txt | ||
| +++ b/Release/src/CMakeLists.txt | ||
| @@ -47,6 +47,10 @@ target_include_directories(cpprest | ||
| pch | ||
| ) | ||
|
|
||
| +if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC" AND (WINDOWS_STORE OR WINDOWS_PHONE)) | ||
| + target_compile_options(cpprest PUBLIC /ZW) | ||
| +endif() | ||
| + | ||
| ## Sub-components | ||
| # Websockets component | ||
| if(CPPREST_WEBSOCKETS_IMPL STREQUAL "none") |
50 changes: 50 additions & 0 deletions
50
packages/server/cmake/ports/cpprestsdk/fix_narrowing.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| diff --git a/Release/src/CMakeLists.txt b/Release/src/CMakeLists.txt | ||
| index e15aeb7fc..128f6d6af 100644 | ||
| --- a/Release/src/CMakeLists.txt | ||
| +++ b/Release/src/CMakeLists.txt | ||
| @@ -185,12 +185,12 @@ endif() | ||
|
|
||
| configure_pch(cpprest stdafx.h pch/stdafx.cpp /Zm120) | ||
|
|
||
| -if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") | ||
| +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND NOT MSVC) | ||
| if(WERROR) | ||
| target_compile_options(cpprest PRIVATE -Werror) | ||
| endif() | ||
| target_compile_options(cpprest PRIVATE -pedantic ${WARNINGS}) | ||
| -elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") | ||
| +elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC" OR CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "MSVC") | ||
| if(WERROR) | ||
| target_compile_options(cpprest PRIVATE /WX ${WARNINGS}) | ||
| endif() | ||
| diff --git a/Release/src/streams/fileio_win32.cpp b/Release/src/streams/fileio_win32.cpp | ||
| index 057dd9b67..a65439cb7 100644 | ||
| --- a/Release/src/streams/fileio_win32.cpp | ||
| +++ b/Release/src/streams/fileio_win32.cpp | ||
| @@ -616,7 +616,7 @@ size_t _fill_buffer_fsb(_In_ _file_info_impl* fInfo, | ||
| // pending | ||
| return read; | ||
|
|
||
| - case (-1): | ||
| + case ((size_t)(-1)): | ||
| // error | ||
| delete cb; | ||
| return read; | ||
| @@ -668,7 +668,7 @@ size_t _fill_buffer_fsb(_In_ _file_info_impl* fInfo, | ||
| // pending | ||
| return read; | ||
|
|
||
| - case (-1): | ||
| + case ((size_t)(-1)): | ||
| // error | ||
| delete cb; | ||
| return read; | ||
| @@ -719,7 +719,7 @@ size_t _fill_buffer_fsb(_In_ _file_info_impl* fInfo, | ||
| // pending | ||
| return read; | ||
|
|
||
| - case (-1): | ||
| + case ((size_t)(-1)): | ||
| // error | ||
| delete cb; | ||
| return read; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| vcpkg_from_github( | ||
| OUT_SOURCE_PATH SOURCE_PATH | ||
| REPO Microsoft/cpprestsdk | ||
| REF 411a109150b270f23c8c97fa4ec9a0a4a98cdecf | ||
| SHA512 4f604763f05d53e50dec5deaba283fa4f82d5e7a94c7c8142bf422f4c0bc24bcef00666ddbdd820f64c14e552997d6657b6aca79a29e69db43799961b44b2a1a | ||
| HEAD_REF master | ||
| PATCHES | ||
| fix-find-openssl.patch | ||
| fix_narrowing.patch | ||
| fix-uwp.patch | ||
| fix-clang-dllimport.patch # workaround for https://github.com/microsoft/cpprestsdk/issues/1710 | ||
| silence-stdext-checked-array-iterators-warning.patch | ||
| fix-asio-error.patch | ||
| fix-libcxx16-char-traits.patch # RocketRide: build against libc++ >= 16 (RR-1438) | ||
| ) | ||
|
|
||
| vcpkg_check_features( | ||
| OUT_FEATURE_OPTIONS FEATURE_OPTIONS | ||
| INVERTED_FEATURES | ||
| brotli CPPREST_EXCLUDE_BROTLI | ||
| compression CPPREST_EXCLUDE_COMPRESSION | ||
| websockets CPPREST_EXCLUDE_WEBSOCKETS | ||
| ) | ||
|
|
||
| if(VCPKG_TARGET_IS_UWP) | ||
| set(configure_opts WINDOWS_USE_MSBUILD) | ||
| endif() | ||
|
|
||
| vcpkg_cmake_configure( | ||
| SOURCE_PATH "${SOURCE_PATH}/Release" | ||
| ${configure_opts} | ||
| OPTIONS | ||
| ${FEATURE_OPTIONS} | ||
| -DBUILD_TESTS=OFF | ||
| -DBUILD_SAMPLES=OFF | ||
| -DCPPREST_EXPORT_DIR=share/cpprestsdk | ||
| -DWERROR=OFF | ||
| -DPKG_CONFIG_EXECUTABLE=FALSE | ||
| OPTIONS_DEBUG | ||
| -DCPPREST_INSTALL_HEADERS=OFF | ||
| ) | ||
|
|
||
| vcpkg_cmake_install() | ||
|
|
||
| vcpkg_copy_pdbs() | ||
|
|
||
| vcpkg_cmake_config_fixup(CONFIG_PATH "lib/share/${PORT}") | ||
| file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/lib/share" "${CURRENT_PACKAGES_DIR}/lib/share") | ||
|
|
||
| if (VCPKG_LIBRARY_LINKAGE STREQUAL static) | ||
| vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/cpprest/details/cpprest_compat.h" | ||
| "#ifdef _NO_ASYNCRTIMP" "#if 1") | ||
| endif() | ||
|
|
||
| file(INSTALL "${SOURCE_PATH}/license.txt" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright) |
12 changes: 12 additions & 0 deletions
12
packages/server/cmake/ports/cpprestsdk/silence-stdext-checked-array-iterators-warning.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| diff --git a/Release/CMakeLists.txt b/Release/CMakeLists.txt | ||
| index 3d6df65..9ff6d66 100644 | ||
| --- a/Release/CMakeLists.txt | ||
| +++ b/Release/CMakeLists.txt | ||
| @@ -178,6 +178,7 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") | ||
| set(WARNINGS) | ||
| set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /ignore:4264") | ||
| add_compile_options(/bigobj) | ||
| + add_compile_options(/D_SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING) | ||
| set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MP") | ||
| set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /MP") | ||
| set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MP") |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.