{"id":24161,"url":"https://patchwork.libcamera.org/api/1.1/patches/24161/?format=json","web_url":"https://patchwork.libcamera.org/patch/24161/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20250819012402.8395-3-laurent.pinchart@ideasonboard.com>","date":"2025-08-19T01:24:00","name":"[v3,2/3] py: libcamera: Get dependency from meson python module unconditionally","commit_ref":"a2b21d60c7bf1d4539da89aaca49b5575e8a4549","pull_url":null,"state":"accepted","archived":false,"hash":"38862552a11e8350cf2d9d43e29832392e4c74e5","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/24161/mbox/","series":[{"id":5393,"url":"https://patchwork.libcamera.org/api/1.1/series/5393/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5393","date":"2025-08-19T01:23:58","name":"py: Improve native and cross-compilation of Python bindings","version":3,"mbox":"https://patchwork.libcamera.org/series/5393/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/24161/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/24161/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 8F6F9BDCC1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 19 Aug 2025 01:24:32 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D7EFC6926B;\n\tTue, 19 Aug 2025 03:24:31 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7E2CE69265\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 19 Aug 2025 03:24:27 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id C3C39446;\n\tTue, 19 Aug 2025 03:23:29 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"mC/Lan3w\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1755566610;\n\tbh=FoV1eZQLOo1+3azC6yGFmYeK5O88hxR+Qgc+i0I/ySw=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=mC/Lan3wCbjNTedogO8wkvAwuO9C0oUxewGF6cdbWf6OdMROtlvoyf4WNC8eOxLaz\n\tzXFN8LvIPQw7JKS4XfXYcH8gbPxCX+JgQ04hxdiXx05cfmUxr7MDtthx3608HVUmZt\n\tPG3vFFtMHkzENsB/zfn2sgzgy3ZExMbuWeC6VK2Q=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"William Vinnicombe <william.vinnicombe@raspberrypi.com>,\n\tTomi Valkeinen <tomi.valkeinen@ideasonboard.com>","Subject":"[PATCH v3 2/3] py: libcamera: Get dependency from meson python\n\tmodule unconditionally","Date":"Tue, 19 Aug 2025 04:24:00 +0300","Message-ID":"<20250819012402.8395-3-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.49.1","In-Reply-To":"<20250819012402.8395-1-laurent.pinchart@ideasonboard.com>","References":"<20250819012402.8395-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"libcamera uses the meson python module to handle native compilation of\nPython extension modules.\n\nWhen cross-compiling, the module uses the build machine suffix instead\nof the host machine suffix in some enviroments (for instance naming the\nshared object file _libcamera.cpython-313-x86_64-linux-gnu.so instead of\n_libcamera.cpython-313-aarch64-linux-gnu.so when cross-compiling from\nx86_64 to aarch64). This prevents using the python module in that case,\nand libcamera uses the normal dependency() function to locate the Python\nlibraries, and the shared_module() function to build the module.\n\nNot using the meson python module to get the Python dependency prevents\nselecting a specific Python interpreter, the same way as it does for\nnative builds. While having multiple Python interpreter versions in a\ncross-build environment is likely less common, different behaviours and\nfeatures between native and cross-compilation are still not optimal.\n\nImprove this situation by getting the dependency from the python module\nfor cross-compilation as well. This also prepares for usage of\npy.extension_module() once the file suffix issue will be fixed in meson.\n\nThe user will need to ensure that the Python interpreter for the build\nmachine matches the version of the interpreter in the cross-compilation\nenvironment for the host machine. Otherwise, meson will fail to find the\nPython dependency. Cross-compilation environment provided by Linux\ndistributions (such as Debian multi-arch support) should work out of the\nbox, but compiling libcamera manually against a cross-compilation\nenvironment provided by Buildroot or Yocto may require manual\nconfiguration.\n\nWhen the interpreters versions do not match, meson needs to be pointed\nto the build ùachine interpreter from the cross-compilation environment\nusing the cross file. For instance, assuming a 'br_host_dir' variable\npointing to the host directory from Buildroot, the cross file should\ncontain\n\n[binaries]\npython = br_host_dir / 'bin/python3'\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/py/libcamera/meson.build |  4 ++--\n src/py/meson.build           | 16 +++-------------\n 2 files changed, 5 insertions(+), 15 deletions(-)","diff":"diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build\nindex fe22ffd2f70b..d5433fbc1e3a 100644\n--- a/src/py/libcamera/meson.build\n+++ b/src/py/libcamera/meson.build\n@@ -47,7 +47,7 @@ pycamera_sources += custom_target('py_gen_formats',\n \n pycamera_deps = [\n     libcamera_private,\n-    py3_dep,\n+    py3.dependency(),\n     pybind11_dep,\n ]\n \n@@ -62,7 +62,7 @@ if meson.is_cross_build()\n     # module. There's work in progress to fix this, based on PEP 739\n     # (https://github.com/mesonbuild/meson/pull/14657). While waiting for this\n     # to become available, work around the issue by using shared_module().\n-    destdir = get_option('libdir') / ('python' + py3_dep.version()) / 'site-packages' / 'libcamera'\n+    destdir = get_option('libdir') / ('python' + py3.language_version()) / 'site-packages' / 'libcamera'\n \n     pycamera = shared_module('_libcamera',\n                              pycamera_sources,\ndiff --git a/src/py/meson.build b/src/py/meson.build\nindex 24102f83d2e1..88ad8b7ec26e 100644\n--- a/src/py/meson.build\n+++ b/src/py/meson.build\n@@ -1,20 +1,10 @@\n # SPDX-License-Identifier: CC0-1.0\n \n-if meson.is_cross_build()\n-    py3_dep = dependency('python3', required : get_option('pycamera'))\n-else\n-    py3 = import('python').find_installation('python3', required : get_option('pycamera'))\n-    if not py3.found()\n-        pycamera_enabled = false\n-        subdir_done()\n-    endif\n-\n-    py3_dep = py3.dependency(required : get_option('pycamera'))\n-endif\n-\n+py_mod = import('python')\n+py3 = py_mod.find_installation('python3', required : get_option('pycamera'))\n pybind11_dep = dependency('pybind11', required : get_option('pycamera'))\n \n-pycamera_enabled = py3_dep.found() and pybind11_dep.found()\n+pycamera_enabled = py3.found() and pybind11_dep.found()\n if not pycamera_enabled\n     subdir_done()\n endif\n","prefixes":["v3","2/3"]}