Skip to content

Commit 0fb12d5

Browse files
Uche Ubafacebook-github-bot
Uche Uba
authored andcommitted
enabling <coroutine> 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 <coroutine> header which has been added to the std library in v20 as opposed to <experimental/coroutine> 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 <coroutine> (v20) or <experimental/coroutine> (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
1 parent fefe8e7 commit 0fb12d5

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

third-party/folly/src/folly/coro/Coroutine.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
// libc++'s <coroutine> header only provides its declarations for C++20 and
3131
// above, so we need to fall back to <experimental/coroutine> when building with
3232
// C++17.
33-
#if __has_include(<coroutine>) && !defined(LLVM_COROUTINES) && \
34-
(!defined(_LIBCPP_VERSION) || __cplusplus > 201703L)
33+
#if (__has_include(<coroutine>) && !defined(LLVM_COROUTINES)) || defined(__cpp_impl_coroutine)
3534
#define FOLLY_USE_STD_COROUTINE 1
3635
#else
3736
#define FOLLY_USE_STD_COROUTINE 0

0 commit comments

Comments
 (0)