Skip to content

Commit

Permalink
scipy: update to 1.11.3
Browse files Browse the repository at this point in the history
  • Loading branch information
T-Dynamos committed Oct 29, 2023
1 parent 89a05ba commit 3470108
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 3 deletions.
91 changes: 91 additions & 0 deletions pythonforandroid/recipes/openblas/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
from pythonforandroid.recipe import CompiledComponentsPythonRecipe, Recipe
from multiprocessing import cpu_count
from os.path import join
import sh
from os import environ
from pythonforandroid.util import build_platform
from pythonforandroid.logger import shprint


def arch_to_toolchain(arch):
if 'arm' in arch.arch:
return arch.command_prefix
return arch.arch


class ScipyRecipe(CompiledComponentsPythonRecipe):

version = '1.11.3'
url = f'https://github.com/scipy/scipy/archive/refs/tags/v{version}.zip'
site_packages_name = 'scipy'
depends = ['setuptools', 'cython', 'numpy', 'lapack', 'pybind11']
call_hostpython_via_targetpython = False
need_stl_shared = True

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 unpack(self, arch):
super().unpack(arch)
shprint(
sh.cp,
join(self.get_build_dir(arch), "_setup.py"),
join(self.get_build_dir(arch), "setup.py")
)

def get_recipe_env(self, arch):
env = super().get_recipe_env(arch)
arch_env = arch.get_env()

env['LDFLAGS'] = arch_env['LDFLAGS']
env['LDFLAGS'] += ' -L{} -lpython{}'.format(
self.ctx.python_recipe.link_root(arch.arch),
self.ctx.python_recipe.link_version,
)

ndk_dir = environ["LEGACY_NDK"]
GCC_VER = '4.9'
HOST = build_platform
suffix = '64' if '64' in arch.arch else ''

prefix = arch.command_prefix
CLANG_BIN = f'{ndk_dir}/toolchains/llvm/prebuilt/{HOST}/bin/'
GCC = f'{ndk_dir}/toolchains/{arch_to_toolchain(arch)}-{GCC_VER}/prebuilt/{HOST}'
libgfortran = f'{GCC}/{prefix}/lib{suffix}'
numpylib = self.ctx.get_python_install_dir(arch.arch) + '/numpy'
arch_cflags = ' '.join(arch.arch_cflags)
LDSHARED_opts = f'-target {arch.target} {arch_cflags} ' + ' '.join(arch.common_ldshared)

# TODO: add pythran support
env['SCIPY_USE_PYTHRAN'] = '0'

lapack_dir = join(Recipe.get_recipe('lapack', self.ctx).get_build_dir(arch.arch), 'build', 'install')
env['LAPACK'] = f'{lapack_dir}/lib'
env['BLAS'] = env['LAPACK']

# compilers
env['F77'] = f'{GCC}/bin/{prefix}-gfortran'
env['F90'] = f'{GCC}/bin/{prefix}-gfortran'
env['CC'] = f'{CLANG_BIN}clang -target {arch.target} {arch_cflags}'
env['CXX'] = f'{CLANG_BIN}clang++ -target {arch.target} {arch_cflags}'

# scipy expects ldshared to be a single executable without options
env['LDSHARED'] = f'{CLANG_BIN}/clang'

# erase the default NDK C++ include options
env['CPPFLAGS'] = '-DANDROID'

# configure linker
env['LDFLAGS'] += f' {LDSHARED_opts} -L{libgfortran} -L{numpylib}/core/lib -L{numpylib}/random/lib'
env['LDFLAGS'] += f' -l{self.stl_lib_name}'
return env


recipe = ScipyRecipe()
16 changes: 13 additions & 3 deletions pythonforandroid/recipes/scipy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from pythonforandroid.recipe import CompiledComponentsPythonRecipe, Recipe
from multiprocessing import cpu_count
from os.path import join
import sh
from os import environ
from pythonforandroid.util import build_platform

from pythonforandroid.logger import shprint
from pythonforandroid.util import current_directory

def arch_to_toolchain(arch):
if 'arm' in arch.arch:
Expand All @@ -13,8 +15,8 @@ def arch_to_toolchain(arch):

class ScipyRecipe(CompiledComponentsPythonRecipe):

version = '1.8.1'
url = f'https://github.com/scipy/scipy/releases/download/v{version}/scipy-{version}.zip'
version = '1.11.3'
url = f'git+https://github.com/scipy/scipy.git'
site_packages_name = 'scipy'
depends = ['setuptools', 'cython', 'numpy', 'lapack', 'pybind11']
call_hostpython_via_targetpython = False
Expand All @@ -30,6 +32,14 @@ def rebuild_compiled_components(self, arch, env):
super().rebuild_compiled_components(arch, env)
self.setup_extra_args = []

def unpack(self, arch):
super().unpack(arch)
shprint(
sh.cp,
join(self.get_build_dir(arch), "_setup.py"),
join(self.get_build_dir(arch), "setup.py")
)

def get_recipe_env(self, arch):
env = super().get_recipe_env(arch)
arch_env = arch.get_env()
Expand Down

0 comments on commit 3470108

Please sign in to comment.