Skip to content

Fix libffi/ctypes - wrong libffi headers when building python #1609

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 4 commits into from
Jan 26, 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
8 changes: 6 additions & 2 deletions pythonforandroid/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,13 @@ def add_flags(include_flags, link_dirs, link_libs):
if 'libffi' in self.ctx.recipe_build_order:
info('Activating flags for libffi')
recipe = Recipe.get_recipe('libffi', self.ctx)
# In order to force the correct linkage for our libffi library, we
# set the following variable to point where is our libffi.pc file,
# because the python build system uses pkg-config to configure it.
env['PKG_CONFIG_PATH'] = recipe.get_build_dir(arch.arch)
add_flags(' -I' + ' -I'.join(recipe.get_include_dirs(arch)),
' -L' + join(recipe.get_build_dir(arch.arch),
recipe.get_host(arch), '.libs'), ' -lffi')
' -L' + join(recipe.get_build_dir(arch.arch), '.libs'),
' -lffi')

if 'openssl' in self.ctx.recipe_build_order:
info('Activating flags for openssl')
Expand Down
29 changes: 9 additions & 20 deletions pythonforandroid/recipes/libffi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,11 @@ class LibffiRecipe(Recipe):
version = '3.2.1'
url = 'https://github.com/libffi/libffi/archive/v{version}.tar.gz'

patches = ['remove-version-info.patch']

def get_host(self, arch):
with current_directory(self.get_build_dir(arch.arch)):
host = None
with open('Makefile') as f:
for line in f:
if line.startswith('host = '):
host = line.strip()[7:]
break

if not host or not exists(host):
raise RuntimeError('failed to find build output! ({})'
.format(host))

return host
patches = ['remove-version-info.patch',
# This patch below is already included into libffi's master
# branch and included in the pre-release 3.3rc0...so we should
# remove this when we update the version number for libffi
'fix-includedir.patch']

def should_build(self, arch):
return not exists(join(self.ctx.get_libs_dir(arch.arch), 'libffi.so'))
Expand All @@ -45,7 +34,8 @@ def build_arch(self, arch):
shprint(sh.Command('autoreconf'), '-vif', _env=env)
shprint(sh.Command('./configure'),
'--host=' + arch.command_prefix,
'--prefix=' + self.ctx.get_python_install_dir(),
'--prefix=' + self.get_build_dir(arch.arch),
'--disable-builddir',
'--enable-shared', _env=env)
# '--with-sysroot={}'.format(self.ctx.ndk_platform),
# '--target={}'.format(arch.toolchain_prefix),
Expand All @@ -62,7 +52,7 @@ def build_arch(self, arch):
info("make libffi.la failed as expected")
cc = sh.Command(env['CC'].split()[0])
cflags = env['CC'].split()[1:]
host_build = join(self.get_build_dir(arch.arch), self.get_host(arch))
host_build = self.get_build_dir(arch.arch)

arch_flags = ''
if '-march=' in env['CFLAGS']:
Expand Down Expand Up @@ -91,8 +81,7 @@ def build_arch(self, arch):
join(host_build, '.libs', 'libffi.so'))

def get_include_dirs(self, arch):
return [join(self.get_build_dir(arch.arch), self.get_host(arch),
'include')]
return [join(self.get_build_dir(arch.arch), 'include')]


recipe = LibffiRecipe()
34 changes: 34 additions & 0 deletions pythonforandroid/recipes/libffi/fix-includedir.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
From 982b89c01aca99c7bc229914fc1521f96930919b Mon Sep 17 00:00:00 2001
From: Yen Chi Hsuan <[email protected]>
Date: Sun, 13 Nov 2016 19:17:19 +0800
Subject: [PATCH] Install public headers in the standard path

---
include/Makefile.am | 3 +--
libffi.pc.in | 2 +-
2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/include/Makefile.am b/include/Makefile.am
index bb241e88..c59df9fb 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -6,5 +6,4 @@ DISTCLEANFILES=ffitarget.h
noinst_HEADERS=ffi_common.h ffi_cfi.h
EXTRA_DIST=ffi.h.in

-includesdir = $(libdir)/@PACKAGE_NAME@-@PACKAGE_VERSION@/include
-nodist_includes_HEADERS = ffi.h ffitarget.h
+nodist_include_HEADERS = ffi.h ffitarget.h
diff --git a/libffi.pc.in b/libffi.pc.in
index edf6fde5..6fad83b4 100644
--- a/libffi.pc.in
+++ b/libffi.pc.in
@@ -2,7 +2,7 @@ prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
toolexeclibdir=@toolexeclibdir@
-includedir=${libdir}/@PACKAGE_NAME@-@PACKAGE_VERSION@/include
+includedir=@includedir@

Name: @PACKAGE_NAME@
Description: Library supporting Foreign Function Interfaces
5 changes: 5 additions & 0 deletions pythonforandroid/recipes/python2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ def prebuild_arch(self, arch):

def set_libs_flags(self, env, arch):
env = super(Python2Recipe, self).set_libs_flags(env, arch)
if 'libffi' in self.ctx.recipe_build_order:
# For python2 we need to tell configure that we want to use our
# compiled libffi, this step is not necessary for python3.
self.configure_args += ('--with-system-ffi',)

if 'openssl' in self.ctx.recipe_build_order:
recipe = Recipe.get_recipe('openssl', self.ctx)
openssl_build = recipe.get_build_dir(arch.arch)
Expand Down