Skip to content
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

Fix libffi recipe, and build + runtime linker errors when compiling on WSL #1744

Merged
merged 8 commits into from
Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 1 addition & 1 deletion Dockerfile.py3
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ RUN dpkg --add-architecture i386 \
build-essential ccache git python3 python3-dev \
libncurses5:i386 libstdc++6:i386 libgtk2.0-0:i386 \
libpangox-1.0-0:i386 libpangoxft-1.0-0:i386 libidn11:i386 \
zip zlib1g-dev zlib1g:i386 \
zip zlib1g-dev zlib1g:i386 lld \
&& apt -y autoremove

# specific recipes dependencies (e.g. libffi requires autoreconf binary)
Expand Down
2 changes: 1 addition & 1 deletion pythonforandroid/archs.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def get_env(self, with_flags_in_cc=True, clang=False):
self.ctx.python_recipe.version[0:3])
)

env['LDFLAGS'] += '--sysroot {} '.format(self.ctx.ndk_platform)
env['LDFLAGS'] += '--sysroot={} '.format(self.ctx.ndk_platform)

env["CXXFLAGS"] = env["CFLAGS"]

Expand Down
8 changes: 8 additions & 0 deletions pythonforandroid/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True):

env['SYSROOT'] = sysroot

if sh.which('lld') is not None:
# Note: The -L. is to fix a bug in python 3.7.
AndreMiras marked this conversation as resolved.
Show resolved Hide resolved
# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=234409
env["LDFLAGS"] += ' -L. -fuse-ld=lld'
else:
logger.warning('lld not found, linking without it. ' +
'Consider installing lld if linker errors occur.')

return env

def set_libs_flags(self, env, arch):
Expand Down
42 changes: 3 additions & 39 deletions pythonforandroid/recipes/libffi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from os.path import exists, join
from multiprocessing import cpu_count
from pythonforandroid.recipe import Recipe
from pythonforandroid.logger import info, shprint
from pythonforandroid.logger import shprint
from pythonforandroid.util import current_directory, ensure_dir
from glob import glob
import sh


Expand Down Expand Up @@ -37,46 +37,10 @@ def build_arch(self, arch):
'--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),

# ndk 15 introduces unified headers required --sysroot and
# -isysroot for libraries and headers. libtool's head explodes
# trying to weave them into it's own magic. The result is a link
# failure trying to link libc. We call make to compile the bits
# and manually link...
shprint(sh.make, '-j', str(cpu_count()), 'libffi.la', _env=env)

try:
shprint(sh.make, '-j5', 'libffi.la', _env=env)
except sh.ErrorReturnCode_2:
info("make libffi.la failed as expected")
cc = sh.Command(env['CC'].split()[0])
cflags = env['CC'].split()[1:]
host_build = self.get_build_dir(arch.arch)

arch_flags = ''
Aralox marked this conversation as resolved.
Show resolved Hide resolved
if '-march=' in env['CFLAGS']:
arch_flags = '-march={}'.format(env['CFLAGS'].split('-march=')[1])

src_arch = arch.command_prefix.split('-')[0]
if src_arch == 'x86_64':
# libffi has not specific arch files for x86_64...so...using
# the ones from x86 which seems to build fine...
src_arch = 'x86'

cflags.extend(arch_flags.split())
cflags.extend(['-shared', '-fPIC', '-DPIC'])
cflags.extend(glob(join(host_build, 'src/.libs/*.o')))
cflags.extend(glob(join(host_build, 'src', src_arch, '.libs/*.o')))

ldflags = env['LDFLAGS'].split()
cflags.extend(ldflags)
cflags.extend(['-Wl,-soname', '-Wl,libffi.so', '-o',
'.libs/libffi.so'])

with current_directory(host_build):
shprint(cc, *cflags, _env=env)

ensure_dir(self.ctx.get_libs_dir(arch.arch))
shprint(sh.cp,
join(host_build, '.libs', 'libffi.so'),
Expand Down
4 changes: 4 additions & 0 deletions pythonforandroid/recipes/python3/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sh
from pythonforandroid.python import GuestPythonRecipe
from pythonforandroid.recipe import Recipe

Expand All @@ -23,6 +24,9 @@ class Python3Recipe(GuestPythonRecipe):

patches = ["patches/fix-ctypes-util-find-library.patch"]

if sh.which('lld') is not None:
patches = patches + ["patches/remove-fix-cortex-a8.patch"]

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
This patch removes --fix-cortex-a8 from the linker flags in order to support linking
with lld, as lld does not support this flag (https://github.com/android-ndk/ndk/issues/766).
diff --git a/configure b/configure
Aralox marked this conversation as resolved.
Show resolved Hide resolved
--- a/configure
+++ b/configure
@@ -5671,7 +5671,7 @@ $as_echo_n "checking for the Android arm ABI... " >&6; }
$as_echo "$_arm_arch" >&6; }
if test "$_arm_arch" = 7; then
BASECFLAGS="${BASECFLAGS} -mfloat-abi=softfp -mfpu=vfpv3-d16"
- LDFLAGS="${LDFLAGS} -march=armv7-a -Wl,--fix-cortex-a8"
+ LDFLAGS="${LDFLAGS} -march=armv7-a"
fi
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: not Android" >&5