Skip to content

Commit c53ba8e

Browse files
kengoonjk
authored andcommitted
Add grpcio recipe
1 parent 96f22dd commit c53ba8e

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import glob
2+
from logging import info
3+
4+
import sh
5+
from pythonforandroid.logger import shprint
6+
from pythonforandroid.recipe import CppCompiledComponentsPythonRecipe
7+
from pythonforandroid.util import current_directory
8+
9+
10+
class GrpcioRecipe(CppCompiledComponentsPythonRecipe):
11+
version = '1.64.0'
12+
url = 'https://files.pythonhosted.org/packages/source/g/grpcio/grpcio-{version}.tar.gz'
13+
depends = ["setuptools", "librt", "libpthread"]
14+
patches = ["comment-getserverbyport-r-args.patch", "remove-android-log-write.patch"]
15+
16+
def get_recipe_env(self, arch, **kwargs):
17+
env = super().get_recipe_env(arch, **kwargs)
18+
env['NDKPLATFORM'] = "NOTNONE"
19+
env['GRPC_PYTHON_BUILD_WITH_CYTHON'] = '1'
20+
env["CFLAGS"] += " -U__ANDROID_API__"
21+
env["CFLAGS"] += " -D__ANDROID_API__={}".format(self.ctx.ndk_api)
22+
23+
# turn off c++11 warning error of "invalid suffix on literal"
24+
env["CFLAGS"] += " -Wno-reserved-user-defined-literal"
25+
env['PLATFORM'] = 'android'
26+
env["LDFLAGS"] += " -llog -landroid"
27+
return env
28+
29+
def build_compiled_components(self, arch):
30+
info('Building compiled components in {}'.format(self.name))
31+
32+
env = self.get_recipe_env(arch)
33+
hostpython = sh.Command(self.hostpython_location)
34+
with current_directory(self.get_build_dir(arch.arch)):
35+
if self.install_in_hostpython:
36+
shprint(hostpython, 'setup.py', 'clean', '--all', _env=env)
37+
shprint(hostpython, 'setup.py', self.build_cmd, '-v',
38+
_env=env, *self.setup_extra_args)
39+
40+
# grpcio creates a build directory and names it `pyb`
41+
build_dir = glob.glob('pyb/lib.*')[0]
42+
shprint(sh.find, build_dir, '-name', '"*.o"', '-exec',
43+
env['STRIP'], '{}', ';', _env=env)
44+
45+
46+
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+
}

0 commit comments

Comments
 (0)