fix(server): build cpprestsdk against libc++ >= 16 via overlay port#1593
fix(server): build cpprestsdk against libc++ >= 16 via overlay port#1593Ansh-Karnwal wants to merge 3 commits into
Conversation
The vendored cpprestsdk (archived by Microsoft, frozen at 2.10.19) uses
std::basic_string<uint8_t> in Value2StringFormatter (cpprest/streams.h),
which requires std::char_traits<unsigned char>. libc++ 16 removed that
non-standard specialization, so the engine link fails on any modern-libc++
host (Fedora 40+, Ubuntu 24.04, clang/libc++ 16-22) with:
error: implicit instantiation of undefined template
'std::char_traits<unsigned char>'
Add a vcpkg overlay port for cpprestsdk (a copy of the stock vcpkg 2026.04.27
port and its patch set) with one extra patch that reintroduces a minimal,
standard-conforming std::char_traits<unsigned char> in astreambuf.h. It is
guarded by _LIBCPP_VERSION >= 160000 so it stays a no-op on libstdc++ and on
libc++ < 16, which still ship the extension, and cannot cause a redefinition
there.
Fixes rocketride-org#1438.
🤖 Internal: Discord sync markerAuto-managed by the Discord notification workflow. Stores the linked Discord message ID and forum thread ID. Do not edit or delete. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds a vcpkg overlay port for cpprestsdk, pins its upstream source, applies Boost.Asio and toolchain compatibility patches, configures platform features, and packages the resulting library with CMake metadata and license files. Changescpprestsdk overlay port
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant vcpkg
participant GitHub
participant cpprestsdk
vcpkg->>GitHub: Fetch pinned cpprestsdk commit
vcpkg->>cpprestsdk: Apply compatibility patches
vcpkg->>cpprestsdk: Configure selected features and platform options
cpprestsdk->>vcpkg: Install library, CMake files, and license
Possibly related issues
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/server/cmake/ports/cpprestsdk/fix-libcxx16-char-traits.patch`:
- Around line 17-19: Update the include list in the libc++ char-traits patch to
explicitly include <cstdio>, alongside the existing headers, so the EOF symbol
used by eof() is directly declared rather than relying on transitive inclusion.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 605ee2c6-72cf-42c8-b4a4-65b854392b87
📒 Files selected for processing (10)
packages/server/cmake/ports/cpprestsdk/README.mdpackages/server/cmake/ports/cpprestsdk/fix-asio-error.patchpackages/server/cmake/ports/cpprestsdk/fix-clang-dllimport.patchpackages/server/cmake/ports/cpprestsdk/fix-find-openssl.patchpackages/server/cmake/ports/cpprestsdk/fix-libcxx16-char-traits.patchpackages/server/cmake/ports/cpprestsdk/fix-uwp.patchpackages/server/cmake/ports/cpprestsdk/fix_narrowing.patchpackages/server/cmake/ports/cpprestsdk/portfile.cmakepackages/server/cmake/ports/cpprestsdk/silence-stdext-checked-array-iterators-warning.patchpackages/server/cmake/ports/cpprestsdk/vcpkg.json
…raits patch libc++ prunes transitive includes aggressively, so do not rely on <string> pulling in <cstdio> for the EOF used by char_traits<unsigned char>::eof().
|
Addressed the CodeRabbit review in be8e0d7: added an explicit #include so EOF is directly declared rather than relying on transitive includes. Regenerated the patch and re-verified that the real cpprest/streams.h still compiles clean under libc++. |
macOS compiles cpprestsdk with -std=gnu++11, where a constexpr function returning void is ill-formed (void is not a literal type before C++14), so Apple clang hard-errored on the injected char_traits<unsigned char>::assign. That in turn removed the two-argument assign from the overload set, and libc++'s <string> then failed to find it (too few arguments, expected 3). CharTraits does not require assign to be constexpr; libc++ itself only marks it constexpr since C++17. Dropping constexpr keeps the specialization valid on C++11 (macOS) while remaining correct on the C++14+ Linux/libc++>=16 build.
|
The macOS (ARM64) build failed and I traced it to the char-traits patch. Pushed a fix in 0fe143d. Root cause: macOS compiles cpprestsdk with The Linux/libc++>=16 job passed because it builds at C++14 or newer, where Fix: drop |
|
@asclearuc when you have a moment, could you approve the workflow run for 0fe143d? It is the macOS char-traits fix from above, and since this is a fork PR the run is waiting on approval before it can start. Thanks for kicking off the last one. |
|
Thanks a lot for your contribution — really appreciate you taking the time to put this together! 🙏 I'm going to put this on hold for now. There's an open question on our side about whether we want to keep Thanks again for your patience, and sorry for the wait in the meantime! |
Fixes #1438
Problem
The C++ engine links against a vendored copy of
cpprestsdk(archived by Microsoft, frozen at2.10.19). On any host with a modern libc++ (>= 16), the engine link step fails:This blocks the build on recent distros (Fedora 40+, Ubuntu 24.04) and on clang/libc++ 16 through 22. The Linux engine build uses
-stdlib=libc++, so it is exposed.Root cause
Value2StringFormatter<uint8_t>inRelease/include/cpprest/streams.hreturnsstd::basic_string<uint8_t>. Sinceuint8_tisunsigned char, that type needsstd::char_traits<unsigned char>. libc++ 16 removed the non-standardchar_traitsspecializations forunsigned char(and friends), so the type can no longer be instantiated. libstdc++ still provides the extension, which is why onlylibc++builds break.Note that
cpprestsdkalready defines its ownchar_traits<unsigned char>, but that one lives in theConcurrency::streamsnamespace and does not satisfystd::basic_string, so it does not help here.Change
Add a vcpkg overlay port for
cpprestsdkunderpackages/server/cmake/ports/cpprestsdk/, following the existing overlay-port pattern in this repo (e.g.tinyxml2,breakpad). The overlay is a copy of the stock vcpkg2026.04.27port (cpprestsdk2.10.19, commit411a109) and its patch set, with one extra patch layered on top:fix-libcxx16-char-traits.patchreintroduces a minimal, standard-conformingstd::char_traits<unsigned char>inastreambuf.h(a headerstreams.halready includes).#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION >= 160000, so it is a no-op on libstdc++ and on libc++ < 16. Those still ship the extension, and defining it there would be a redefinition. The<string>include is placed before the guard so_LIBCPP_VERSIONis defined when the guard is evaluated.This is the overlay-port approach suggested in the issue. Migrating off
cpprestsdkentirely is the longer-term path and is tracked separately in #1468.Verification
Reproduced and verified locally with clang/libc++ 22 (the failure exists for any libc++ >= 16):
cpprest/streams.hwithout the patch fails with the exactchar_traits<unsigned char>error at two sites in<string>.-fsyntax-only.std::basic_string<uint8_t>compiles and runs; under gcc/libstdc++ the block is skipped and there is no redefinition. Also confirmed under-std=c++14and-std=c++17.git apply --checkconfirms the patch applies cleanly against a fresh2.10.19checkout.The final engine link against a full libc++ build is left to CI, which builds the port through vcpkg on the pinned toolchain.
Notes for reviewers
portfile.cmake,vcpkg.json, and the stock.patchfiles should be re-synced from upstream and this patch re-verified. This is noted in the port'sREADME.md.Summary by CodeRabbit