From f0e68762d6dd991786808b81b7855d1946af5d3c Mon Sep 17 00:00:00 2001 From: Kenechukwu Akubue Date: Tue, 28 May 2024 12:18:39 +0100 Subject: [PATCH 1/5] Add grpcio recipe --- pythonforandroid/recipes/grpcio/__init__.py | 46 +++++++++++++++++++ .../comment-getserverbyport-r-args.patch | 17 +++++++ .../grpcio/remove-android-log-write.patch | 36 +++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 pythonforandroid/recipes/grpcio/__init__.py create mode 100644 pythonforandroid/recipes/grpcio/comment-getserverbyport-r-args.patch create mode 100644 pythonforandroid/recipes/grpcio/remove-android-log-write.patch diff --git a/pythonforandroid/recipes/grpcio/__init__.py b/pythonforandroid/recipes/grpcio/__init__.py new file mode 100644 index 000000000..4276f52e4 --- /dev/null +++ b/pythonforandroid/recipes/grpcio/__init__.py @@ -0,0 +1,46 @@ +import glob +from logging import info + +import sh +from pythonforandroid.logger import shprint +from pythonforandroid.recipe import CppCompiledComponentsPythonRecipe +from pythonforandroid.util import current_directory + + +class GrpcioRecipe(CppCompiledComponentsPythonRecipe): + version = '1.64.0' + url = 'https://files.pythonhosted.org/packages/source/g/grpcio/grpcio-{version}.tar.gz' + depends = ["setuptools", "librt", "libpthread"] + patches = ["comment-getserverbyport-r-args.patch", "remove-android-log-write.patch"] + + def get_recipe_env(self, arch, **kwargs): + env = super().get_recipe_env(arch, **kwargs) + env['NDKPLATFORM'] = "NOTNONE" + env['GRPC_PYTHON_BUILD_WITH_CYTHON'] = '1' + env["CFLAGS"] += " -U__ANDROID_API__" + env["CFLAGS"] += " -D__ANDROID_API__={}".format(self.ctx.ndk_api) + + # turn off c++11 warning error of "invalid suffix on literal" + env["CFLAGS"] += " -Wno-reserved-user-defined-literal" + env['PLATFORM'] = 'android' + env["LDFLAGS"] += " -llog -landroid" + return env + + def build_compiled_components(self, arch): + info('Building compiled components in {}'.format(self.name)) + + env = self.get_recipe_env(arch) + hostpython = sh.Command(self.hostpython_location) + with current_directory(self.get_build_dir(arch.arch)): + if self.install_in_hostpython: + shprint(hostpython, 'setup.py', 'clean', '--all', _env=env) + shprint(hostpython, 'setup.py', self.build_cmd, '-v', + _env=env, *self.setup_extra_args) + + # grpcio creates a build directory and names it `pyb` + build_dir = glob.glob('pyb/lib.*')[0] + shprint(sh.find, build_dir, '-name', '"*.o"', '-exec', + env['STRIP'], '{}', ';', _env=env) + + +recipe = GrpcioRecipe() diff --git a/pythonforandroid/recipes/grpcio/comment-getserverbyport-r-args.patch b/pythonforandroid/recipes/grpcio/comment-getserverbyport-r-args.patch new file mode 100644 index 000000000..6d64105d7 --- /dev/null +++ b/pythonforandroid/recipes/grpcio/comment-getserverbyport-r-args.patch @@ -0,0 +1,17 @@ +Index: ares_config.h +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +diff --git a/third_party/cares/config_android/ares_config.h b/third_party/cares/config_android/ares_config.h +--- a/third_party/cares/config_android/ares_config.h ++++ b/third_party/cares/config_android/ares_config.h (date 1716777985227) +@@ -43,7 +43,7 @@ + #define GETNAMEINFO_TYPE_ARG7 int + + /* Specifies the number of arguments to getservbyport_r */ +-#define GETSERVBYPORT_R_ARGS ++//#define GETSERVBYPORT_R_ARGS + + /* Define to 1 if you have AF_INET6. */ + #define HAVE_AF_INET6 diff --git a/pythonforandroid/recipes/grpcio/remove-android-log-write.patch b/pythonforandroid/recipes/grpcio/remove-android-log-write.patch new file mode 100644 index 000000000..b032c65a0 --- /dev/null +++ b/pythonforandroid/recipes/grpcio/remove-android-log-write.patch @@ -0,0 +1,36 @@ +Index: log.cc +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +diff --git a/src/core/lib/gpr/android/log.cc b/src/core/lib/gpr/android/log.cc +--- a/src/core/lib/gpr/android/log.cc ++++ b/src/core/lib/gpr/android/log.cc (date 1716778822204) +@@ -30,18 +30,6 @@ + + #include "src/core/lib/gprpp/crash.h" + +-static android_LogPriority severity_to_log_priority(gpr_log_severity severity) { +- switch (severity) { +- case GPR_LOG_SEVERITY_DEBUG: +- return ANDROID_LOG_DEBUG; +- case GPR_LOG_SEVERITY_INFO: +- return ANDROID_LOG_INFO; +- case GPR_LOG_SEVERITY_ERROR: +- return ANDROID_LOG_ERROR; +- } +- return ANDROID_LOG_DEFAULT; +-} +- + void gpr_log(const char* file, int line, gpr_log_severity severity, + const char* format, ...) { + // Avoid message construction if gpr_log_message won't log +@@ -70,8 +58,6 @@ + + asprintf(&output, "%s:%d] %s", display_file, args->line, args->message); + +- __android_log_write(severity_to_log_priority(args->severity), "GRPC", output); +- + // allocated by asprintf => use free, not gpr_free + free(output); + } From b9341ef9f171bd11bc2ca62c849290f960293250 Mon Sep 17 00:00:00 2001 From: Kenechukwu Akubue Date: Fri, 31 May 2024 23:21:14 +0100 Subject: [PATCH 2/5] Migrate to PyProjectRecipe --- pythonforandroid/recipes/grpcio/__init__.py | 38 +++++-------------- ...-ndk-zlib-and-openssl-recipe-include.patch | 16 ++++++++ 2 files changed, 26 insertions(+), 28 deletions(-) create mode 100644 pythonforandroid/recipes/grpcio/use-ndk-zlib-and-openssl-recipe-include.patch diff --git a/pythonforandroid/recipes/grpcio/__init__.py b/pythonforandroid/recipes/grpcio/__init__.py index 4276f52e4..3a442f629 100644 --- a/pythonforandroid/recipes/grpcio/__init__.py +++ b/pythonforandroid/recipes/grpcio/__init__.py @@ -1,13 +1,7 @@ -import glob -from logging import info +from pythonforandroid.recipe import PyProjectRecipe, Recipe -import sh -from pythonforandroid.logger import shprint -from pythonforandroid.recipe import CppCompiledComponentsPythonRecipe -from pythonforandroid.util import current_directory - -class GrpcioRecipe(CppCompiledComponentsPythonRecipe): +class GrpcioRecipe(PyProjectRecipe): version = '1.64.0' url = 'https://files.pythonhosted.org/packages/source/g/grpcio/grpcio-{version}.tar.gz' depends = ["setuptools", "librt", "libpthread"] @@ -15,32 +9,20 @@ class GrpcioRecipe(CppCompiledComponentsPythonRecipe): def get_recipe_env(self, arch, **kwargs): env = super().get_recipe_env(arch, **kwargs) - env['NDKPLATFORM'] = "NOTNONE" - env['GRPC_PYTHON_BUILD_WITH_CYTHON'] = '1' + env["NDKPLATFORM"] = "NOTNONE" + env["GRPC_PYTHON_BUILD_SYSTEM_OPENSSL"] = "1" + env["GRPC_PYTHON_BUILD_SYSTEM_ZLIB"] = "1" + env["ZLIB_INCLUDE"] = self.ctx.ndk.sysroot_include_dir + # replace -I with a space + openssl_recipe = Recipe.get_recipe('openssl', self.ctx) + env["SSL_INCLUDE"] = openssl_recipe.include_flags(arch).strip().replace("-I", "") env["CFLAGS"] += " -U__ANDROID_API__" env["CFLAGS"] += " -D__ANDROID_API__={}".format(self.ctx.ndk_api) - # turn off c++11 warning error of "invalid suffix on literal" env["CFLAGS"] += " -Wno-reserved-user-defined-literal" - env['PLATFORM'] = 'android' + env["PLATFORM"] = "android" env["LDFLAGS"] += " -llog -landroid" return env - def build_compiled_components(self, arch): - info('Building compiled components in {}'.format(self.name)) - - env = self.get_recipe_env(arch) - hostpython = sh.Command(self.hostpython_location) - with current_directory(self.get_build_dir(arch.arch)): - if self.install_in_hostpython: - shprint(hostpython, 'setup.py', 'clean', '--all', _env=env) - shprint(hostpython, 'setup.py', self.build_cmd, '-v', - _env=env, *self.setup_extra_args) - - # grpcio creates a build directory and names it `pyb` - build_dir = glob.glob('pyb/lib.*')[0] - shprint(sh.find, build_dir, '-name', '"*.o"', '-exec', - env['STRIP'], '{}', ';', _env=env) - recipe = GrpcioRecipe() diff --git a/pythonforandroid/recipes/grpcio/use-ndk-zlib-and-openssl-recipe-include.patch b/pythonforandroid/recipes/grpcio/use-ndk-zlib-and-openssl-recipe-include.patch new file mode 100644 index 000000000..7810d5077 --- /dev/null +++ b/pythonforandroid/recipes/grpcio/use-ndk-zlib-and-openssl-recipe-include.patch @@ -0,0 +1,16 @@ +--- a/setup.py 2024-05-31 11:20:56.824695569 +0100 ++++ b/setup.py 2024-05-31 23:13:40.324392463 +0100 +@@ -299,11 +299,11 @@ + lambda x: "third_party/boringssl" not in x, CORE_C_FILES + ) + CORE_C_FILES = filter(lambda x: "src/boringssl" not in x, CORE_C_FILES) +- SSL_INCLUDE = (os.path.join("/usr", "include", "openssl"),) ++ SSL_INCLUDE = tuple(os.environ["SSL_INCLUDE"].split(" ")) + + if BUILD_WITH_SYSTEM_ZLIB: + CORE_C_FILES = filter(lambda x: "third_party/zlib" not in x, CORE_C_FILES) +- ZLIB_INCLUDE = (os.path.join("/usr", "include"),) ++ ZLIB_INCLUDE = tuple(os.environ["ZLIB_INCLUDE"].split(" ")) + + if BUILD_WITH_SYSTEM_CARES: + CORE_C_FILES = filter(lambda x: "third_party/cares" not in x, CORE_C_FILES) From 4b7500fcee090572b3d94428384083bdae57dce9 Mon Sep 17 00:00:00 2001 From: Kenechukwu Akubue Date: Sat, 1 Jun 2024 08:04:27 +0100 Subject: [PATCH 3/5] Add patch --- pythonforandroid/recipes/grpcio/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pythonforandroid/recipes/grpcio/__init__.py b/pythonforandroid/recipes/grpcio/__init__.py index 3a442f629..ceb0f6121 100644 --- a/pythonforandroid/recipes/grpcio/__init__.py +++ b/pythonforandroid/recipes/grpcio/__init__.py @@ -5,7 +5,7 @@ class GrpcioRecipe(PyProjectRecipe): version = '1.64.0' url = 'https://files.pythonhosted.org/packages/source/g/grpcio/grpcio-{version}.tar.gz' depends = ["setuptools", "librt", "libpthread"] - patches = ["comment-getserverbyport-r-args.patch", "remove-android-log-write.patch"] + patches = ["comment-getserverbyport-r-args.patch", "remove-android-log-write.patch", "use-ndk-zlib-and-openssl-recipe-include.patch"] def get_recipe_env(self, arch, **kwargs): env = super().get_recipe_env(arch, **kwargs) From 3a147350f05c23af056021ee8d3c04b72b06beca Mon Sep 17 00:00:00 2001 From: Kenechukwu Akubue Date: Sat, 1 Jun 2024 08:10:22 +0100 Subject: [PATCH 4/5] Update __init__.py --- pythonforandroid/recipes/grpcio/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pythonforandroid/recipes/grpcio/__init__.py b/pythonforandroid/recipes/grpcio/__init__.py index ceb0f6121..8e3b9cd7a 100644 --- a/pythonforandroid/recipes/grpcio/__init__.py +++ b/pythonforandroid/recipes/grpcio/__init__.py @@ -5,7 +5,11 @@ class GrpcioRecipe(PyProjectRecipe): version = '1.64.0' url = 'https://files.pythonhosted.org/packages/source/g/grpcio/grpcio-{version}.tar.gz' depends = ["setuptools", "librt", "libpthread"] - patches = ["comment-getserverbyport-r-args.patch", "remove-android-log-write.patch", "use-ndk-zlib-and-openssl-recipe-include.patch"] + patches = [ + "comment-getserverbyport-r-args.patch", + "remove-android-log-write.patch", + "use-ndk-zlib-and-openssl-recipe-include.patch" + ] def get_recipe_env(self, arch, **kwargs): env = super().get_recipe_env(arch, **kwargs) From 8c931ed4ddbcb20591e1551c193410e3094b9dcd Mon Sep 17 00:00:00 2001 From: Kenechukwu Akubue Date: Sat, 8 Jun 2024 00:49:44 +0100 Subject: [PATCH 5/5] Fix -lss, lcrypto linking bug --- pythonforandroid/recipes/grpcio/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pythonforandroid/recipes/grpcio/__init__.py b/pythonforandroid/recipes/grpcio/__init__.py index 8e3b9cd7a..3cf2437e3 100644 --- a/pythonforandroid/recipes/grpcio/__init__.py +++ b/pythonforandroid/recipes/grpcio/__init__.py @@ -26,6 +26,7 @@ def get_recipe_env(self, arch, **kwargs): env["CFLAGS"] += " -Wno-reserved-user-defined-literal" env["PLATFORM"] = "android" env["LDFLAGS"] += " -llog -landroid" + env["LDFLAGS"] += openssl_recipe.link_flags(arch) return env