Skip to content

Commit 6be6853

Browse files
authored
Merge pull request #1481 from TheBrokenRail/patch-4
Allow Python 3 To Be Built On Non-ARM Architectures
2 parents 5ee19e6 + 10e53bc commit 6be6853

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

pythonforandroid/archs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class Archx86_64(Arch):
178178
arch = 'x86_64'
179179
toolchain_prefix = 'x86_64'
180180
command_prefix = 'x86_64-linux-android'
181-
platform_dir = 'arch-x86'
181+
platform_dir = 'arch-x86_64'
182182

183183
def get_env(self, with_flags_in_cc=True):
184184
env = super(Archx86_64, self).get_env(with_flags_in_cc)

pythonforandroid/recipes/python3/__init__.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,20 @@ def build_arch(self, arch):
6767
env = environ.copy()
6868

6969
# TODO: Get this information from p4a's arch system
70-
android_host = 'arm-linux-androideabi'
70+
android_host = arch.command_prefix
7171
android_build = sh.Command(join(recipe_build_dir, 'config.guess'))().stdout.strip().decode('utf-8')
72-
platform_dir = join(self.ctx.ndk_dir, 'platforms', platform_name, 'arch-arm')
73-
toolchain = '{android_host}-4.9'.format(android_host=android_host)
72+
platform_dir = join(self.ctx.ndk_dir, 'platforms', platform_name, arch.platform_dir)
73+
toolchain = '{android_host}-4.9'.format(android_host=arch.toolchain_prefix)
7474
toolchain = join(self.ctx.ndk_dir, 'toolchains', toolchain, 'prebuilt', 'linux-x86_64')
75+
76+
target_data = arch.command_prefix.split('-')
77+
if target_data[0] == 'arm':
78+
target_data[0] = 'armv7a'
79+
target = '-'.join([target_data[0], 'none', target_data[1], target_data[2]])
80+
7581
CC = '{clang} -target {target} -gcc-toolchain {toolchain}'.format(
7682
clang=join(self.ctx.ndk_dir, 'toolchains', 'llvm', 'prebuilt', 'linux-x86_64', 'bin', 'clang'),
77-
target='armv7-none-linux-androideabi',
83+
target=target,
7884
toolchain=toolchain)
7985

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

97-
ndk_flags = ('--sysroot={ndk_sysroot} -D__ANDROID_API__={android_api} '
103+
ndk_flags = ('-fPIC --sysroot={ndk_sysroot} -D__ANDROID_API__={android_api} '
98104
'-isystem {ndk_android_host}').format(
99105
ndk_sysroot=join(self.ctx.ndk_dir, 'sysroot'),
100106
android_api=self.ctx.ndk_api,
101107
ndk_android_host=join(
102108
self.ctx.ndk_dir, 'sysroot', 'usr', 'include', android_host))
103-
sysroot = join(self.ctx.ndk_dir, 'platforms', platform_name, 'arch-arm')
109+
sysroot = join(self.ctx.ndk_dir, 'platforms', platform_name, arch.platform_dir)
104110
env['CFLAGS'] = env.get('CFLAGS', '') + ' ' + ndk_flags
105111
env['CPPFLAGS'] = env.get('CPPFLAGS', '') + ' ' + ndk_flags
106112
env['LDFLAGS'] = env.get('LDFLAGS', '') + ' --sysroot={} -L{}'.format(sysroot, join(sysroot, 'usr', 'lib'))
@@ -113,6 +119,8 @@ def build_arch(self, arch):
113119
# bpo-30386 Makefile system.
114120
logger.warning('Doing some hacky stuff to link properly')
115121
lib_dir = join(sysroot, 'usr', 'lib')
122+
if arch.arch == 'x86_64':
123+
lib_dir = join(sysroot, 'usr', 'lib64')
116124
env['LDFLAGS'] += ' -L{}'.format(lib_dir)
117125
shprint(sh.cp, join(lib_dir, 'crtbegin_so.o'), './')
118126
shprint(sh.cp, join(lib_dir, 'crtend_so.o'), './')

0 commit comments

Comments
 (0)