[Build] Enable vsock support for Android (#37733)

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 `<linux/version.h>` 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:
06fb97455f%5E%21/src/core/lib/iomgr/port.h

But this patch compiles with older NDK version, in case someone is still using them.

<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes #37733

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/37733 from ricardoquesadawork:android 9b27187337
PiperOrigin-RevId: 685868655
python/sync/typings
Ricardo Quesada 1 month ago committed by Copybara-Service
parent 7c766e2a72
commit ddfaa3402f
  1. 6
      include/grpc/support/port_platform.h
  2. 4
      src/core/lib/iomgr/port.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(<android/ndk-version.h>)
#include <android/ndk-version.h>
#endif /* __has_include(<android/ndk-version.h>) */
#endif /* defined(__has_include) */
#include <linux/version.h>
#elif defined(__linux__)
#define GPR_PLATFORM_STRING "linux"
#ifndef _BSD_SOURCE

@ -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

Loading…
Cancel
Save