mirror of
https://github.com/termux-pacman/termux-packages.git
synced 2026-02-12 04:41:03 +00:00
- debpython is the commands `py3compile` and `py3clean` from Debian. I
am calling them that because a large chunk of their source code is
found inside a folder inside Debian's source code named "debpython"
- 5348f70466
- rather than packaging `.pyc` files into packages, `py3compile` and
`py3clean` can be called from `postinst` and `prerm` scripts to
generate all `.pyc` for the `.py` files in the package immediately
after the package is installed, and remove all `.pyc` files immediately
before uninstalling the package, respectively
- fixes the error `trying to overwrite '/data/data/com.termux/files/usr/lib/python3.12/__pycache__/cProfile.cpython-312.pyc'` when packages were built on-device, but at the same time, also:
- prevents the warnings `dpkg: warning: while removing python, directory '/data/data/com.termux/files/usr/lib/python3.12/site-packages' not empty so not removed` as long as no packages were installed using `pip`
- The `termux_step_create_python_debscripts.sh` can configure work on debpython (i.e. its `py3copile` and `py3clean` commands) from the glibc package `python-glibc`, if some glibc package is being compiled.
- New variables have been implemented:
- `TERMUX_PYTHON_CROSSENV_BUILDHOME` - location of crossenv's python build libraries.
- `TERMUX_PKG_PYTHON_RUNTIME_DEPS` - configures the installation of the python modules via pip3 in the pkg's debscripts. If not configured in the package, it will use the value from `TERMUX_PKG_PYTHON_TARGET_DEPS`. If the variable is set to `false`, then the customization of installing python modules will be disabled, even if the `TERMUX_PKG_PYTHON_TARGET_DEPS` variable is set in the package.
- `TERMUX_SUBPKG_PYTHON_RUNTIME_DEPS` - configures the installation of the python modules via pip3 in the subpkg's debscripts.
- Implemented reconfiguration of prefixes in python module `sysconfig` and setting in `TERMUX_PYTHON_CROSSENV_BUILDHOME`, so that python modules from crossenv building can specify system paths of termux for correct compilation.
- Added automatic addition of `python-glibc{-glibc}` dependency when using the `TERMUX_PKG_PYTHON_RUNTIME_DEPS` (for pkg; will be disabled, i.e. will not be added, if the variable is set to `false`) or `TERMUX_SUBPKG_PYTHON_RUNTIME_DEPS` (for subpkg) value.
> How to add a new Python package after this?
Everything is the same, except, now, this block is no longer necessary in `build.sh`.
```bash
termux_step_create_debscripts() {
cat <<- EOF > ./postinst
#!$TERMUX_PREFIX/bin/sh
echo "Installing dependencies through pip..."
pip3 install ${TERMUX_PKG_PYTHON_TARGET_DEPS//, / }
EOF
}
```
- Instead, `scripts/build/termux_step_create_python_debscripts.sh` can now detect the presence of `pip` package lists in `$TERMUX_PKG_PYTHON_TARGET_DEPS`, `$TERMUX_SUBPKG_PYTHON_TARGET_DEPS`, and the `METADATA` file of the Python package if it exists, and automatically insert them as a block into the `postinst` script for all relevant packages.
- `$TERMUX_PKG_PYTHON_TARGET_DEPS` is used for `pip` dependencies that are both on-device build-time and on-device run-time dependencies, and `$TERMUX_PKG_PYTHON_RUNTIME_DEPS` is used for runtime-only `pip` dependencies. `$TERMUX_PKG_PYTHON_RUNTIME_DEPS` overrides `$TERMUX_PKG_PYTHON_TARGET_DEPS` for runtime dependencies,
- i.e. if `TERMUX_PKG_PYTHON_RUNTIME_DEPS` is not specified, but `TERMUX_PKG_PYTHON_TARGET_DEPS` is, then `TERMUX_PKG_PYTHON_TARGET_DEPS` will be used as both on-device build and on-device runtime dependencies,
- but if `TERMUX_PKG_PYTHON_RUNTIME_DEPS` is specified, then `TERMUX_PKG_PYTHON_TARGET_DEPS`, if specified, is used only for on-device build-time dependencies.
- If `python-pip` is not already in the dependencies of any package that needs it, the build will fail with an error instructing maintainers to add `python-pip` to the dependencies of the package that needs it.
Co-authored-by: Maxython <mixython@gmail.com>
87 lines
3.5 KiB
Bash
87 lines
3.5 KiB
Bash
TERMUX_PKG_HOMEPAGE=https://www.tensorflow.org/lite
|
|
TERMUX_PKG_DESCRIPTION="TensorFlow Lite Python bindings"
|
|
TERMUX_PKG_LICENSE="Apache-2.0"
|
|
TERMUX_PKG_MAINTAINER="@termux"
|
|
TERMUX_PKG_VERSION="2.20.0"
|
|
TERMUX_PKG_REVISION=1
|
|
TERMUX_PKG_SRCURL=git+https://github.com/tensorflow/tensorflow
|
|
TERMUX_PKG_AUTO_UPDATE=true
|
|
TERMUX_PKG_DEPENDS="python, python-numpy, python-pip"
|
|
TERMUX_PKG_UPDATE_TAG_TYPE="latest-release-tag"
|
|
TERMUX_PKG_PYTHON_COMMON_DEPS="setuptools, wheel, pybind11"
|
|
TERMUX_PKG_HOSTBUILD=true
|
|
TERMUX_PKG_EXTRA_CONFIGURE_ARGS="
|
|
-DCMAKE_POLICY_VERSION_MINIMUM=3.5
|
|
-DTFLITE_HOST_TOOLS_DIR=$TERMUX_PKG_HOSTBUILD_DIR
|
|
"
|
|
|
|
termux_step_host_build() {
|
|
termux_setup_cmake
|
|
|
|
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 "$TERMUX_PKG_SRCDIR"/tensorflow/lite
|
|
cmake --build . --verbose -j $TERMUX_PKG_MAKE_PROCESSES -t flatbuffers-flatc
|
|
}
|
|
|
|
termux_step_pre_configure() {
|
|
termux_setup_cmake
|
|
termux_setup_ninja
|
|
|
|
# Copied from tensorflow/lite/tools/pip_package/build_pip_package_with_cmake.sh
|
|
export TENSORFLOW_DIR="$TERMUX_PKG_SRCDIR"
|
|
local TENSORFLOW_LITE_DIR="$TENSORFLOW_DIR/tensorflow/lite"
|
|
local TENSORFLOW_VERSION=$(grep "TF_VERSION = " "${TENSORFLOW_DIR}/tensorflow/tf_version.bzl" | cut -d= -f2 | sed 's/[ "-]//g')
|
|
IFS='.' read -r -a array <<< "$TENSORFLOW_VERSION"
|
|
local TF_MAJOR=${array[0]}
|
|
local TF_MINOR=${array[1]}
|
|
local TF_PATCH=${array[2]}
|
|
local TF_CXX_FLAGS="-DTF_MAJOR_VERSION=${TF_MAJOR} -DTF_MINOR_VERSION=${TF_MINOR} -DTF_PATCH_VERSION=${TF_PATCH} -DTF_VERSION_SUFFIX=''"
|
|
export PACKAGE_VERSION="$TENSORFLOW_VERSION"
|
|
export PROJECT_NAME="tflite_runtime"
|
|
TFLITE_BUILD_DIR="$TERMUX_PKG_BUILDDIR/build-wheel"
|
|
local BUILD_DIR="$TFLITE_BUILD_DIR"
|
|
local PYTHON="$(command -v python)"
|
|
local PYBIND11_INCLUDE=$($PYTHON -c "import pybind11; print (pybind11.get_include())")
|
|
CPPFLAGS+=" -I$TERMUX_PYTHON_HOME/site-packages/numpy/_core/include"
|
|
CPPFLAGS+=" -I$PYBIND11_INCLUDE"
|
|
CPPFLAGS+=" -I$TERMUX_PREFIX/include/python$TERMUX_PYTHON_VERSION"
|
|
CPPFLAGS+=" $TF_CXX_FLAGS"
|
|
|
|
# Build source tree
|
|
rm -rf "$BUILD_DIR" && mkdir -p "$BUILD_DIR/tflite_runtime"
|
|
cp -r "$TENSORFLOW_LITE_DIR/tools/pip_package/debian" \
|
|
"$TENSORFLOW_LITE_DIR/tools/pip_package/MANIFEST.in" \
|
|
"$TENSORFLOW_LITE_DIR/python/interpreter_wrapper" \
|
|
"$BUILD_DIR"
|
|
cp "$TENSORFLOW_LITE_DIR/tools/pip_package/setup_with_binary.py" "$BUILD_DIR/setup.py"
|
|
cp "$TENSORFLOW_LITE_DIR/python/interpreter.py" \
|
|
"$TENSORFLOW_LITE_DIR/python/metrics/metrics_interface.py" \
|
|
"$TENSORFLOW_LITE_DIR/python/metrics/metrics_portable.py" \
|
|
"$BUILD_DIR/tflite_runtime"
|
|
echo "__version__ = '$PACKAGE_VERSION'" >> "$BUILD_DIR/tflite_runtime/__init__.py"
|
|
echo "__git_version__ = '$(git -C "$TENSORFLOW_DIR" describe)'" >> "$BUILD_DIR/tflite_runtime/__init__.py"
|
|
|
|
TERMUX_PKG_SRCDIR_OLD="$TERMUX_PKG_SRCDIR"
|
|
TERMUX_PKG_SRCDIR="$TERMUX_PKG_SRCDIR/tensorflow/lite"
|
|
}
|
|
|
|
termux_step_post_configure() {
|
|
TERMUX_PKG_SRCDIR="$TERMUX_PKG_SRCDIR_OLD"
|
|
}
|
|
|
|
termux_step_make() {
|
|
# Build python interpreter_wrapper
|
|
cmake --build . -j $TERMUX_PKG_MAKE_PROCESSES -t _pywrap_tensorflow_interpreter_wrapper
|
|
cp "$TERMUX_PKG_BUILDDIR/_pywrap_tensorflow_interpreter_wrapper.so" \
|
|
"$TFLITE_BUILD_DIR/tflite_runtime"
|
|
|
|
# Build python wheel
|
|
cd "$TFLITE_BUILD_DIR"
|
|
python setup.py bdist_wheel
|
|
}
|
|
|
|
termux_step_make_install() {
|
|
local _pyver="${TERMUX_PYTHON_VERSION//./}"
|
|
local _wheel="tflite_runtime-${TERMUX_PKG_VERSION}-cp${_pyver}-cp${_pyver}-linux_${TERMUX_ARCH}.whl"
|
|
pip install --force-reinstall --no-deps --prefix="$TERMUX_PREFIX" "$TFLITE_BUILD_DIR/dist/${_wheel}"
|
|
}
|