From 0fb12d570e3f395bc905afd60e2f58ef3c759ed7 Mon Sep 17 00:00:00 2001 From: Uche Uba Date: Thu, 30 Jan 2025 18:27:50 -0800 Subject: [PATCH] enabling from std library for folly when c++ version is 20 Summary: When upgrading the C++ version from 17 -> 20 for fbcode and xplat, the folly library coroutine depends on the header which has been added to the std library in v20 as opposed to header. This diff ensures that the given a c++ version, the right coroutine header is always selected Problem: The `LLVM_COROUTINES` flag is used to enable the folly coroutines library, and based on the c++ version, it should either include the (v20) or (v17) header. The current issue when upgrading however occurs in the if directive changed within this diff; It checks `!defined(LLVM_COROUTINES)` when determining which library to include. Because it has to be defined for folly to utilize coroutines, the check always fails, resulting in the experimental coroutine always being included. This results in compilation errors when it is not included in the header files for c++20. So a reasonable approach is needed to ensure that the right coroutine header, when present, is selected. Proposed Solution: - Within the if directive, check to determine if the current c++ version is 20 and above. This ensures that the flag `FOLLY_USE_STD_COROUTINE` is set if so, and folly uses the coroutines from the std library. Potential Issue: Not all c++20 toolchains might have coroutines (like bespoke embedded hardware compilers) - *Utilize the `LLVM_COROUTINES_CPP20` flag which would be set in the buckconfig to indicate that the toolchain supports c++20 coroutines. - Use either of the available coroutine feature macros `__cpp_impl_coroutine` or `__cpp_lib_coroutine` to check if coroutines are implemented in the standard library Reviewed By: Gownta Differential Revision: D68659268 fbshipit-source-id: 689570387c160bf71f362ceab23489c75d590e67 --- third-party/folly/src/folly/coro/Coroutine.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/third-party/folly/src/folly/coro/Coroutine.h b/third-party/folly/src/folly/coro/Coroutine.h index bbfdf4b4b6c..f15648a4989 100644 --- a/third-party/folly/src/folly/coro/Coroutine.h +++ b/third-party/folly/src/folly/coro/Coroutine.h @@ -30,8 +30,7 @@ // libc++'s header only provides its declarations for C++20 and // above, so we need to fall back to when building with // C++17. -#if __has_include() && !defined(LLVM_COROUTINES) && \ - (!defined(_LIBCPP_VERSION) || __cplusplus > 201703L) +#if (__has_include() && !defined(LLVM_COROUTINES)) || defined(__cpp_impl_coroutine) #define FOLLY_USE_STD_COROUTINE 1 #else #define FOLLY_USE_STD_COROUTINE 0 -- 2.11.4.GIT