Skip to content

Commit

Permalink
python-scikit-image: use ndk to compile (#1306)
Browse files Browse the repository at this point in the history
  • Loading branch information
licy183 authored Nov 10, 2024
1 parent f7b3db7 commit ecbdcc3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
20 changes: 5 additions & 15 deletions tur/python-scikit-image/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ TERMUX_PKG_DESCRIPTION="Image processing in Python"
TERMUX_PKG_LICENSE="BSD 2-Clause, BSD 3-Clause, MIT"
TERMUX_PKG_MAINTAINER="@termux-user-repository"
TERMUX_PKG_VERSION="0.24.0"
TERMUX_PKG_REVISION=1
TERMUX_PKG_REVISION=2
TERMUX_PKG_SRCURL=https://github.com/scikit-image/scikit-image/archive/refs/tags/v$TERMUX_PKG_VERSION.tar.gz
TERMUX_PKG_SHA256=a2cf85577f8a9105ac46130277ad27e1627bfa3effecff7c1ef3ea851e5671ba
TERMUX_PKG_AUTO_UPDATE=true
TERMUX_PKG_DEPENDS="libandroid-complex-math, libc++, python, python-pip, python-numpy, python-pillow, python-pywavelets, python-scipy"
TERMUX_PKG_ANTI_BUILD_DEPENDS="python-pillow, python-pywavelets, python-scipy"
TERMUX_PKG_PYTHON_COMMON_DEPS="wheel, 'Cython>=3.0.4', meson-python, build"
_NUMPY_VERSION=$(. $TERMUX_SCRIPTDIR/packages/python-numpy/build.sh; echo $TERMUX_PKG_VERSION)
TERMUX_PKG_PYTHON_BUILD_DEPS="pythran, 'numpy==$_NUMPY_VERSION'"
Expand All @@ -18,30 +19,19 @@ TERMUX_PKG_EXTRA_CONFIGURE_ARGS="
--cross-file $TERMUX_MESON_WHEEL_CROSSFILE
"

source $TERMUX_SCRIPTDIR/common-files/setup_toolchain_gcc.sh

termux_step_pre_configure() {
if $TERMUX_ON_DEVICE_BUILD; then
termux_error_exit "Package '$TERMUX_PKG_NAME' is not available for on-device builds."
fi

# FIXME: NDK r27b cannot compile pythran due to https://github.com/llvm/llvm-project/issues/76358
_setup_toolchain_ndk_gcc_11

# ERROR: ./lib/python3.12/site-packages/skimage/measure/_marching_cubes_lewiner_cy.cpython-312.so contains undefined symbols:
# 139: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND cpow
LDFLAGS+=" -landroid-complex-math"
LDFLAGS+=" -Wl,--no-as-needed -lpython${TERMUX_PYTHON_VERSION}"

# FIXME: Don't know why NDK's libc++ should link against clang's libunwind,
# FIXME: otherwise pybind11's `register_local_exception_translator` won't
# FIXME: work properly, causing crash on `scipy.io._mmio`.
mkdir -p $TERMUX_PKG_TMPDIR/_libunwind_libdir
local _NDK_ARCH=$TERMUX_ARCH
test $_NDK_ARCH == 'i686' && _NDK_ARCH='i386'
cp $NDK/toolchains/llvm/prebuilt/linux-x86_64/lib/clang/*/lib/linux/$_NDK_ARCH/libunwind.a \
$TERMUX_PKG_TMPDIR/_libunwind_libdir/libunwind.a
LDFLAGS="-L$TERMUX_PKG_TMPDIR/_libunwind_libdir -l:libunwind.a ${LDFLAGS}"
mkdir -p $TERMUX_PKG_TMPDIR/complex-math-include
cp -f $TERMUX_PKG_BUILDER_DIR/complex.h $TERMUX_PKG_TMPDIR/complex-math-include/
CFLAGS="-I$TERMUX_PKG_TMPDIR/complex-math-include $CFLAGS"
}

termux_step_configure() {
Expand Down
10 changes: 10 additions & 0 deletions tur/python-scikit-image/complex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#ifndef __TERMUX_SCIKIT_IMAGE_COMPLEX__
#define __TERMUX_SCIKIT_IMAGE_COMPLEX__

#include_next <complex.h>

double complex cpow(double complex __x, double complex __z);

#endif // __TERMUX_SCIKIT_IMAGE_COMPLEX__

0 comments on commit ecbdcc3

Please sign in to comment.