[FEATURE] Coroutine support for Clang
pbronneberg opened this issue · 2 comments
Is your feature request related to a problem? Please describe.
It's great to see that coroutine support is added to redis-plus-plus. For my project, I would like to start using this as alternative to async redis.
When using clang
from a debian
devcontainer, I encounter build errors on #include <coroutine>
in co_redis.h
& co_redis_cluster. This is to be expected, since co-routines are still considered experimental for
clang. Adapting the include to
#include <experimental/coroutine>` solves the build issue.
CMAKE settings used:
SET(REDIS_PLUS_PLUS_CXX_STANDARD 20)
SET(REDIS_PLUS_PLUS_BUILD_ASYNC libuv)
SET(REDIS_PLUS_PLUS_ASYNC_FUTURE std)
OPTION(REDIS_PLUS_PLUS_BUILD_TEST "Build tests for redis++" OFF)
OPTION(REDIS_PLUS_PLUS_BUILD_SHARED "Build shared library" OFF)
OPTION(REDIS_PLUS_PLUS_BUILD_STATIC "Build static library" ON)
OPTION(REDIS_PLUS_PLUS_BUILD_CORO "Build co-routines" ON)
Describe the solution you'd like
Please support Redis++ coroutines for clang
Describe alternatives you've considered
Switching compilers is of course an option, but for other reasons we are defaulting to clang
Additional context
A fix that supports both clang
and gcc
:
Replace #include <coroutine>
by
#if __has_include(<coroutine>)
# include <coroutine>
#elif __has_include(<experimental/coroutine>)
# include <experimental/coroutine>
# ifndef coroutine_handle
# define coroutine_handle experimental::coroutine_handle
# endif
# ifndef suspend_never
# define suspend_never experimental::suspend_never
# endif
#else
# error "<coroutine> not found."
#endif
See PR #484 for a proposal fix
PR has been merged. Thanks for your contribution!
Regards