From 9b27187337d0174084baaf28cf61836474364003 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Mon, 16 Sep 2024 10:04:07 -0700 Subject: [PATCH] Enable vsock support for Android The existing code fails to enable vsock on Android because it tries to enable vsock on Android when: a) a certain Linux version is detected b) and a certain libc is present. For a), it requires that `` is included. For b), Android does not use glibc. Instead `AF_VSOCK` is included since NDK version 14. This commit fixes both issues by including the needed Linux header and detecting the `__NDK_MAJOR__` version. For context, AOSP, has it always enabled: https://android.googlesource.com/platform/external/grpc-grpc/+/06fb97455fd5336cebfa9a1eb44d4fac6d054608%5E%21/src/core/lib/iomgr/port.h But this patch compiles with older NDK version and/or older Linux versions, in case someone is still using them. --- include/grpc/support/port_platform.h | 6 ++++++ src/core/lib/iomgr/port.h | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/grpc/support/port_platform.h b/include/grpc/support/port_platform.h index 8f0d1fa933c..04a79ef3c85 100644 --- a/include/grpc/support/port_platform.h +++ b/include/grpc/support/port_platform.h @@ -194,6 +194,12 @@ #define GPR_HAS_PTHREAD_H 1 #define GPR_GETPID_IN_UNISTD_H 1 #define GPR_SUPPORT_CHANNELS_FROM_FD 1 +#if defined(__has_include) +#if __has_include() +#include +#endif /* __has_include() */ +#endif /* defined(__has_include) */ +#include #elif defined(__linux__) #define GPR_PLATFORM_STRING "linux" #ifndef _BSD_SOURCE diff --git a/src/core/lib/iomgr/port.h b/src/core/lib/iomgr/port.h index f4102a524a2..4899e173464 100644 --- a/src/core/lib/iomgr/port.h +++ b/src/core/lib/iomgr/port.h @@ -40,8 +40,8 @@ #define GRPC_HAVE_IP_PKTINFO 1 #define GRPC_HAVE_MSG_NOSIGNAL 1 #define GRPC_HAVE_UNIX_SOCKET 1 -#if defined(LINUX_VERSION_CODE) && defined(__GLIBC_PREREQ) -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0) && __GLIBC_PREREQ(2, 18) +#if defined(LINUX_VERSION_CODE) && defined(__NDK_MAJOR__) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0) && __NDK_MAJOR__ >= 14 #define GRPC_HAVE_VSOCK 1 #endif #endif