Skip to content

compile numpy for x86 #1252

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 2 commits into from
May 7, 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
13 changes: 11 additions & 2 deletions pythonforandroid/archs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

class Arch(object):

include_prefix = None
'''The prefix for the include dir in the NDK.'''

toolchain_prefix = None
'''The prefix for the toolchain dir in the NDK.'''

Expand Down Expand Up @@ -44,7 +47,7 @@ def get_env(self, with_flags_in_cc=True):
# post-15 NDK per
# https://android.googlesource.com/platform/ndk/+/ndk-r15-release/docs/UnifiedHeaders.md
env['CFLAGS'] += ' -isystem {}/sysroot/usr/include/{}'.format(
self.ctx.ndk_dir, self.ctx.toolchain_prefix)
self.ctx.ndk_dir, self.ctx.include_prefix)
else:
sysroot = self.ctx.ndk_platform
env['CFLAGS'] += ' -I{}'.format(self.ctx.ndk_platform)
Expand All @@ -67,10 +70,12 @@ def get_env(self, with_flags_in_cc=True):
if py_platform in ['linux2', 'linux3']:
py_platform = 'linux'

include_prefix = self.ctx.include_prefix
toolchain_prefix = self.ctx.toolchain_prefix
toolchain_version = self.ctx.toolchain_version
command_prefix = self.command_prefix

env['INCLUDE_PREFIX'] = include_prefix
env['TOOLCHAIN_PREFIX'] = toolchain_prefix
env['TOOLCHAIN_VERSION'] = toolchain_version

Expand Down Expand Up @@ -138,6 +143,7 @@ def get_env(self, with_flags_in_cc=True):

class ArchARM(Arch):
arch = "armeabi"
include_prefix = 'arm-linux-androideabi'
toolchain_prefix = 'arm-linux-androideabi'
command_prefix = 'arm-linux-androideabi'
platform_dir = 'arch-arm'
Expand All @@ -157,6 +163,7 @@ def get_env(self, with_flags_in_cc=True):

class Archx86(Arch):
arch = 'x86'
include_prefix = 'i686-linux-android'
toolchain_prefix = 'x86'
command_prefix = 'i686-linux-android'
platform_dir = 'arch-x86'
Expand All @@ -171,7 +178,8 @@ def get_env(self, with_flags_in_cc=True):

class Archx86_64(Arch):
arch = 'x86_64'
toolchain_prefix = 'x86'
include_prefix = 'x86_64-linux-android'
toolchain_prefix = 'x86_64'
command_prefix = 'x86_64-linux-android'
platform_dir = 'arch-x86'

Expand All @@ -185,6 +193,7 @@ def get_env(self, with_flags_in_cc=True):

class ArchAarch_64(Arch):
arch = 'arm64-v8a'
include_prefix = 'aarch64-linux-android'
toolchain_prefix = 'aarch64-linux-android'
command_prefix = 'aarch64-linux-android'
platform_dir = 'arch-arm64'
Expand Down
9 changes: 9 additions & 0 deletions pythonforandroid/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
# This would need to be changed if supporting multiarch APKs
arch = self.archs[0]
platform_dir = arch.platform_dir
include_prefix = arch.include_prefix
toolchain_prefix = arch.toolchain_prefix
toolchain_version = None
self.ndk_platform = join(
Expand All @@ -380,6 +381,13 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
if py_platform in ['linux2', 'linux3']:
py_platform = 'linux'

self.include_prefix = include_prefix
include_path = join(self.ndk_dir, 'sysroot/usr/include/', self.include_prefix)
if not os.path.isdir(include_path):
warning('include directory doesn\'t exist: {}'.format(
include_path))
ok = False

toolchain_versions = []
toolchain_path = join(self.ndk_dir, 'toolchains')
if os.path.isdir(toolchain_path):
Expand Down Expand Up @@ -446,6 +454,7 @@ def __init__(self):
self._ndk_ver = None
self.ndk = None

self.include_prefix = None
self.toolchain_prefix = None
self.toolchain_version = None

Expand Down
2 changes: 0 additions & 2 deletions pythonforandroid/recipes/numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ def get_recipe_env(self, arch):
def prebuild_arch(self, arch):
super(NumpyRecipe, self).prebuild_arch(arch)

warning('Numpy is built assuming the archiver name is '
'arm-linux-androideabi-ar, which may not always be true!')


recipe = NumpyRecipe()
2 changes: 1 addition & 1 deletion pythonforandroid/recipes/numpy/patches/ar.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
self.mkpath(os.path.dirname(output_filename))
tmp_objects = objects + self.objects
+ from os import environ
+ self.archiver[0] = 'arm-linux-androideabi-ar'
+ self.archiver[0] = environ["AR"]
while tmp_objects:
objects = tmp_objects[:50]
tmp_objects = tmp_objects[50:]