-
Notifications
You must be signed in to change notification settings - Fork 1.9k
recipes: add scipy support #2370
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from pythonforandroid.recipe import Recipe | ||
from pythonforandroid.logger import shprint | ||
from pythonforandroid.util import current_directory, ensure_dir, BuildInterruptingException | ||
from multiprocessing import cpu_count | ||
from os.path import join | ||
import sh | ||
|
||
|
||
class LapackRecipe(Recipe): | ||
|
||
name = 'lapack' | ||
version = 'v3.9.0' | ||
url = 'https://github.com/Reference-LAPACK/lapack/archive/{version}.tar.gz' | ||
libdir = 'build/install/lib' | ||
built_libraries = {'libblas.so': libdir, 'liblapack.so': libdir, 'libcblas.so': libdir} | ||
need_stl_shared = True | ||
|
||
def get_recipe_env(self, arch): | ||
env = super().get_recipe_env(arch) | ||
sysroot = f"{self.ctx.ndk_dir}/platforms/{env['NDK_API']}/{arch.platform_dir}" | ||
FC = f"{env['TOOLCHAIN_PREFIX']}-gfortran" | ||
env['FC'] = f'{FC} --sysroot={sysroot}' | ||
if sh.which(FC) is None: | ||
raise BuildInterruptingException(f"{FC} not found. See https://github.com/mzakharo/android-gfortran") | ||
return env | ||
|
||
def build_arch(self, arch): | ||
source_dir = self.get_build_dir(arch.arch) | ||
build_target = join(source_dir, 'build') | ||
install_target = join(build_target, 'install') | ||
|
||
ensure_dir(build_target) | ||
with current_directory(build_target): | ||
env = self.get_recipe_env(arch) | ||
shprint(sh.rm, '-rf', 'CMakeFiles/', 'CMakeCache.txt', _env=env) | ||
shprint(sh.cmake, source_dir, | ||
'-DCMAKE_SYSTEM_NAME=Android', | ||
'-DCMAKE_POSITION_INDEPENDENT_CODE=1', | ||
'-DCMAKE_ANDROID_ARCH_ABI={arch}'.format(arch=arch.arch), | ||
'-DCMAKE_ANDROID_NDK=' + self.ctx.ndk_dir, | ||
'-DCMAKE_BUILD_TYPE=Release', | ||
'-DCMAKE_INSTALL_PREFIX={}'.format(install_target), | ||
'-DANDROID_ABI={arch}'.format(arch=arch.arch), | ||
'-DANDROID_ARM_NEON=ON', | ||
'-DENABLE_NEON=ON', | ||
'-DCBLAS=ON', | ||
'-DBUILD_SHARED_LIBS=ON', | ||
_env=env) | ||
shprint(sh.make, '-j' + str(cpu_count()), _env=env) | ||
shprint(sh.make, 'install', _env=env) | ||
|
||
|
||
recipe = LapackRecipe() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
pythonforandroid/recipes/numpy/patches/compiler_cxx_fix.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
diff --git a/numpy/distutils/ccompiler.py b/numpy/distutils/ccompiler.py | ||
index 6438790..a5f1527 100644 | ||
--- a/numpy/distutils/ccompiler.py | ||
+++ b/numpy/distutils/ccompiler.py | ||
@@ -686,13 +686,13 @@ def CCompiler_cxx_compiler(self): | ||
return self | ||
|
||
cxx = copy(self) | ||
- cxx.compiler_so = [cxx.compiler_cxx[0]] + cxx.compiler_so[1:] | ||
+ cxx.compiler_so = cxx.compiler_cxx + cxx.compiler_so[1:] | ||
if sys.platform.startswith('aix') and 'ld_so_aix' in cxx.linker_so[0]: | ||
# AIX needs the ld_so_aix script included with Python | ||
cxx.linker_so = [cxx.linker_so[0], cxx.compiler_cxx[0]] \ | ||
+ cxx.linker_so[2:] | ||
else: | ||
- cxx.linker_so = [cxx.compiler_cxx[0]] + cxx.linker_so[1:] | ||
+ cxx.linker_so = cxx.compiler_cxx + cxx.linker_so[1:] | ||
return cxx | ||
|
||
replace_method(CCompiler, 'cxx_compiler', CCompiler_cxx_compiler) |
12 changes: 0 additions & 12 deletions
12
pythonforandroid/recipes/numpy/patches/do_not_use_system_libs.patch
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
pythonforandroid/recipes/numpy/patches/hostnumpy-xlocale.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
diff --git a/numpy/core/src/common/numpyos.c b/numpy/core/src/common/numpyos.c | ||
index d60b1ca..8972144 100644 | ||
--- a/numpy/core/src/common/numpyos.c | ||
+++ b/numpy/core/src/common/numpyos.c | ||
@@ -20,7 +20,7 @@ | ||
* the defines from xlocale.h are included in locale.h on some systems; | ||
* see gh-8367 | ||
*/ | ||
- #include <xlocale.h> | ||
+ #include <locale.h> | ||
#endif | ||
#endif | ||
|
28 changes: 28 additions & 0 deletions
28
pythonforandroid/recipes/numpy/patches/remove-default-paths.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
diff --git a/numpy/distutils/system_info.py b/numpy/distutils/system_info.py | ||
index fc7018a..7b514bc 100644 | ||
--- a/numpy/distutils/system_info.py | ||
+++ b/numpy/distutils/system_info.py | ||
@@ -340,10 +340,10 @@ if os.path.join(sys.prefix, 'lib') not in default_lib_dirs: | ||
default_include_dirs.append(os.path.join(sys.prefix, 'include')) | ||
default_src_dirs.append(os.path.join(sys.prefix, 'src')) | ||
|
||
-default_lib_dirs = [_m for _m in default_lib_dirs if os.path.isdir(_m)] | ||
-default_runtime_dirs = [_m for _m in default_runtime_dirs if os.path.isdir(_m)] | ||
-default_include_dirs = [_m for _m in default_include_dirs if os.path.isdir(_m)] | ||
-default_src_dirs = [_m for _m in default_src_dirs if os.path.isdir(_m)] | ||
+default_lib_dirs = [] #[_m for _m in default_lib_dirs if os.path.isdir(_m)] | ||
+default_runtime_dirs =[] # [_m for _m in default_runtime_dirs if os.path.isdir(_m)] | ||
+default_include_dirs =[] # [_m for _m in default_include_dirs if os.path.isdir(_m)] | ||
+default_src_dirs =[] # [_m for _m in default_src_dirs if os.path.isdir(_m)] | ||
|
||
so_ext = get_shared_lib_extension() | ||
|
||
@@ -814,7 +814,7 @@ class system_info(object): | ||
path = self.get_paths(self.section, key) | ||
if path == ['']: | ||
path = [] | ||
- return path | ||
+ return [] | ||
|
||
def get_include_dirs(self, key='include_dirs'): | ||
return self.get_paths(self.section, key) |
30 changes: 0 additions & 30 deletions
30
pythonforandroid/recipes/numpy/patches/remove_unittest_call.patch
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from pythonforandroid.recipe import CompiledComponentsPythonRecipe, Recipe | ||
from multiprocessing import cpu_count | ||
from os.path import join | ||
|
||
|
||
class ScipyRecipe(CompiledComponentsPythonRecipe): | ||
|
||
version = '1.5.4' | ||
url = f'https://github.com/scipy/scipy/releases/download/v{version}/scipy-{version}.zip' | ||
site_packages_name = 'scipy' | ||
depends = ['setuptools', 'cython', 'numpy', 'lapack'] | ||
call_hostpython_via_targetpython = False | ||
|
||
def build_compiled_components(self, arch): | ||
self.setup_extra_args = ['-j', str(cpu_count())] | ||
super().build_compiled_components(arch) | ||
self.setup_extra_args = [] | ||
|
||
def rebuild_compiled_components(self, arch, env): | ||
self.setup_extra_args = ['-j', str(cpu_count())] | ||
super().rebuild_compiled_components(arch, env) | ||
self.setup_extra_args = [] | ||
|
||
def get_recipe_env(self, arch): | ||
env = super().get_recipe_env(arch) | ||
|
||
GCC_VER = '4.9' | ||
HOST = 'linux-x86_64' | ||
LIB = 'lib64' | ||
|
||
prefix = env['TOOLCHAIN_PREFIX'] | ||
lapack_dir = join(Recipe.get_recipe('lapack', self.ctx).get_build_dir(arch.arch), 'build', 'install') | ||
sysroot = f"{self.ctx.ndk_dir}/platforms/{env['NDK_API']}/{arch.platform_dir}" | ||
sysroot_include = f'{self.ctx.ndk_dir}/toolchains/llvm/prebuilt/{HOST}/sysroot/usr/include' | ||
libgfortran = f'{self.ctx.ndk_dir}/toolchains/{prefix}-{GCC_VER}/prebuilt/{HOST}/{prefix}/{LIB}' | ||
numpylib = self.ctx.get_python_install_dir() + '/numpy/core/lib' | ||
LDSHARED_opts = env['LDSHARED'].split('clang')[1] | ||
|
||
env['LAPACK'] = f'{lapack_dir}/lib' | ||
env['BLAS'] = env['LAPACK'] | ||
env['F90'] = f'{prefix}-gfortran' | ||
env['CXX'] += f' -Wl,-l{self.stl_lib_name} -Wl,-L{self.get_stl_lib_dir(arch)}' | ||
env['CPPFLAGS'] += f' --sysroot={sysroot} -I{sysroot_include}/c++/v1 -I{sysroot_include}' | ||
env['LDSHARED'] = 'clang' | ||
env['LDFLAGS'] += f' {LDSHARED_opts} --sysroot={sysroot} -L{libgfortran} -L{numpylib}' | ||
return env | ||
|
||
|
||
recipe = ScipyRecipe() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the need to reset this to the empty list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is copy-paste from the original
numpy/__init__.py
Thoughts on whether this is needed?