Skip to content

Commit b16d95b

Browse files
committed
Fix build of python's zlib module
Because we need that module to successfully run an android app and hopefully...will solve the `zip/unzip` issues reported in python-for-android's issues tracker
1 parent c5717ec commit b16d95b

File tree

6 files changed

+90
-17
lines changed

6 files changed

+90
-17
lines changed

pythonforandroid/python.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class GuestPythonRecipe(TargetPythonRecipe):
9292
'''The file extensions from site packages dir that we don't want to be
9393
included in our python bundle.'''
9494

95-
opt_depends = ['sqlite3', 'libffi', 'openssl']
95+
opt_depends = ['sqlite3', 'libffi', 'openssl', 'zlib']
9696
'''The optional libraries which we would like to get our python linked'''
9797

9898
compiled_extension = '.pyc'
@@ -164,6 +164,15 @@ def add_flags(include_flags, link_dirs, link_libs):
164164
recipe = Recipe.get_recipe('openssl', self.ctx)
165165
add_flags(recipe.include_flags(arch),
166166
recipe.link_dirs_flags(arch), recipe.link_libs_flags())
167+
168+
if 'zlib' in self.ctx.recipe_build_order:
169+
info('Activating flags for zlib')
170+
recipe = Recipe.get_recipe('zlib', self.ctx)
171+
add_flags(' -I' + recipe.get_build_dir(arch.arch),
172+
' -L' + recipe.get_build_dir(arch.arch),
173+
' -lz{}'.format(recipe.version_link))
174+
env['ZLIB_VERSION'] = recipe.version
175+
167176
return env
168177

169178
def prebuild_arch(self, arch):

pythonforandroid/recipes/python2/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Python2Recipe(GuestPythonRecipe):
2020
url = 'https://www.python.org/ftp/python/{version}/Python-{version}.tgz'
2121
name = 'python2'
2222

23-
depends = ['hostpython2']
23+
depends = ['hostpython2', 'zlib']
2424
conflicts = ['python3crystax', 'python3', 'python2legacy']
2525

2626
patches = [
@@ -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: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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:
13+
@@ -1428,13 +1429,13 @@ class PyBuildExt(build_ext):
14+
version = line.split()[2]
15+
break
16+
if version >= version_req:
17+
- if (self.compiler.find_library_file(lib_dirs, 'z')):
18+
+ if (self.compiler.find_library_file(lib_dirs, 'z' + os.environ.get('ZLIB_VERSION', '').replace('.', ''))):
19+
if host_platform == "darwin":
20+
zlib_extra_link_args = ('-Wl,-search_paths_first',)
21+
else:
22+
zlib_extra_link_args = ()
23+
exts.append( Extension('zlib', ['zlibmodule.c'],
24+
- libraries = ['z'],
25+
+ libraries = ['z' + os.environ.get('ZLIB_VERSION', '').replace('.', '')],
26+
extra_link_args = zlib_extra_link_args))
27+
have_zlib = True
28+
else:
29+
@@ -1448,7 +1449,7 @@ class PyBuildExt(build_ext):
30+
# crc32 if we have it. Otherwise binascii uses its own.
31+
if have_zlib:
32+
extra_compile_args = ['-DUSE_ZLIB_CRC32']
33+
- libraries = ['z']
34+
+ libraries = ['z' + os.environ.get('ZLIB_VERSION', '').replace('.', '')]
35+
extra_link_args = zlib_extra_link_args
36+
else:
37+
extra_compile_args = []

pythonforandroid/recipes/python3/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ class Python3Recipe(GuestPythonRecipe):
2121
url = 'https://www.python.org/ftp/python/{version}/Python-{version}.tgz'
2222
name = 'python3'
2323

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

26-
depends = ['hostpython3', 'sqlite3', 'openssl', 'libffi']
27+
depends = ['hostpython3', 'sqlite3', 'openssl', 'libffi', 'zlib']
2728
conflicts = ['python3crystax', 'python2', 'python2legacy']
2829

2930
configure_args = (
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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:
13+
@@ -1422,13 +1423,13 @@ class PyBuildExt(build_ext):
14+
version = line.split()[2]
15+
break
16+
if version >= version_req:
17+
- if (self.compiler.find_library_file(lib_dirs, 'z')):
18+
+ if (self.compiler.find_library_file(lib_dirs, 'z' + os.environ.get('ZLIB_VERSION', '').replace('.', ''))):
19+
if host_platform == "darwin":
20+
zlib_extra_link_args = ('-Wl,-search_paths_first',)
21+
else:
22+
zlib_extra_link_args = ()
23+
exts.append( Extension('zlib', ['zlibmodule.c'],
24+
- libraries = ['z'],
25+
+ libraries = ['z' + os.environ.get('ZLIB_VERSION', '').replace('.', '')],
26+
extra_link_args = zlib_extra_link_args))
27+
have_zlib = True
28+
else:
29+
@@ -1442,7 +1443,7 @@ class PyBuildExt(build_ext):
30+
# crc32 if we have it. Otherwise binascii uses its own.
31+
if have_zlib:
32+
extra_compile_args = ['-DUSE_ZLIB_CRC32']
33+
- libraries = ['z']
34+
+ libraries = ['z' + os.environ.get('ZLIB_VERSION', '').replace('.', '')]
35+
extra_link_args = zlib_extra_link_args
36+
else:
37+
extra_compile_args = []

0 commit comments

Comments
 (0)