8000 Merge pull request #1295 from AndreMiras/feature/various_recipes_upda… · crylearner/python-for-android@6905c2b · GitHub
[go: up one dir, main page]

Skip to content

Commit 6905c2b

Browse files
authored
Merge pull request kivy#1295 from AndreMiras/feature/various_recipes_update_python3
Recipes updates with CrystaX/Python3 support
2 parents 15c032a + ccd5b59 commit 6905c2b

File tree

10 files changed

+96
-37
lines changed

10 files changed

+96
-37
lines changed

pythonforandroid/recipes/cffi/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from pythonforandroid.recipe import CompiledComponentsPythonRecipe
23

34

@@ -15,15 +16,32 @@ class CffiRecipe(CompiledComponentsPythonRecipe):
1516

1617
def get_recipe_env(self, arch=None):
1718
env = super(CffiRecipe, self).get_recipe_env(arch)
19+
# sets linker to use the correct gcc (cross compiler)
20+
env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
1821
libffi = self.get_recipe('libffi', self.ctx)
1922
includes = libffi.get_include_dirs(arch)
2023
env['CFLAGS'] = ' -I'.join([env.get('CFLAGS', '')] + includes)
2124
env['LDFLAGS'] = (env.get('CFLAGS', '') + ' -L' +
2225
self.ctx.get_libs_dir(arch.arch))
26+
env['LDFLAGS'] += ' -L{}'.format(os.path.join(self.ctx.bootstrap.build_dir, 'libs', arch.arch))
27+
# required for libc and libdl
28+
ndk_dir = self.ctx.ndk_platform
29+
ndk_lib_dir = os.path.join(ndk_dir, 'usr', 'lib')
30+
env['LDFLAGS'] += ' -L{}'.format(ndk_lib_dir)
31+
env['LDFLAGS'] += " --sysroot={}".format(self.ctx.ndk_platform)
2332
env['PYTHONPATH'] = ':'.join([
2433
self.ctx.get_site_packages_dir(),
2534
env['BUILDLIB_PATH'],
2635
])
36+
if self.ctx.ndk == 'crystax':
37+
# only keeps major.minor (discards patch)
38+
python_version = self.ctx.python_recipe.version[0:3]
39+
ndk_dir_python = os.path.join(self.ctx.ndk_dir, 'sources/python/', python_version)
40+
env['LDFLAGS'] += ' -L{}'.format(os.path.join(ndk_dir_python, 'libs', arch.arch))
41+
env['LDFLAGS'] += ' -lpython{}m'.format(python_version)
42+
# until `pythonforandroid/archs.py` gets merged upstream:
43+
# https://github.com/kivy/python-for-android/pull/1250/files#diff-569e13021e33ced8b54385f55b49cbe6
44+
env['CFLAGS'] += ' -I{}/include/python/'.format(ndk_dir_python)
2745
return env
2846

2947

pythonforandroid/recipes/decorator/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33

44
class DecoratorPyRecipe(PythonRecipe):
5-
version = '4.0.9'
5+
version = '4.2.1'
66
url = 'https://pypi.python.org/packages/source/d/decorator/decorator-{version}.tar.gz'
7-
depends = ['hostpython2', 'setuptools']
7+
url = 'https://github.com/micheles/decorator/archive/{version}.tar.gz'
8+
depends = [('python2', 'python3crystax'), 'setuptools']
89
site_packages_name = 'decorator'
910
call_hostpython_via_targetpython = False
1011

pythonforandroid/recipes/idna/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
class IdnaRecipe(PythonRecipe):
55
name = 'idna'
6-
version = '2.0'
7-
url = 'https://pypi.python.org/packages/source/i/idna/idna-{version}.tar.gz'
6+
version = '2.6'
7+
url = 'https://github.com/kjd/idna/archive/v{version}.tar.gz'
88

99
depends = [('python2', 'python3crystax'), 'setuptools']
1010

pythonforandroid/recipes/pycryptodome/__init__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22

33

44
class PycryptodomeRecipe(PythonRecipe):
5-
version = 'v3.4.6'
6-
url = 'https://github.com/Legrandin/pycryptodome/archive/{version}.tar.gz'
5+
version = '3.4.6'
6+
url = 'https://github.com/Legrandin/pycryptodome/archive/v{version}.tar.gz'
7+
depends = [('python2', 'python3crystax'), 'setuptools', 'cffi']
78

8-
depends = ['python2', 'setuptools', 'cffi']
9+
def get_recipe_env(self, arch=None, with_flags_in_cc=True):
10+
env = super(PycryptodomeRecipe, self).get_recipe_env(arch, with_flags_in_cc)
11+
# sets linker to use the correct gcc (cross compiler)
12+
env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
13+
return env
914

1015

1116
recipe = PycryptodomeRecipe()
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
1+
import os
12
from pythonforandroid.recipe import PythonRecipe
23

34

5+
# TODO: CompiledComponentsPythonRecipe
46
class Pysha3Recipe(PythonRecipe):
57
version = '1.0.2'
68
url = 'https://github.com/tiran/pysha3/archive/{version}.tar.gz'
9+
depends = [('python2', 'python3crystax'), 'setuptools']
710

8-
depends = ['python2', 'setuptools']
11+
def get_recipe_env(self, arch=None, with_flags_in_cc=True):
12+
env = super(Pysha3Recipe, self).get_recipe_env(arch, with_flags_in_cc)
13+
# sets linker to use the correct gcc (cross compiler)
14+
env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
15+
# CFLAGS may only be used to specify C compiler flags, for macro definitions use CPPFLAGS
16+
env['CPPFLAGS'] = env['CFLAGS'] + ' -I{}/sources/python/3.5/include/python/'.format(self.ctx.ndk_dir)
17+
env['CFLAGS'] = ''
18+
# LDFLAGS may only be used to specify linker flags, for libraries use LIBS
19+
env['LDFLAGS'] = env['LDFLAGS'].replace('-lm', '').replace('-lcrystax', '')
20+
env['LDFLAGS'] += ' -L{}'.format(os.path.join(self.ctx.bootstrap.build_dir, 'libs', arch.arch))
21+
env['LIBS'] = ' -lm'
22+
if self.ctx.ndk == 'crystax':
23+
env['LIBS'] += ' -lcrystax -lpython{}m'.format(self.ctx.python_recipe.version[0:3])
24+
env['LDSHARED'] += env['LIBS']
25+
return env
926

1027

1128
recipe = Pysha3Recipe()

pythonforandroid/recipes/pyyaml/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33

44
class PyYamlRecipe(PythonRecipe):
5-
version = "3.11"
5+
version = "3.12"
66
url = 'http://pyyaml.org/download/pyyaml/PyYAML-{version}.tar.gz'
77
depends = [('python2', 'python3crystax'), "setuptools"]
88
site_packages_name = 'pyyaml'
9-
call_hostpython_via_targetpython = False
109

1110

1211
recipe = PyYamlRecipe()

pythonforandroid/recipes/requests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class RequestsRecipe(PythonRecipe):
55
version = '2.13.0'
66
url = 'https://github.com/kennethreitz/requests/archive/v{version}.tar.gz'
7-
depends = ['hostpython2', 'setuptools']
7+
depends = [('hostpython2', 'hostpython3crystax'), 'setuptools']
88
site_packages_name = 'requests'
99
call_hostpython_via_targetpython = False
1010

pythonforandroid/recipes/scrypt/__init__.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1+
import os
12
from pythonforandroid.recipe import CythonRecipe
2-
from os.path import join
33

44

55
class ScryptRecipe(CythonRecipe):
66

7-
url = 'https://bitbucket.org/mhallin/py-scrypt/get/default.zip'
8-
9-
depends = ['python2', 'setuptools', 'openssl']
10-
7+
version = '0.8.6'
8+
url = 'https://bitbucket.org/mhallin/py-scrypt/get/v{version}.zip'
9+
depends = [('python2', 'python3crystax'), 'setuptools', 'openssl']
1110
call_hostpython_via_targetpython = False
12-
1311
patches = ["remove_librt.patch"]
1412

1513
def get_recipe_env(self, arch, with_flags_in_cc=True):
@@ -19,12 +17,21 @@ def get_recipe_env(self, arch, with_flags_in_cc=True):
1917
env = super(ScryptRecipe, self).get_recipe_env(arch, with_flags_in_cc)
2018
openssl_build_dir = self.get_recipe(
2119
'openssl', self.ctx).get_build_dir(arch.arch)
22-
print("openssl_build_dir:", openssl_build_dir)
23-
env['CC'] = '%s -I%s' % (env['CC'], join(openssl_build_dir, 'include'))
24-
env['LDFLAGS'] = env['LDFLAGS'] + ' -L{}'.format(
20+
env['CFLAGS'] += ' -I{}'.format(os.path.join(openssl_build_dir, 'include'))
21+
env['LDFLAGS'] += ' -L{}'.format(
2522
self.ctx.get_libs_dir(arch.arch) +
2623
'-L{}'.format(self.ctx.libs_dir)) + ' -L{}'.format(
2724
openssl_build_dir)
25+
# required additional library and path for Crystax
26+
if self.ctx.ndk == 'crystax':
27+
# only keeps major.minor (discards patch)
28+
python_version = self.ctx.python_recipe.version[0:3]
29+
ndk_dir_python = os.path.join(self.ctx.ndk_dir, 'sources/python/', python_version)
30+
env['LDFLAGS'] += ' -L{}'.format(os.path.join(ndk_dir_python, 'libs', arch.arch))
31+
env['LDFLAGS'] += ' -lpython{}m'.format(python_version)
32+
# until `pythonforandroid/archs.py` gets merged upstream:
33+
# https://github.com/kivy/python-for-android/pull/1250/files#diff-569e13021e33ced8b54385f55b49cbe6
34+
env['CFLAGS'] += ' -I{}/include/python/'.format(ndk_dir_python)
2835
return env
2936

3037

pythonforandroid/recipes/scrypt/remove_librt.patch

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
diff -r 91d194b6a6bd setup.py
2-
--- a/setup.py Sat Sep 17 15:29:49 2016 +0200
3-
+++ b/setup.py Mon May 29 07:30:24 2017 +0000
4-
@@ -13,7 +13,6 @@
1+
--- a/setup.py 2018-05-06 23:25:08.757522119 +0200
2+
+++ b/setup.py 2018-05-06 23:25:30.269797365 +0200
3+
@@ -15,7 +15,6 @@
54

65
if sys.platform.startswith('linux'):
76
define_macros = [('HAVE_CLOCK_GETTIME', '1'),
87
- ('HAVE_LIBRT', '1'),
98
('HAVE_POSIX_MEMALIGN', '1'),
109
('HAVE_STRUCT_SYSINFO', '1'),
1110
('HAVE_STRUCT_SYSINFO_MEM_UNIT', '1'),
12-
@@ -21,7 +20,7 @@
11+
@@ -23,8 +22,7 @@
1312
('HAVE_SYSINFO', '1'),
1413
('HAVE_SYS_SYSINFO_H', '1'),
1514
('_FILE_OFFSET_BITS', '64')]
1615
- libraries = ['crypto', 'rt']
16+
- includes = ['/usr/local/include', '/usr/include']
1717
+ libraries = ['crypto']
1818
CFLAGS.append('-O2')
1919
elif sys.platform.startswith('win32'):

pythonforandroid/recipes/secp256k1/__init__.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from os.path import join
1+
import os
22
from pythonforandroid.recipe import PythonRecipe
33

44

@@ -9,25 +9,37 @@ class Secp256k1Recipe(PythonRecipe):
99
call_hostpython_via_targetpython = False
1010

1111
depends = [
12-
'openssl', 'hostpython2', 'python2', 'setuptools',
13-
'libffi', 'cffi', 'libffi', 'libsecp256k1']
12+
'openssl', ('hostpython2', 'hostpython3crystax'),
13+
('python2', 'python3crystax'), 'setuptools',
14+
'libffi', 'cffi', 'libsecp256k1']
1415

1516
patches = [
1617
"cross_compile.patch", "drop_setup_requires.patch",
1718
"pkg-config.patch", "find_lib.patch", "no-download.patch"]
1819

19-
def get_recipe_env(self, arch=None):
20-
env = super(Secp256k1Recipe, self).get_recipe_env(arch)
20+
def get_recipe_env(self, arch=None, with_flags_in_cc=True):
21+
env = super(Secp256k1Recipe, self).get_recipe_env(arch, with_flags_in_cc)
22+
# sets linker to use the correct gcc (cross compiler)
23+
env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
2124
libsecp256k1 = self.get_recipe('libsecp256k1', self.ctx)
2225
libsecp256k1_dir = libsecp256k1.get_build_dir(arch.arch)
23-
env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
24-
env['CFLAGS'] = ' -I' + join(libsecp256k1_dir, 'include')
25-
env['CFLAGS'] += ' -I' + env['PYTHON_ROOT'] + '/include/python2.7'
26-
env['LDSHARED'] = env['CC'] + \
27-
' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
2826
env['LDFLAGS'] += ' -L{}'.format(libsecp256k1_dir)
29-
# TODO: hardcoded Python version
30-
env['LDFLAGS'] += " -landroid -lpython2.7 -lsecp256k1"
27+
env['CFLAGS'] = ' -I' + os.path.join(libsecp256k1_dir, 'include')
28+
# only keeps major.minor (discards patch)
29+
python_version = self.ctx.python_recipe.version[0:3]
30+
# required additional library and path for Crystax
31+
if self.ctx.ndk == 'crystax':
32+
ndk_dir_python = os.path.join(self.ctx.ndk_dir, 'sources/python/', python_version)
33+
env['LDFLAGS'] += ' -L{}'.format(os.path.join(ndk_dir_python, 'libs', arch.arch))
34+
env['LDFLAGS'] += ' -lpython{}m'.format(python_version)
35+
# until `pythonforandroid/archs.py` gets merged upstream:
36+
# https://github.com/kivy/python-for-android/pull/1250/files#diff-569e13021e33ced8b54385f55b49cbe6
37+
env['CFLAGS'] += ' -I{}/include/python/'.format(ndk_dir_python)
38+
else:
39+
env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
40+
env['CFLAGS'] += ' -I' + env['PYTHON_ROOT'] + '/include/python{}'.format(python_version)
41+
env['LDFLAGS'] += " -lpython{}".format(python_version)
42+
env['LDFLAGS'] += " -lsecp256k1"
3143
return env
3244

3345

0 commit comments

Comments
 (0)
0