From patchwork Tue Aug 19 01:24:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 24161 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 8F6F9BDCC1 for ; Tue, 19 Aug 2025 01:24:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D7EFC6926B; Tue, 19 Aug 2025 03:24:31 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="mC/Lan3w"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7E2CE69265 for ; Tue, 19 Aug 2025 03:24:27 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id C3C39446; Tue, 19 Aug 2025 03:23:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1755566610; bh=FoV1eZQLOo1+3azC6yGFmYeK5O88hxR+Qgc+i0I/ySw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mC/Lan3wCbjNTedogO8wkvAwuO9C0oUxewGF6cdbWf6OdMROtlvoyf4WNC8eOxLaz zXFN8LvIPQw7JKS4XfXYcH8gbPxCX+JgQ04hxdiXx05cfmUxr7MDtthx3608HVUmZt PG3vFFtMHkzENsB/zfn2sgzgy3ZExMbuWeC6VK2Q= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: William Vinnicombe , Tomi Valkeinen Subject: [PATCH v3 2/3] py: libcamera: Get dependency from meson python module 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 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" libcamera uses the meson python module to handle native compilation of Python extension modules. When cross-compiling, the module uses the build machine suffix instead of the host machine suffix in some enviroments (for instance naming the shared object file _libcamera.cpython-313-x86_64-linux-gnu.so instead of _libcamera.cpython-313-aarch64-linux-gnu.so when cross-compiling from x86_64 to aarch64). This prevents using the python module in that case, and libcamera uses the normal dependency() function to locate the Python libraries, and the shared_module() function to build the module. Not using the meson python module to get the Python dependency prevents selecting a specific Python interpreter, the same way as it does for native builds. While having multiple Python interpreter versions in a cross-build environment is likely less common, different behaviours and features between native and cross-compilation are still not optimal. Improve this situation by getting the dependency from the python module for cross-compilation as well. This also prepares for usage of py.extension_module() once the file suffix issue will be fixed in meson. The user will need to ensure that the Python interpreter for the build machine matches the version of the interpreter in the cross-compilation environment for the host machine. Otherwise, meson will fail to find the Python dependency. Cross-compilation environment provided by Linux distributions (such as Debian multi-arch support) should work out of the box, but compiling libcamera manually against a cross-compilation environment provided by Buildroot or Yocto may require manual configuration. When the interpreters versions do not match, meson needs to be pointed to the build ùachine interpreter from the cross-compilation environment using the cross file. For instance, assuming a 'br_host_dir' variable pointing to the host directory from Buildroot, the cross file should contain [binaries] python = br_host_dir / 'bin/python3' Signed-off-by: Laurent Pinchart --- src/py/libcamera/meson.build | 4 ++-- src/py/meson.build | 16 +++------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build index fe22ffd2f70b..d5433fbc1e3a 100644 --- a/src/py/libcamera/meson.build +++ b/src/py/libcamera/meson.build @@ -47,7 +47,7 @@ pycamera_sources += custom_target('py_gen_formats', pycamera_deps = [ libcamera_private, - py3_dep, + py3.dependency(), pybind11_dep, ] @@ -62,7 +62,7 @@ if meson.is_cross_build() # module. There's work in progress to fix this, based on PEP 739 # (https://github.com/mesonbuild/meson/pull/14657). While waiting for this # to become available, work around the issue by using shared_module(). - destdir = get_option('libdir') / ('python' + py3_dep.version()) / 'site-packages' / 'libcamera' + destdir = get_option('libdir') / ('python' + py3.language_version()) / 'site-packages' / 'libcamera' pycamera = shared_module('_libcamera', pycamera_sources, diff --git a/src/py/meson.build b/src/py/meson.build index 24102f83d2e1..88ad8b7ec26e 100644 --- a/src/py/meson.build +++ b/src/py/meson.build @@ -1,20 +1,10 @@ # SPDX-License-Identifier: CC0-1.0 -if meson.is_cross_build() - py3_dep = dependency('python3', required : get_option('pycamera')) -else - py3 = import('python').find_installation('python3', required : get_option('pycamera')) - if not py3.found() - pycamera_enabled = false - subdir_done() - endif - - py3_dep = py3.dependency(required : get_option('pycamera')) -endif - +py_mod = import('python') +py3 = py_mod.find_installation('python3', required : get_option('pycamera')) pybind11_dep = dependency('pybind11', required : get_option('pycamera')) -pycamera_enabled = py3_dep.found() and pybind11_dep.found() +pycamera_enabled = py3.found() and pybind11_dep.found() if not pycamera_enabled subdir_done() endif