Skip to content

Allow Python 3 To Be Built On Non-ARM Architectures #1481

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 9 commits into from
Dec 3, 2018
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
2 changes: 1 addition & 1 deletion pythonforandroid/archs.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class Archx86_64(Arch):
arch = 'x86_64'
toolchain_prefix = 'x86_64'
command_prefix = 'x86_64-linux-android'
platform_dir = 'arch-x86'
platform_dir = 'arch-x86_64'

def get_env(self, with_flags_in_cc=True):
env = super(Archx86_64, self).get_env(with_flags_in_cc)
Expand Down
20 changes: 14 additions & 6 deletions pythonforandroid/recipes/python3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,20 @@ def build_arch(self, arch):
env = environ.copy()

# TODO: Get this information from p4a's arch system
android_host = 'arm-linux-androideabi'
android_host = arch.command_prefix
android_build = sh.Command(join(recipe_build_dir, 'config.guess'))().stdout.strip().decode('utf-8')
platform_dir = join(self.ctx.ndk_dir, 'platforms', platform_name, 'arch-arm')
toolchain = '{android_host}-4.9'.format(android_host=android_host)
platform_dir = join(self.ctx.ndk_dir, 'platforms', platform_name, arch.platform_dir)
toolchain = '{android_host}-4.9'.format(android_host=arch.toolchain_prefix)
toolchain = join(self.ctx.ndk_dir, 'toolchains', toolchain, 'prebuilt', 'linux-x86_64')

target_data = arch.command_prefix.split('-')
if target_data[0] == 'arm':
target_data[0] = 'armv7a'
target = '-'.join([target_data[0], 'none', target_data[1], target_data[2]])

CC = '{clang} -target {target} -gcc-toolchain {toolchain}'.format(
clang=join(self.ctx.ndk_dir, 'toolchains', 'llvm', 'prebuilt', 'linux-x86_64', 'bin', 'clang'),
target='armv7-none-linux-androideabi',
target=target,
toolchain=toolchain)

AR = join(toolchain, 'bin', android_host) + '-ar'
Expand All @@ -94,13 +100,13 @@ def build_arch(self, arch):
hostpython_dir=self.get_recipe('hostpython3', self.ctx).get_path_to_python(),
old_path=env['PATH'])

ndk_flags = ('--sysroot={ndk_sysroot} -D__ANDROID_API__={android_api} '
ndk_flags = ('-fPIC --sysroot={ndk_sysroot} -D__ANDROID_API__={android_api} '
'-isystem {ndk_android_host}').format(
ndk_sysroot=join(self.ctx.ndk_dir, 'sysroot'),
android_api=self.ctx.ndk_api,
ndk_android_host=join(
self.ctx.ndk_dir, 'sysroot', 'usr', 'include', android_host))
sysroot = join(self.ctx.ndk_dir, 'platforms', platform_name, 'arch-arm')
sysroot = join(self.ctx.ndk_dir, 'platforms', platform_name, arch.platform_dir)
env['CFLAGS'] = env.get('CFLAGS', '') + ' ' + ndk_flags
env['CPPFLAGS'] = env.get('CPPFLAGS', '') + ' ' + ndk_flags
env['LDFLAGS'] = env.get('LDFLAGS', '') + ' --sysroot={} -L{}'.format(sysroot, join(sysroot, 'usr', 'lib'))
Expand All @@ -113,6 +119,8 @@ def build_arch(self, arch):
# bpo-30386 Makefile system.
logger.warning('Doing some hacky stuff to link properly')
lib_dir = join(sysroot, 'usr', 'lib')
if arch.arch == 'x86_64':
lib_dir = join(sysroot, 'usr', 'lib64')
env['LDFLAGS'] += ' -L{}'.format(lib_dir)
shprint(sh.cp, join(lib_dir, 'crtbegin_so.o'), './')
shprint(sh.cp, join(lib_dir, 'crtend_so.o'), './')
Expand Down