sewenew / redis-plus-plus

Redis client written in C++
Apache License 2.0
1.64k stars 351 forks source link

[FEATURE] Coroutine support for Clang #485

Closed pbronneberg closed 1 year ago

pbronneberg commented 1 year ago

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 forclang. 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
pbronneberg commented 1 year ago

See PR #484 for a proposal fix

sewenew commented 1 year ago

PR has been merged. Thanks for your contribution!

Regards