Skip to content

[CORE UPDATE - PART IV] Fix cryptography+cffi #1545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions pythonforandroid/recipes/cffi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class CffiRecipe(CompiledComponentsPythonRecipe):
version = '1.11.5'
url = 'https://pypi.python.org/packages/source/c/cffi/cffi-{version}.tar.gz'

depends = [('python2', 'python3crystax'), 'setuptools', 'pycparser', 'libffi']
depends = ['setuptools', 'pycparser', 'libffi']

patches = ['disable-pkg-config.patch']

Expand All @@ -27,11 +27,10 @@ def get_hostrecipe_env(self, arch=None):

def get_recipe_env(self, arch=None):
env = super(CffiRecipe, self).get_recipe_env(arch)
# sets linker to use the correct gcc (cross compiler)
env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
libffi = self.get_recipe('libffi', self.ctx)
includes = libffi.get_include_dirs(arch)
env['CFLAGS'] = ' -I'.join([env.get('CFLAGS', '')] + includes)
env['CFLAGS'] += ' -I{}'.format(self.ctx.python_recipe.include_root(arch.arch))
env['LDFLAGS'] = (env.get('CFLAGS', '') + ' -L' +
self.ctx.get_libs_dir(arch.arch))
env['LDFLAGS'] += ' -L{}'.format(os.path.join(self.ctx.bootstrap.build_dir, 'libs', arch.arch))
Expand All @@ -44,15 +43,10 @@ def get_recipe_env(self, arch=None):
self.ctx.get_site_packages_dir(),
env['BUILDLIB_PATH'],
])
if self.ctx.ndk == 'crystax':
# only keeps major.minor (discards patch)
python_version = self.ctx.python_recipe.version[0:3]
ndk_dir_python = os.path.join(self.ctx.ndk_dir, 'sources/python/', python_version)
env['LDFLAGS'] += ' -L{}'.format(os.path.join(ndk_dir_python, 'libs', arch.arch))
env['LDFLAGS'] += ' -lpython{}m'.format(python_version)
# until `pythonforandroid/archs.py` gets merged upstream:
# https://github.com/kivy/python-for-android/pull/1250/files#diff-569e13021e33ced8b54385f55b49cbe6
env['CFLAGS'] += ' -I{}/include/python/'.format(ndk_dir_python)
env['LDFLAGS'] += ' -L{}'.format(self.ctx.python_recipe.link_root(arch.arch))
env['LDFLAGS'] += ' -lpython{}'.format(self.ctx.python_recipe.major_minor_version_string)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm does libffi actually depend on python? The old recipe doesn't seem to have done that other than for crystax, it just leaves me wondering why it is required? Or is libffi a python-specific lib

(I'm just curious, not saying it's necessarily wrong or anything!)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@opacam got any input on this particular question?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a pretty valid concern @Jonast and definitely deserves some investigations. In the meantime this PR is already improving the current state while not bringing any regression to me.
I think we could merge and eventually address that later

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

if 'python3' in self.ctx.python_recipe.name:
env['LDFLAGS'] += 'm'
return env


Expand Down
21 changes: 9 additions & 12 deletions pythonforandroid/recipes/cryptography/__init__.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
from pythonforandroid.recipe import CompiledComponentsPythonRecipe
from os.path import join
from pythonforandroid.recipe import CompiledComponentsPythonRecipe, Recipe


class CryptographyRecipe(CompiledComponentsPythonRecipe):
name = 'cryptography'
version = '2.3.1'
version = '2.4.2'
url = 'https://github.com/pyca/cryptography/archive/{version}.tar.gz'
depends = [('python2', 'python3crystax'), 'openssl', 'idna', 'asn1crypto', 'six', 'setuptools', 'enum34', 'ipaddress', 'cffi']
depends = ['openssl', 'idna', 'asn1crypto', 'six', 'setuptools',
'enum34', 'ipaddress', 'cffi']
call_hostpython_via_targetpython = False

def get_recipe_env(self, arch):
env = super(CryptographyRecipe, self).get_recipe_env(arch)
r = self.get_recipe('openssl', self.ctx)
openssl_dir = r.get_build_dir(arch.arch)
# Set linker to use the correct gcc
env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
env['CFLAGS'] += ' -I' + join(openssl_dir, 'include')
env['LDFLAGS'] += ' -L' + openssl_dir + \
' -lssl' + r.version + \
' -lcrypto' + r.version

openssl_recipe = Recipe.get_recipe('openssl', self.ctx)
env['CFLAGS'] += openssl_recipe.include_flags(arch)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems clever, I like it! 👍

env['LDFLAGS'] += openssl_recipe.link_dirs_flags(arch)
env['LIBS'] = openssl_recipe.link_libs_flags()

return env

Expand Down
12 changes: 11 additions & 1 deletion pythonforandroid/recipes/enum34/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@
class Enum34Recipe(PythonRecipe):
version = '1.1.3'
url = 'https://pypi.python.org/packages/source/e/enum34/enum34-{version}.tar.gz'
depends = [('python2', 'python3crystax'), 'setuptools']
depends = ['setuptools']
site_packages_name = 'enum'
call_hostpython_via_targetpython = False

def should_build(self, arch):
if 'python3' in self.ctx.python_recipe.name:
# Since python 3.6 the enum34 library is no longer compatible with
# the standard library and it will cause errors, so we disable it
# in favour of the internal module, but we still add python3 to
# attribute `depends` because otherwise we will not be able to
# build the cryptography recipe.
return False
return super(Enum34Recipe, self).should_build(arch)


recipe = Enum34Recipe()
4 changes: 2 additions & 2 deletions pythonforandroid/recipes/idna/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

class IdnaRecipe(PythonRecipe):
name = 'idna'
version = '2.6'
version = '2.8'
url = 'https://github.com/kjd/idna/archive/v{version}.tar.gz'

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

call_hostpython_via_targetpython = False

Expand Down
7 changes: 3 additions & 4 deletions pythonforandroid/recipes/ipaddress/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

class IpaddressRecipe(PythonRecipe):
name = 'ipaddress'
version = '1.0.16'
url = 'https://pypi.python.org/packages/source/i/ipaddress/ipaddress-{version}.tar.gz'

depends = [('python2', 'python3crystax')]
version = '1.0.22'
url = 'https://github.com/phihag/ipaddress/archive/v{version}.tar.gz'
depends = ['setuptools']


recipe = IpaddressRecipe()
2 changes: 1 addition & 1 deletion pythonforandroid/recipes/pycparser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class PycparserRecipe(PythonRecipe):
version = '2.14'
url = 'https://pypi.python.org/packages/source/p/pycparser/pycparser-{version}.tar.gz'

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

call_hostpython_via_targetpython = False

Expand Down