Skip to content

Commit 2bb7285

Browse files
authored
Merge pull request kivy#1609 from opacam/fix-libffi-linkage
Fix libffi/ctypes - wrong libffi headers when building python
2 parents 32389cb + 38cdc93 commit 2bb7285

File tree

4 files changed

+54
-22
lines changed

4 files changed

+54
-22
lines changed

pythonforandroid/python.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,13 @@ def add_flags(include_flags, link_dirs, link_libs):
178178
if 'libffi' in self.ctx.recipe_build_order:
179179
info('Activating flags for libffi')
180180
recipe = Recipe.get_recipe('libffi', self.ctx)
181+
# In order to force the correct linkage for our libffi library, we
182+
# set the following variable to point where is our libffi.pc file,
183+
# because the python build system uses pkg-config to configure it.
184+
env['PKG_CONFIG_PATH'] = recipe.get_build_dir(arch.arch)
181185
add_flags(' -I' + ' -I'.join(recipe.get_include_dirs(arch)),
182-
' -L' + join(recipe.get_build_dir(arch.arch),
183-
recipe.get_host(arch), '.libs'), ' -lffi')
186+
' -L' + join(recipe.get_build_dir(arch.arch), '.libs'),
187+
' -lffi')
184188

185189
if 'openssl' in self.ctx.recipe_build_order:
186190
info('Activating flags for openssl')

pythonforandroid/recipes/libffi/__init__.py

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,11 @@ class LibffiRecipe(Recipe):
1717
version = '3.2.1'
1818
url = 'https://github.com/libffi/libffi/archive/v{version}.tar.gz'
1919

20-
patches = ['remove-version-info.patch']
21-
22-
def get_host(self, arch):
23-
with current_directory(self.get_build_dir(arch.arch)):
24-
host = None
25-
with open('Makefile') as f:
26-
for line in f:
27-
if line.startswith('host = '):
28-
host = line.strip()[7:]
29-
break
30-
31-
if not host or not exists(host):
32-
raise RuntimeError('failed to find build output! ({})'
33-
.format(host))
34-
35-
return host
20+
patches = ['remove-version-info.patch',
21+
# This patch below is already included into libffi's master
22+
# branch and included in the pre-release 3.3rc0...so we should
23+
# remove this when we update the version number for libffi
24+
'fix-includedir.patch']
3625

3726
def should_build(self, arch):
3827
return not exists(join(self.ctx.get_libs_dir(arch.arch), 'libffi.so'))
@@ -45,7 +34,8 @@ def build_arch(self, arch):
4534
shprint(sh.Command('autoreconf'), '-vif', _env=env)
4635
shprint(sh.Command('./configure'),
4736
'--host=' + arch.command_prefix,
48-
'--prefix=' + self.ctx.get_python_install_dir(),
37+
'--prefix=' + self.get_build_dir(arch.arch),
38+
'--disable-builddir',
4939
'--enable-shared', _env=env)
5040
# '--with-sysroot={}'.format(self.ctx.ndk_platform),
5141
# '--target={}'.format(arch.toolchain_prefix),
@@ -62,7 +52,7 @@ def build_arch(self, arch):
6252
info("make libffi.la failed as expected")
6353
cc = sh.Command(env['CC'].split()[0])
6454
cflags = env['CC'].split()[1:]
65-
host_build = join(self.get_build_dir(arch.arch), self.get_host(arch))
55+
host_build = self.get_build_dir(arch.arch)
6656

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

9383
def get_include_dirs(self, arch):
94-
return [join(self.get_build_dir(arch.arch), self.get_host(arch),
95-
'include')]
84+
return [join(self.get_build_dir(arch.arch), 'include')]
9685

9786

9887
recipe = LibffiRecipe()
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
From 982b89c01aca99c7bc229914fc1521f96930919b Mon Sep 17 00:00:00 2001
2+
From: Yen Chi Hsuan <[email protected]>
3+
Date: Sun, 13 Nov 2016 19:17:19 +0800
4+
Subject: [PATCH] Install public headers in the standard path
5+
6+
---
7+
include/Makefile.am | 3 +--
8+
libffi.pc.in | 2 +-
9+
2 files changed, 2 insertions(+), 3 deletions(-)
10+
11+
diff --git a/include/Makefile.am b/include/Makefile.am
12+
index bb241e88..c59df9fb 100644
13+
--- a/include/Makefile.am
14+
+++ b/include/Makefile.am
15+
@@ -6,5 +6,4 @@ DISTCLEANFILES=ffitarget.h
16+
noinst_HEADERS=ffi_common.h ffi_cfi.h
17+
EXTRA_DIST=ffi.h.in
18+
19+
-includesdir = $(libdir)/@PACKAGE_NAME@-@PACKAGE_VERSION@/include
20+
-nodist_includes_HEADERS = ffi.h ffitarget.h
21+
+nodist_include_HEADERS = ffi.h ffitarget.h
22+
diff --git a/libffi.pc.in b/libffi.pc.in
23+
index edf6fde5..6fad83b4 100644
24+
--- a/libffi.pc.in
25+
+++ b/libffi.pc.in
26+
@@ -2,7 +2,7 @@ prefix=@prefix@
27+
exec_prefix=@exec_prefix@
28+
libdir=@libdir@
29+
toolexeclibdir=@toolexeclibdir@
30+
-includedir=${libdir}/@PACKAGE_NAME@-@PACKAGE_VERSION@/include
31+
+includedir=@includedir@
32+
33+
Name: @PACKAGE_NAME@
34+
Description: Library supporting Foreign Function Interfaces

pythonforandroid/recipes/python2/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ def prebuild_arch(self, arch):
5656

5757
def set_libs_flags(self, env, arch):
5858
env = super(Python2Recipe, self).set_libs_flags(env, arch)
59+
if 'libffi' in self.ctx.recipe_build_order:
60+
# For python2 we need to tell configure that we want to use our
61+
# compiled libffi, this step is not necessary for python3.
62+
self.configure_args += ('--with-system-ffi',)
63+
5964
if 'openssl' in self.ctx.recipe_build_order:
6065
recipe = Recipe.get_recipe('openssl', self.ctx)
6166
openssl_build = recipe.get_build_dir(arch.arch)

0 commit comments

Comments
 (0)