From 4cfaa39e869a22e2d1e1d4e1189b90d0968c1826 Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Sun, 22 Mar 2020 21:43:01 +0100 Subject: [PATCH] Custom gevent recipe to fix broken arm64-v8a build Refs: https://github.com/kivy/python-for-android/pull/1722#issuecomment-524550920 --- .../recipes/gevent/__init__.py | 41 +++++++++++++++++++ .../recipes/gevent/cross_compiling.patch | 26 ++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 src/python-for-android/recipes/gevent/__init__.py create mode 100644 src/python-for-android/recipes/gevent/cross_compiling.patch diff --git a/src/python-for-android/recipes/gevent/__init__.py b/src/python-for-android/recipes/gevent/__init__.py new file mode 100644 index 0000000..3c42fde --- /dev/null +++ b/src/python-for-android/recipes/gevent/__init__.py @@ -0,0 +1,41 @@ +import re + +from pythonforandroid.logger import info +from pythonforandroid.recipe import CythonRecipe + + +class GeventRecipe(CythonRecipe): + version = '1.4.0' + url = ( + 'https://pypi.python.org/packages/source/g/gevent/' + 'gevent-{version}.tar.gz' + ) + depends = ['librt', 'greenlet'] + patches = ["cross_compiling.patch"] + + def get_recipe_env(self, arch=None, with_flags_in_cc=True): + """ + - Moves all -I -D from CFLAGS to CPPFLAGS environment. + - Moves all -l from LDFLAGS to LIBS environment. + - Copies all -l from LDLIBS to LIBS environment. + - Fixes linker name (use cross compiler) and flags (appends LIBS) + """ + env = super().get_recipe_env(arch, with_flags_in_cc) + # CFLAGS may only be used to specify C compiler flags, + # for macro definitions use CPPFLAGS + regex = re.compile(r'(?:\s|^)-[DI][\S]+') + env['CPPFLAGS'] = ''.join(re.findall(regex, env['CFLAGS'])).strip() + env['CFLAGS'] = re.sub(regex, '', env['CFLAGS']) + info('Moved "{}" from CFLAGS to CPPFLAGS.'.format(env['CPPFLAGS'])) + # LDFLAGS may only be used to specify linker flags, + # for libraries use LIBS + regex = re.compile(r'(?:\s|^)-l[\w\.]+') + env['LIBS'] = ''.join(re.findall(regex, env['LDFLAGS'])).strip() + env['LIBS'] += ' {}'.format( + ''.join(re.findall(regex, env['LDLIBS'])).strip()) + env['LDFLAGS'] = re.sub(regex, '', env['LDFLAGS']) + info('Moved "{}" from LDFLAGS to LIBS.'.format(env['LIBS'])) + return env + + +recipe = GeventRecipe() diff --git a/src/python-for-android/recipes/gevent/cross_compiling.patch b/src/python-for-android/recipes/gevent/cross_compiling.patch new file mode 100644 index 0000000..01e55d8 --- /dev/null +++ b/src/python-for-android/recipes/gevent/cross_compiling.patch @@ -0,0 +1,26 @@ +diff --git a/_setupares.py b/_setupares.py +index dd184de6..bb16bebe 100644 +--- a/_setupares.py ++++ b/_setupares.py +@@ -43,7 +43,7 @@ else: + ares_configure_command = ' '.join([ + "(cd ", quoted_dep_abspath('c-ares'), + " && if [ -r ares_build.h ]; then cp ares_build.h ares_build.h.orig; fi ", +- " && sh ./configure --disable-dependency-tracking " + _m32 + "CONFIG_COMMANDS= ", ++ " && sh ./configure --host={} --disable-dependency-tracking ".format(os.environ['TOOLCHAIN_PREFIX']) + _m32 + "CONFIG_COMMANDS= ", + " && cp ares_config.h ares_build.h \"$OLDPWD\" ", + " && cat ares_build.h ", + " && if [ -r ares_build.h.orig ]; then mv ares_build.h.orig ares_build.h; fi)", +diff --git a/_setuplibev.py b/_setuplibev.py +index 2a5841bf..b6433c94 100644 +--- a/_setuplibev.py ++++ b/_setuplibev.py +@@ -31,7 +31,7 @@ LIBEV_EMBED = should_embed('libev') + # and the PyPy branch will clean it up. + libev_configure_command = ' '.join([ + "(cd ", quoted_dep_abspath('libev'), +- " && sh ./configure ", ++ " && sh ./configure --host={} ".format(os.environ['TOOLCHAIN_PREFIX']), + " && cp config.h \"$OLDPWD\"", + ")", + '> configure-output.txt'