Skip to content

Commit bbc4021

Browse files
authored
Merge pull request #3023 from kengoon/grpcio-recipe
recipes: add new `grpcio` recipe
2 parents fbb40ec + 8c931ed commit bbc4021

File tree

4 files changed

+102
-0
lines changed

4 files changed

+102
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from pythonforandroid.recipe import PyProjectRecipe, Recipe
2+
3+
4+
class GrpcioRecipe(PyProjectRecipe):
5+
version = '1.64.0'
6+
url = 'https://files.pythonhosted.org/packages/source/g/grpcio/grpcio-{version}.tar.gz'
7+
depends = ["setuptools", "librt", "libpthread"]
8+
patches = [
9+
"comment-getserverbyport-r-args.patch",
10+
"remove-android-log-write.patch",
11+
"use-ndk-zlib-and-openssl-recipe-include.patch"
12+
]
13+
14+
def get_recipe_env(self, arch, **kwargs):
15+
env = super().get_recipe_env(arch, **kwargs)
16+
env["NDKPLATFORM"] = "NOTNONE"
17+
env["GRPC_PYTHON_BUILD_SYSTEM_OPENSSL"] = "1"
18+
env["GRPC_PYTHON_BUILD_SYSTEM_ZLIB"] = "1"
19+
env["ZLIB_INCLUDE"] = self.ctx.ndk.sysroot_include_dir
20+
# replace -I with a space
21+
openssl_recipe = Recipe.get_recipe('openssl', self.ctx)
22+
env["SSL_INCLUDE"] = openssl_recipe.include_flags(arch).strip().replace("-I", "")
23+
env["CFLAGS"] += " -U__ANDROID_API__"
24+
env["CFLAGS"] += " -D__ANDROID_API__={}".format(self.ctx.ndk_api)
25+
# turn off c++11 warning error of "invalid suffix on literal"
26+
env["CFLAGS"] += " -Wno-reserved-user-defined-literal"
27+
env["PLATFORM"] = "android"
28+
env["LDFLAGS"] += " -llog -landroid"
29+
env["LDFLAGS"] += openssl_recipe.link_flags(arch)
30+
return env
31+
32+
33+
recipe = GrpcioRecipe()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Index: ares_config.h
2+
IDEA additional info:
3+
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
4+
<+>UTF-8
5+
===================================================================
6+
diff --git a/third_party/cares/config_android/ares_config.h b/third_party/cares/config_android/ares_config.h
7+
--- a/third_party/cares/config_android/ares_config.h
8+
+++ b/third_party/cares/config_android/ares_config.h (date 1716777985227)
9+
@@ -43,7 +43,7 @@
10+
#define GETNAMEINFO_TYPE_ARG7 int
11+
12+
/* Specifies the number of arguments to getservbyport_r */
13+
-#define GETSERVBYPORT_R_ARGS
14+
+//#define GETSERVBYPORT_R_ARGS
15+
16+
/* Define to 1 if you have AF_INET6. */
17+
#define HAVE_AF_INET6
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Index: log.cc
2+
IDEA additional info:
3+
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
4+
<+>UTF-8
5+
===================================================================
6+
diff --git a/src/core/lib/gpr/android/log.cc b/src/core/lib/gpr/android/log.cc
7+
--- a/src/core/lib/gpr/android/log.cc
8+
+++ b/src/core/lib/gpr/android/log.cc (date 1716778822204)
9+
@@ -30,18 +30,6 @@
10+
11+
#include "src/core/lib/gprpp/crash.h"
12+
13+
-static android_LogPriority severity_to_log_priority(gpr_log_severity severity) {
14+
- switch (severity) {
15+
- case GPR_LOG_SEVERITY_DEBUG:
16+
- return ANDROID_LOG_DEBUG;
17+
- case GPR_LOG_SEVERITY_INFO:
18+
- return ANDROID_LOG_INFO;
19+
- case GPR_LOG_SEVERITY_ERROR:
20+
- return ANDROID_LOG_ERROR;
21+
- }
22+
- return ANDROID_LOG_DEFAULT;
23+
-}
24+
-
25+
void gpr_log(const char* file, int line, gpr_log_severity severity,
26+
const char* format, ...) {
27+
// Avoid message construction if gpr_log_message won't log
28+
@@ -70,8 +58,6 @@
29+
30+
asprintf(&output, "%s:%d] %s", display_file, args->line, args->message);
31+
32+
- __android_log_write(severity_to_log_priority(args->severity), "GRPC", output);
33+
-
34+
// allocated by asprintf => use free, not gpr_free
35+
free(output);
36+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--- a/setup.py 2024-05-31 11:20:56.824695569 +0100
2+
+++ b/setup.py 2024-05-31 23:13:40.324392463 +0100
3+
@@ -299,11 +299,11 @@
4+
lambda x: "third_party/boringssl" not in x, CORE_C_FILES
5+
)
6+
CORE_C_FILES = filter(lambda x: "src/boringssl" not in x, CORE_C_FILES)
7+
- SSL_INCLUDE = (os.path.join("/usr", "include", "openssl"),)
8+
+ SSL_INCLUDE = tuple(os.environ["SSL_INCLUDE"].split(" "))
9+
10+
if BUILD_WITH_SYSTEM_ZLIB:
11+
CORE_C_FILES = filter(lambda x: "third_party/zlib" not in x, CORE_C_FILES)
12+
- ZLIB_INCLUDE = (os.path.join("/usr", "include"),)
13+
+ ZLIB_INCLUDE = tuple(os.environ["ZLIB_INCLUDE"].split(" "))
14+
15+
if BUILD_WITH_SYSTEM_CARES:
16+
CORE_C_FILES = filter(lambda x: "third_party/cares" not in x, CORE_C_FILES)

0 commit comments

Comments
 (0)