|
| 1 | +TERMUX_PKG_HOMEPAGE=https://www.tensorflow.org/lite |
| 2 | +TERMUX_PKG_DESCRIPTION="TensorFlow Lite Python bindings" |
| 3 | +TERMUX_PKG_LICENSE="Apache-2.0" |
| 4 | +TERMUX_PKG_MAINTAINER="@termux-user-repository" |
| 5 | +TERMUX_PKG_VERSION="2.17.0" |
| 6 | +TERMUX_PKG_SRCURL=git+https://github.com/tensorflow/tensorflow |
| 7 | +TERMUX_PKG_AUTO_UPDATE=true |
| 8 | +TERMUX_PKG_DEPENDS="python, python-numpy, python-pip" |
| 9 | +TERMUX_PKG_UPDATE_TAG_TYPE="latest-release" |
| 10 | +TERMUX_PKG_PYTHON_COMMON_DEPS="setuptools, wheel, pybind11" |
| 11 | + |
| 12 | +TERMUX_PYTHON_VERSION=3.12 |
| 13 | +TERMUX_PYTHON_HOME=$TERMUX_PREFIX/lib/python${TERMUX_PYTHON_VERSION} |
| 14 | +TERMUX_PYTHON_CROSSENV_PREFIX=$TERMUX_PKG_BUILDDIR/python${TERMUX_PYTHON_VERSION/./}-crossenv-prefix-$TERMUX_ARCH |
| 15 | +TUR_AUTO_AUDIT_WHEEL=true |
| 16 | +TUR_AUDIT_WHEEL_NO_LIBS=true |
| 17 | +TUR_AUTO_BUILD_WHEEL=false |
| 18 | +TUR_WHEEL_DIR="build-wheel/dist" |
| 19 | + |
| 20 | +source $TERMUX_SCRIPTDIR/common-files/tur_build_wheel.sh |
| 21 | + |
| 22 | +termux_step_pre_configure() { |
| 23 | + termux_setup_cmake |
| 24 | + termux_setup_ninja |
| 25 | + |
| 26 | + # Copied from tensorflow/lite/tools/pip_package/build_pip_package_with_cmake.sh |
| 27 | + export TENSORFLOW_DIR="$TERMUX_PKG_SRCDIR" |
| 28 | + local TENSORFLOW_LITE_DIR="$TENSORFLOW_DIR/tensorflow/lite" |
| 29 | + local TENSORFLOW_VERSION=$(grep "_VERSION = " "$TENSORFLOW_DIR/tensorflow/tools/pip_package/setup.py" | cut -d= -f2 | sed "s/[ '-]//g") |
| 30 | + export PACKAGE_VERSION="$TENSORFLOW_VERSION" |
| 31 | + export PROJECT_NAME="tflite_runtime" |
| 32 | + TFLITE_BUILD_DIR="$TERMUX_PKG_BUILDDIR/build-wheel" |
| 33 | + local BUILD_DIR="$TFLITE_BUILD_DIR" |
| 34 | + local PYTHON="$(command -v python)" |
| 35 | + local PYBIND11_INCLUDE=$($PYTHON -c "import pybind11; print (pybind11.get_include())") |
| 36 | + CPPFLAGS+=" -I$PYTHON_SITE_PKG/numpy/_core/include" |
| 37 | + CPPFLAGS+=" -I$PYBIND11_INCLUDE" |
| 38 | + CPPFLAGS+=" -I$TERMUX_PREFIX/include/python$TERMUX_PYTHON_VERSION" |
| 39 | + |
| 40 | + # Build source tree |
| 41 | + rm -rf "$BUILD_DIR" && mkdir -p "$BUILD_DIR/tflite_runtime" |
| 42 | + cp -r "$TENSORFLOW_LITE_DIR/tools/pip_package/debian" \ |
| 43 | + "$TENSORFLOW_LITE_DIR/tools/pip_package/MANIFEST.in" \ |
| 44 | + "$TENSORFLOW_LITE_DIR/python/interpreter_wrapper" \ |
| 45 | + "$BUILD_DIR" |
| 46 | + cp "$TENSORFLOW_LITE_DIR/tools/pip_package/setup_with_binary.py" "$BUILD_DIR/setup.py" |
| 47 | + cp "$TENSORFLOW_LITE_DIR/python/interpreter.py" \ |
| 48 | + "$TENSORFLOW_LITE_DIR/python/metrics/metrics_interface.py" \ |
| 49 | + "$TENSORFLOW_LITE_DIR/python/metrics/metrics_portable.py" \ |
| 50 | + "$BUILD_DIR/tflite_runtime" |
| 51 | + echo "__version__ = '$PACKAGE_VERSION'" >> "$BUILD_DIR/tflite_runtime/__init__.py" |
| 52 | + echo "__git_version__ = '$(git -C "$TENSORFLOW_DIR" describe)'" >> "$BUILD_DIR/tflite_runtime/__init__.py" |
| 53 | + |
| 54 | + TERMUX_PKG_SRCDIR_OLD="$TERMUX_PKG_SRCDIR" |
| 55 | + TERMUX_PKG_SRCDIR="$TERMUX_PKG_SRCDIR/tensorflow/lite" |
| 56 | +} |
| 57 | + |
| 58 | +termux_step_post_configure() { |
| 59 | + TERMUX_PKG_SRCDIR="$TERMUX_PKG_SRCDIR_OLD" |
| 60 | +} |
| 61 | + |
| 62 | +termux_step_make() { |
| 63 | + # Build python interpreter_wrapper |
| 64 | + cmake --build . -j $TERMUX_PKG_MAKE_PROCESSES -t _pywrap_tensorflow_interpreter_wrapper |
| 65 | + cp "$TERMUX_PKG_BUILDDIR/_pywrap_tensorflow_interpreter_wrapper.so" \ |
| 66 | + "$TFLITE_BUILD_DIR/tflite_runtime" |
| 67 | + |
| 68 | + # Build python wheel |
| 69 | + cd "$TFLITE_BUILD_DIR" |
| 70 | + python setup.py bdist_wheel |
| 71 | +} |
| 72 | + |
| 73 | +termux_step_make_install() { |
| 74 | + local _pyver="${TERMUX_PYTHON_VERSION//./}" |
| 75 | + local _wheel="tflite_runtime-${TERMUX_PKG_VERSION}-cp${_pyver}-cp${_pyver}-linux_${TERMUX_ARCH}.whl" |
| 76 | + pip install --no-deps --prefix="$TERMUX_PREFIX" "$TFLITE_BUILD_DIR/dist/${_wheel}" |
| 77 | +} |
0 commit comments