Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recipes: add new grpcio recipe #3023

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions pythonforandroid/recipes/grpcio/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from pythonforandroid.recipe import PyProjectRecipe, Recipe


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"
]

def get_recipe_env(self, arch, **kwargs):
env = super().get_recipe_env(arch, **kwargs)
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["LDFLAGS"] += " -llog -landroid"
env["LDFLAGS"] += openssl_recipe.link_flags(arch)
return env


recipe = GrpcioRecipe()
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions pythonforandroid/recipes/grpcio/remove-android-log-write.patch
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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)
Loading