<div dir="ltr"><div>Could I request some reviews on this V2 of my python patch? It should now work with cross-compilation, as it still uses the old method for building the bindings when cross-compiling.</div><div><br></div><div>Thanks,</div><div>William</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 26 Oct 2023 at 13:52, William Vinnicombe <<a href="mailto:william.vinnicombe@raspberrypi.com">william.vinnicombe@raspberrypi.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">The existing meson.build file installs the bindings to an architecture<br>
specific libdir (eg /usr/local/lib/aarch64-linux-gnu/), which is not<br>
picked up by default python which only looks in the non architecture<br>
specific libdir (eg /usr/local/lib/python3.11/). It also will always<br>
build using the system python, rather than building using the same<br>
python as meson is using. This prevents a user being able to build the<br>
bindings for a different version of python, without changing their<br>
system python to that version.<br>
<br>
Modify the build process to use the meson Python module to build the<br>
python bindings targets, so it installs them to the correct directories<br>
for python, and builds them for the version of python that meson is<br>
running with. For cross-compiling, still use the previous method to<br>
build the bindings, as the host machine version of python should be<br>
used instead.<br>
<br>
Signed-off-by: William Vinnicombe <<a href="mailto:william.vinnicombe@raspberrypi.com" target="_blank">william.vinnicombe@raspberrypi.com</a>><br>
---<br>
 src/py/libcamera/meson.build | 60 +++++++++++++++++++++++++++---------<br>
 1 file changed, 45 insertions(+), 15 deletions(-)<br>
<br>
diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build<br>
index f58c7198..128793aa 100644<br>
--- a/src/py/libcamera/meson.build<br>
+++ b/src/py/libcamera/meson.build<br>
@@ -1,10 +1,25 @@<br>
 # SPDX-License-Identifier: CC0-1.0<br>
<br>
-py3_dep = dependency('python3', required : get_option('pycamera'))<br>
-<br>
-if not py3_dep.found()<br>
-    pycamera_enabled = false<br>
-    subdir_done()<br>
+if meson.is_cross_build()<br>
+    py3_dep = dependency('python3', required : get_option('pycamera'))<br>
+<br>
+    if not py3_dep.found()<br>
+        pycamera_enabled = false<br>
+        subdir_done()<br>
+    endif<br>
+else<br>
+    py = import('python').find_installation('python3', required : get_option('pycamera'))<br>
+<br>
+    if not py.found()<br>
+        pycamera_enabled = false<br>
+        subdir_done()<br>
+    else<br>
+        py3_dep = py.dependency(required : get_option('pycamera'))<br>
+        if not py3_dep.found()<br>
+            pycamera_enabled = false<br>
+            subdir_done()<br>
+        endif<br>
+    endif<br>
 endif<br>
<br>
 pybind11_dep = dependency('pybind11', required : get_option('pycamera'))<br>
@@ -78,15 +93,24 @@ pycamera_args = [<br>
     '-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT',<br>
 ]<br>
<br>
-destdir = get_option('libdir') / ('python' + py3_dep.version()) / 'site-packages' / 'libcamera'<br>
-<br>
-pycamera = shared_module('_libcamera',<br>
-                         pycamera_sources,<br>
-                         install : true,<br>
-                         install_dir : destdir,<br>
-                         name_prefix : '',<br>
-                         dependencies : pycamera_deps,<br>
-                         cpp_args : pycamera_args)<br>
+if meson.is_cross_build()<br>
+    destdir = get_option('libdir') / ('python' + py3_dep.version()) / 'site-packages' / 'libcamera'<br>
+<br>
+    pycamera = shared_module('_libcamera',<br>
+                             pycamera_sources,<br>
+                             install : true,<br>
+                             install_dir : destdir,<br>
+                             name_prefix : '',<br>
+                             dependencies : pycamera_deps,<br>
+                             cpp_args : pycamera_args)<br>
+else<br>
+    pycamera = py.extension_module('_libcamera',<br>
+                                   pycamera_sources,<br>
+                                   install : true,<br>
+                                   subdir : 'libcamera',<br>
+                                   dependencies : pycamera_deps,<br>
+                                   cpp_args : pycamera_args)<br>
+endif<br>
<br>
 # Create symlinks from the build dir to the source dir so that we can use the<br>
 # Python module directly from the build dir.<br>
@@ -99,7 +123,13 @@ run_command('ln', '-fsrT', meson.current_source_dir() / 'utils',<br>
             meson.current_build_dir() / 'utils',<br>
             check : true)<br>
<br>
-install_data(['__init__.py'], install_dir : destdir)<br>
+if meson.is_cross_build()<br>
+    install_data(['__init__.py'], install_dir : destdir)<br>
+else<br>
+    py.install_sources(['__init__.py'],<br>
+                       subdir : 'libcamera',<br>
+                       pure : false)<br>
+endif<br>
<br>
 # \todo Generate stubs when building. See <a href="https://peps.python.org/pep-0484/#stub-files" rel="noreferrer" target="_blank">https://peps.python.org/pep-0484/#stub-files</a><br>
 # Note: Depends on pybind11-stubgen. To generate pylibcamera stubs:<br>
-- <br>
2.39.2<br>
<br>
</blockquote></div></div>