Skip to content

Commit 17ba878

Browse files
authored
Merge pull request kivy#3310 from lazycat11/fix-tflite-runtime-numpy-include
Fix tflite-runtime numpy include path
2 parents 8b12ed5 + 375c20d commit 17ba878

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

pythonforandroid/recipes/tflite-runtime/__init__.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from pythonforandroid.recipe import PythonRecipe, current_directory, \
22
shprint, info_main, warning
33
from pythonforandroid.logger import error
4-
from os.path import join
4+
from os.path import exists, join
55
import sh
66

77

@@ -25,7 +25,8 @@ class TFLiteRuntimeRecipe(PythonRecipe):
2525

2626
version = '2.8.0'
2727
url = 'https://github.com/tensorflow/tensorflow/archive/refs/tags/v{version}.zip'
28-
depends = ['pybind11', 'numpy']
28+
depends = ['numpy']
29+
hostpython_prerequisites = ['pybind11==2.11.1']
2930
patches = ['CMakeLists.patch', 'build_with_cmake.patch']
3031
site_packages_name = 'tflite-runtime'
3132
call_hostpython_via_targetpython = False
@@ -49,6 +50,7 @@ def build_arch(self, arch):
4950
return
5051

5152
env = self.get_recipe_env(arch)
53+
self.install_hostpython_prerequisites()
5254

5355
# Directories
5456
root_dir = self.get_build_dir(arch.arch)
@@ -58,10 +60,14 @@ def build_arch(self, arch):
5860

5961
# Includes
6062
python_include_dir = self.ctx.python_recipe.include_root(arch.arch)
61-
pybind11_recipe = self.get_recipe('pybind11', self.ctx)
62-
pybind11_include_dir = pybind11_recipe.get_include_dir(arch)
63+
pybind11_include_dir = sh.Command(self.real_hostpython_location)(
64+
'-c', 'import pybind11; print(pybind11.get_include())'
65+
).strip()
6366
numpy_include_dir = join(self.ctx.get_site_packages_dir(arch),
64-
'numpy', 'core', 'include')
67+
'numpy', '_core', 'include')
68+
if not exists(numpy_include_dir):
69+
numpy_include_dir = join(self.ctx.get_site_packages_dir(arch),
70+
'numpy', 'core', 'include')
6571
includes = ' -I' + python_include_dir + \
6672
' -I' + numpy_include_dir + \
6773
' -I' + pybind11_include_dir
@@ -81,6 +87,7 @@ def build_arch(self, arch):
8187
'ANDROID_ABI': arch.arch,
8288
'WRAPPER_INCLUDES': includes,
8389
'CMAKE_SHARED_LINKER_FLAGS': env['LDFLAGS'],
90+
'CMAKE_POLICY_VERSION_MINIMUM': '3.5',
8491
})
8592

8693
try:

pythonforandroid/recipes/tflite-runtime/build_with_cmake.patch

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
# Build python interpreter_wrapper.
2020
mkdir -p "${BUILD_DIR}/cmake_build"
21-
@@ -111,6 +111,18 @@
21+
@@ -111,6 +111,19 @@
2222
-DCMAKE_CXX_FLAGS="${BUILD_FLAGS}" \
2323
"${TENSORFLOW_LITE_DIR}"
2424
;;
@@ -29,6 +29,7 @@
2929
+ -DANDROID_ARM_NEON=ON \
3030
+ -DCMAKE_CXX_FLAGS="${BUILD_FLAGS}" \
3131
+ -DCMAKE_SHARED_LINKER_FLAGS="${CMAKE_SHARED_LINKER_FLAGS}" \
32+
+ -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
3233
+ -DCMAKE_TOOLCHAIN_FILE="${CMAKE_TOOLCHAIN_FILE}" \
3334
+ -DANDROID_PLATFORM="${ANDROID_PLATFORM}" \
3435
+ -DANDROID_ABI="${ANDROID_ABI}" \
@@ -37,7 +38,7 @@
3738
*)
3839
BUILD_FLAGS=${BUILD_FLAGS:-"-I${PYTHON_INCLUDE} -I${PYBIND11_INCLUDE}"}
3940
cmake \
40-
@@ -162,7 +174,7 @@
41+
@@ -162,7 +175,7 @@
4142
${PYTHON} setup.py bdist --plat-name=${WHEEL_PLATFORM_NAME} \
4243
bdist_wheel --plat-name=${WHEEL_PLATFORM_NAME}
4344
else

0 commit comments

Comments
 (0)