Skip to content

Commit

Permalink
Add libffi and libexpat support for python3 recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
opacam committed Oct 21, 2018
1 parent 675e2fb commit bec21c7
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ protected static ArrayList<String> getLibraries(File filesDir) {
ArrayList<String> libsList = new ArrayList<String>();
addLibraryIfExists(libsList, "crystax", libsDir);
addLibraryIfExists(libsList, "sqlite3", libsDir);
addLibraryIfExists(libsList, "expat", libsDir);
addLibraryIfExists(libsList, "ffi", libsDir);
libsList.add("SDL2");
libsList.add("SDL2_image");
libsList.add("SDL2_mixer");
Expand Down
33 changes: 25 additions & 8 deletions pythonforandroid/recipes/python3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Python3Recipe(TargetPythonRecipe):

depends = ['hostpython3']
conflicts = ['python3crystax', 'python2']
opt_depends = ['openssl', 'sqlite3']
opt_depends = ['openssl', 'sqlite3', 'libffi', 'libexpat']

def build_arch(self, arch):
recipe_build_dir = self.get_build_dir(arch.arch)
Expand Down Expand Up @@ -69,6 +69,13 @@ def build_arch(self, arch):
env['CPPFLAGS'] = env.get('CPPFLAGS', '') + ' ' + ndk_flags
env['LDFLAGS'] = env.get('LDFLAGS', '') + ' --sysroot={} -L{}'.format(sysroot, join(sysroot, 'usr', 'lib'))

def add_lib_flags(lib_include, lib_link):
# Insert or append to env
flag = 'CPPFLAGS'
env[flag] = env[flag] + lib_include if flag in env else lib_include
flag = 'LDFLAGS'
env[flag] = env[flag] + lib_link if flag in env else lib_link

with_libs = ()
if 'openssl' in self.ctx.recipe_build_order:
recipe = Recipe.get_recipe('openssl', self.ctx)
Expand All @@ -81,18 +88,28 @@ def build_arch(self, arch):
shprint(sh.ln, '-s', openssl_build_dir, lib_ln)

with_libs += ('--with-openssl=' + openssl_build_dir,)

if 'sqlite3' in self.ctx.recipe_build_order:
# Include sqlite3 in python2 build
recipe = Recipe.get_recipe('sqlite3', self.ctx)
include = ' -I' + recipe.get_build_dir(arch.arch)
lib = ' -L' + recipe.get_lib_dir(arch) + ' -lsqlite3'
# Insert or append to env
flag = 'CPPFLAGS'
env[flag] = env[flag] + include if flag in env else include
flag = 'LDFLAGS'
env[flag] = env[flag] + lib if flag in env else lib

add_lib_flags(include, lib)
if 'libffi' in self.ctx.recipe_build_order:
recipe = Recipe.get_recipe('libffi', self.ctx)
include = ' -I' + ' -I'.join(recipe.get_include_dirs(arch))
lib = ' -L' + join(recipe.get_build_dir(arch.arch),
recipe.get_host(arch), '.libs') + ' -lffi'
add_lib_flags(include, lib)
env['LIBFFI_CFLAGS'] = env['CFLAGS'] + include
env['LIBFFI_LIBS'] = lib
with_libs += ('--with-system-ffi',)
if 'libexpat' in self.ctx.recipe_build_order:
recipe = Recipe.get_recipe('libexpat', self.ctx)
include = ' -I' + join(recipe.get_build_dir(arch.arch), 'dist', 'include')
lib = ' -L' + join(recipe.get_build_dir(arch.arch),
'dist', 'lib') + ' -lexpat'
add_lib_flags(include, lib)
with_libs += ('--with-system-expat',)
# Manually add the libs directory, and copy some object
# files to the current directory otherwise they aren't
# picked up. This seems necessary because the --sysroot
Expand Down
31 changes: 31 additions & 0 deletions testapps/setup_testapp_python3_sqlite_openssl_ffi_expat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

from distutils.core import setup
from setuptools import find_packages

options = {'apk': {'debug': None,
'requirements': 'sdl2,pyjnius,kivy,python3,openssl,sqlite3,libffi,libexpat',
'android-api': 19,
'ndk-dir': '/home/asandy/android/crystax-ndk-10.3.2',
'dist-name': 'bdisttest_python3_googlendk_sqlite_openssl_ffi_expat',
'ndk-version': '10.3.2',
'arch': 'armeabi-v7a',
'permission': 'VIBRATE',
}}

package_data = {'': ['*.py',
'*.png']
}

packages = find_packages()
print('packages are', packages)

setup(
name='testapp_python3_googlendk_sqlite_openssl_ffi_expat',
version='1.1',
description='p4a setup.py test',
author='Alexander Taylor',
author_email='[email protected]',
packages=find_packages(),
options=options,
package_data={'testapp': ['*.py', '*.png']}
)

0 comments on commit bec21c7

Please sign in to comment.