Skip to content

Commit ee22544

Browse files
committed
Fix build of python's zlib module
Because python has a hardcoded zlib version which does not match android's ndk r19, and that prevents the build of zlib's module Note: it seems that we have to point to the right lib and headers, otherwise we wan't succeed in building python's zlib module
1 parent b913778 commit ee22544

File tree

6 files changed

+55
-14
lines changed

6 files changed

+55
-14
lines changed

pythonforandroid/python.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,33 @@ def add_flags(include_flags, link_dirs, link_libs):
183183
recipe = Recipe.get_recipe('openssl', self.ctx)
184184
add_flags(recipe.include_flags(arch),
185185
recipe.link_dirs_flags(arch), recipe.link_libs_flags())
186+
187+
# python build system contains hardcoded zlib version which prevents
188+
# the build of zlib module, here we search for android's zlib version
189+
# and sets the right flags, so python can be build with android's zlib
190+
info("Activating flags for android's zlib")
191+
zlib_lib_path = join(self.ctx.ndk_platform, 'usr', 'lib')
192+
zlib_includes = join(self.ctx.ndk_dir, 'sysroot', 'usr', 'include')
193+
zlib_h = join(zlib_includes, 'zlib.h')
194+
try:
195+
with open(zlib_h) as fileh:
196+
zlib_data = fileh.read()
197+
except IOError:
198+
raise BuildInterruptingException(
199+
"Could not determine android's zlib version, no zlib.h in "
200+
"the NDK dir includes"
201+
)
202+
for line in zlib_data.split('\n'):
203+
if line.startswith('#define ZLIB_VERSION '):
204+
break
205+
else:
206+
raise BuildInterruptingException(
207+
'Could not parse zlib.h...so we cannot find zlib version,'
208+
'required by python build,'
209+
)
210+
env['ZLIB_VERSION'] = line.replace('#define ZLIB_VERSION ', '')
211+
add_flags(' -I' + zlib_includes, ' -L' + zlib_lib_path, ' -lz')
212+
186213
return env
187214

188215
def prebuild_arch(self, arch):

pythonforandroid/recipes/python2/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class Python2Recipe(GuestPythonRecipe):
3131
'patches/fix-filesystem-default-encoding.patch',
3232
'patches/fix-gethostbyaddr.patch',
3333
'patches/fix-posix-declarations.patch',
34-
'patches/fix-pwd-gecos.patch']
34+
'patches/fix-pwd-gecos.patch',
35+
'patches/fix-zlib-version.patch']
3536

3637
configure_args = ('--host={android_host}',
3738
'--build={android_build}',

pythonforandroid/recipes/python2/patches/fix-missing-extensions.patch

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
diff -Naurp Python-2.7.15/Modules/Setup.dist.orig Python-2.7.15/Modules/Setup.dist
2-
--- Python-2.7.15/Modules/Setup.dist.orig 2018-04-30 00:47:33.000000000 +0200
3-
+++ Python-2.7.15/Modules/Setup.dist 2018-11-17 20:40:20.153518694 +0100
4-
@@ -464,7 +464,7 @@
5-
# Andrew Kuchling's zlib module.
6-
# This require zlib 1.1.3 (or later).
7-
# See http://www.gzip.org/zlib/
8-
-#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
9-
+zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
10-
11-
# Interface to the Expat XML parser
12-
#
131
diff -Naurp Python-2.7.15.orig/Makefile.pre.in Python-2.7.15/Makefile.pre.in
142
--- Python-2.7.15.orig/Makefile.pre.in 2018-04-30 00:47:33.000000000 +0200
153
+++ Python-2.7.15/Makefile.pre.in 2018-11-18 00:43:58.777379280 +0100
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--- Python-3.7.1/setup.py.orig 2018-10-20 08:04:19.000000000 +0200
2+
+++ Python-3.7.1/setup.py 2019-02-17 00:24:30.715904412 +0100
3+
@@ -1416,7 +1416,8 @@ class PyBuildExt(build_ext):
4+
if zlib_inc is not None:
5+
zlib_h = zlib_inc[0] + '/zlib.h'
6+
version = '"0.0.0"'
7+
- version_req = '"1.1.3"'
8+
+ version_req = '"{}"'.format(
9+
+ os.environ.get('ZLIB_VERSION', '1.1.3'))
10+
if host_platform == 'darwin' and is_macosx_sdk_path(zlib_h):
11+
zlib_h = os.path.join(macosx_sdk_root(), zlib_h[1:])
12+
with open(zlib_h) as fp:

pythonforandroid/recipes/python3/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class Python3Recipe(GuestPythonRecipe):
2222
url = 'https://www.python.org/ftp/python/{version}/Python-{version}.tgz'
2323
name = 'python3'
2424

25-
patches = ["patches/fix-ctypes-util-find-library.patch"]
25+
patches = ['patches/fix-ctypes-util-find-library.patch',
26+
'patches/fix-zlib-version.patch']
2627

2728
if sh.which('lld') is not None:
2829
patches = patches + ["patches/remove-fix-cortex-a8.patch"]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--- Python-3.7.1/setup.py.orig 2018-10-20 08:04:19.000000000 +0200
2+
+++ Python-3.7.1/setup.py 2019-02-17 00:24:30.715904412 +0100
3+
@@ -1410,7 +1410,8 @@ class PyBuildExt(build_ext):
4+
if zlib_inc is not None:
5+
zlib_h = zlib_inc[0] + '/zlib.h'
6+
version = '"0.0.0"'
7+
- version_req = '"1.1.3"'
8+
+ version_req = '"{}"'.format(
9+
+ os.environ.get('ZLIB_VERSION', '1.1.3'))
10+
if host_platform == 'darwin' and is_macosx_sdk_path(zlib_h):
11+
zlib_h = os.path.join(macosx_sdk_root(), zlib_h[1:])
12+
with open(zlib_h) as fp:

0 commit comments

Comments
 (0)