11from pythonforandroid .recipe import CompiledComponentsPythonRecipe , Recipe
22from multiprocessing import cpu_count
33from os .path import join
4+ from os import environ
5+ from pythonforandroid .util import build_platform
6+
7+ arch_to_sysroot = {'armeabi' : 'arm' , 'armeabi-v7a' : 'arm' , 'arm64-v8a' : 'arm64' }
48
59
610class ScipyRecipe (CompiledComponentsPythonRecipe ):
711
8- version = '1.5.4 '
12+ version = '1.8.1 '
913 url = f'https://github.com/scipy/scipy/releases/download/v{ version } /scipy-{ version } .zip'
1014 site_packages_name = 'scipy'
11- depends = ['setuptools' , 'cython' , 'numpy' , 'lapack' ]
15+ depends = ['setuptools' , 'cython' , 'numpy' , 'lapack' , 'pybind11' ]
1216 call_hostpython_via_targetpython = False
17+ need_stl_shared = True
1318
1419 def build_compiled_components (self , arch ):
1520 self .setup_extra_args = ['-j' , str (cpu_count ())]
@@ -24,27 +29,42 @@ def rebuild_compiled_components(self, arch, env):
2429 def get_recipe_env (self , arch ):
2530 env = super ().get_recipe_env (arch )
2631
32+ ndk_dir = environ ["LEGACY_NDK" ]
2733 GCC_VER = '4.9'
28- HOST = 'linux-x86_64'
29- LIB = 'lib64 ' if '64' in arch .arch else 'lib '
34+ HOST = build_platform
35+ suffix = '64 ' if '64' in arch .arch else ''
3036
31- lapack_dir = join (Recipe .get_recipe ('lapack' , self .ctx ).get_build_dir (arch .arch ), 'build' , 'install' )
32- sysroot = f"{ self .ctx .ndk_dir } /platforms/{ env ['NDK_API' ]} /{ arch .platform_dir } "
33- sysroot_include = f'{ self .ctx .ndk_dir } /toolchains/llvm/prebuilt/{ HOST } /sysroot/usr/include'
34- prefix = "" # FIXME
35- libgfortran = f'{ self .ctx .ndk_dir } /toolchains/{ prefix } -{ GCC_VER } /prebuilt/{ HOST } /{ prefix } /{ LIB } '
36- numpylib = self .ctx .get_python_install_dir (arch .arch ) + '/numpy/core/lib'
37+ prefix = arch .command_prefix
38+ sysroot_suffix = arch_to_sysroot .get (arch .arch , arch .arch )
39+ sysroot = f"{ ndk_dir } /platforms/{ env ['NDK_API' ]} /arch-{ sysroot_suffix } "
40+ sysroot_include = f'{ ndk_dir } /toolchains/llvm/prebuilt/{ HOST } /sysroot/usr/include'
41+ CLANG_BIN = f'{ ndk_dir } /toolchains/llvm/prebuilt/{ HOST } /bin/'
42+ GCC = f'{ ndk_dir } /toolchains/{ prefix } -{ GCC_VER } /prebuilt/{ HOST } '
43+ libgfortran = f'{ GCC } /{ prefix } /lib{ suffix } '
44+
45+ numpylib = self .ctx .get_python_install_dir (arch .arch ) + '/numpy'
3746 LDSHARED_opts = env ['LDSHARED' ].split ('clang' )[1 ]
47+ arch_cflags = ' ' .join (arch .arch_cflags )
3848
49+ # TODO: add pythran support
50+ env ['SCIPY_USE_PYTHRAN' ] = '0'
51+
52+ lapack_dir = join (Recipe .get_recipe ('lapack' , self .ctx ).get_build_dir (arch .arch ), 'build' , 'install' )
3953 env ['LAPACK' ] = f'{ lapack_dir } /lib'
4054 env ['BLAS' ] = env ['LAPACK' ]
41- env ['F90' ] = f'{ prefix } -gfortran'
42- env ['CXX' ] += f' -Wl,-l{ self .stl_lib_name } -Wl,-L{ self .get_stl_lib_dir (arch )} '
43- env ['CPPFLAGS' ] += f' --sysroot={ sysroot } -I{ sysroot_include } /c++/v1 -I{ sysroot_include } '
44- env ['LDSHARED' ] = 'clang'
45- env ['LDFLAGS' ] += f' { LDSHARED_opts } --sysroot={ sysroot } -L{ libgfortran } -L{ numpylib } '
46- env ['LDFLAGS' ] += f' -L{ self .ctx .ndk_dir } /sources/cxx-stl/llvm-libc++/libs/{ arch .arch } /'
4755
56+ # compilers
57+ env ['F77' ] = f'{ GCC } /bin/{ prefix } -gfortran'
58+ env ['F90' ] = f'{ GCC } /bin/{ prefix } -gfortran'
59+ env ['CC' ] = f'{ CLANG_BIN } /clang -target { arch .target } { arch_cflags } '
60+ env ['CXX' ] = f'{ CLANG_BIN } /clang++ -target { arch .target } { arch_cflags } '
61+ env ['LDSHARED' ] = f'{ CLANG_BIN } /clang'
62+
63+ # flags
64+ env ['CPPFLAGS' ] = f'-DANDROID -I{ sysroot_include } /{ prefix } --sysroot={ sysroot } -I{ sysroot_include } /c++/v1 -I{ sysroot_include } '
65+ env ['LDFLAGS' ] += f' { LDSHARED_opts } --sysroot={ sysroot } -L{ libgfortran } -L{ numpylib } /core/lib -L{ numpylib } /random/lib'
66+ env ['LDFLAGS' ] += f' -l{ self .stl_lib_name } '
67+ env ['LDFLAGS' ] += f' -L{ ndk_dir } /sources/cxx-stl/llvm-libc++/libs/{ arch .arch } /' # for arm32 - unwind
4868 return env
4969
5070
0 commit comments