diff --git a/pythonforandroid/recipes/tflite-runtime/__init__.py b/pythonforandroid/recipes/tflite-runtime/__init__.py index 1d208866c2..952782dfb9 100644 --- a/pythonforandroid/recipes/tflite-runtime/__init__.py +++ b/pythonforandroid/recipes/tflite-runtime/__init__.py @@ -1,7 +1,7 @@ from pythonforandroid.recipe import PythonRecipe, current_directory, \ shprint, info_main, warning from pythonforandroid.logger import error -from os.path import join +from os.path import exists, join import sh @@ -25,7 +25,8 @@ class TFLiteRuntimeRecipe(PythonRecipe): version = '2.8.0' url = 'https://github.com/tensorflow/tensorflow/archive/refs/tags/v{version}.zip' - depends = ['pybind11', 'numpy'] + depends = ['numpy'] + hostpython_prerequisites = ['pybind11==2.11.1'] patches = ['CMakeLists.patch', 'build_with_cmake.patch'] site_packages_name = 'tflite-runtime' call_hostpython_via_targetpython = False @@ -49,6 +50,7 @@ def build_arch(self, arch): return env = self.get_recipe_env(arch) + self.install_hostpython_prerequisites() # Directories root_dir = self.get_build_dir(arch.arch) @@ -58,10 +60,14 @@ def build_arch(self, arch): # Includes python_include_dir = self.ctx.python_recipe.include_root(arch.arch) - pybind11_recipe = self.get_recipe('pybind11', self.ctx) - pybind11_include_dir = pybind11_recipe.get_include_dir(arch) + pybind11_include_dir = sh.Command(self.real_hostpython_location)( + '-c', 'import pybind11; print(pybind11.get_include())' + ).strip() numpy_include_dir = join(self.ctx.get_site_packages_dir(arch), - 'numpy', 'core', 'include') + 'numpy', '_core', 'include') + if not exists(numpy_include_dir): + numpy_include_dir = join(self.ctx.get_site_packages_dir(arch), + 'numpy', 'core', 'include') includes = ' -I' + python_include_dir + \ ' -I' + numpy_include_dir + \ ' -I' + pybind11_include_dir @@ -81,6 +87,7 @@ def build_arch(self, arch): 'ANDROID_ABI': arch.arch, 'WRAPPER_INCLUDES': includes, 'CMAKE_SHARED_LINKER_FLAGS': env['LDFLAGS'], + 'CMAKE_POLICY_VERSION_MINIMUM': '3.5', }) try: diff --git a/pythonforandroid/recipes/tflite-runtime/build_with_cmake.patch b/pythonforandroid/recipes/tflite-runtime/build_with_cmake.patch index 9670e1865f..e2678bef3d 100644 --- a/pythonforandroid/recipes/tflite-runtime/build_with_cmake.patch +++ b/pythonforandroid/recipes/tflite-runtime/build_with_cmake.patch @@ -18,7 +18,7 @@ # Build python interpreter_wrapper. mkdir -p "${BUILD_DIR}/cmake_build" -@@ -111,6 +111,18 @@ +@@ -111,6 +111,19 @@ -DCMAKE_CXX_FLAGS="${BUILD_FLAGS}" \ "${TENSORFLOW_LITE_DIR}" ;; @@ -29,6 +29,7 @@ + -DANDROID_ARM_NEON=ON \ + -DCMAKE_CXX_FLAGS="${BUILD_FLAGS}" \ + -DCMAKE_SHARED_LINKER_FLAGS="${CMAKE_SHARED_LINKER_FLAGS}" \ ++ -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \ + -DCMAKE_TOOLCHAIN_FILE="${CMAKE_TOOLCHAIN_FILE}" \ + -DANDROID_PLATFORM="${ANDROID_PLATFORM}" \ + -DANDROID_ABI="${ANDROID_ABI}" \ @@ -37,7 +38,7 @@ *) BUILD_FLAGS=${BUILD_FLAGS:-"-I${PYTHON_INCLUDE} -I${PYBIND11_INCLUDE}"} cmake \ -@@ -162,7 +174,7 @@ +@@ -162,7 +175,7 @@ ${PYTHON} setup.py bdist --plat-name=${WHEEL_PLATFORM_NAME} \ bdist_wheel --plat-name=${WHEEL_PLATFORM_NAME} else