Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions pythonforandroid/recipes/tflite-runtime/__init__.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
;;
Expand All @@ -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}" \
Expand All @@ -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
Expand Down
Loading