From patchwork Thu Oct 26 12:50:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Vinnicombe X-Patchwork-Id: 19186 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 62184BDCBD for ; Thu, 26 Oct 2023 12:52:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DC6E66297C; Thu, 26 Oct 2023 14:52:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1698324752; bh=FdTsqbbXHuq8fqSQzmbFCKXnuh9m9Fkg9W+FXfUebQ4=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=JDGGj60CYS8Wai2tDeWBMYl4iUzmiD6sFoTvpKrLeUvaAfCiVV/xnpnBYT2crB8oG p6YFnJA9nSYnE5P3XNRFVNP9IBqd3oDiDTD9jjjN0nfnSfZDwuuJJ+htixEyKYVX2r 9eev+TCSfgzOJxQlmSURbma+WI3icDfwoHvXB9R9/MBd5199/SGeuYdXKOiEsobgHj fBbM6uEbYgZj47tRvxGHkcYKCXLwmrRTMlg2xOJenf1bwLv7Ov9PgHgzqtyVlcVWuP QPgL1IAYLFqZGLGLJNeXqY9x603kFXDXV0oSidDeLsKiDMAQYjQ4pvX1nKMFkTrUJQ UgblDU+zYel+g== Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9357E61DCC for ; Thu, 26 Oct 2023 14:52:31 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="Wr7k6omS"; dkim-atps=neutral Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-32dff202b4bso623742f8f.1 for ; Thu, 26 Oct 2023 05:52:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1698324751; x=1698929551; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=UIurfkBGZkCyTQeUFfkIh87rwmafCmjvJgYAehe87fc=; b=Wr7k6omSYveB8a4W/6/83j7PDsuhqtrlyRDIwAFV6JCoJTXZaD6X5OpFFx444Za9qD +e0Oicu5hqCjSKTXHDiMF5PF6asrzTx05FWOiWRPbc23+Wo4gD97QaHbecii8+yrsr1d NClKb84EnundYKdereGqXCMFqBWM77mohwnn+EVOgnkbIVjwDwTe0xiQxxYCLFAaKkmX mIu2/Y1Ju0UFUAD8Dc1q7vf6bVk5rp11+FAOp8V58kTUVTtOUUx2ivSLd6ku9HqDpTA+ xG3xj9r746ng2a4xaKgIz9HO7eyLJYi5sjYssg3Rx/LEks8Pjn6hfYeHPD3Ho1XgPiw9 fCHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698324751; x=1698929551; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=UIurfkBGZkCyTQeUFfkIh87rwmafCmjvJgYAehe87fc=; b=Z1Hc8Z4emUHDhdCaT19vW5U09I/KqITDJ039Q7ccAfIPnEeIaWgJK3is+OV1EDGk6o Eiz6yCkWftuthJKlSRtS2JLuqWF94tkaP30MHv3G5NhB+yiviLpdhcJnPdntZcMK+ZLd q/JC1lY3GgAQY6x9HA2VoBa2PBHaTe8EB591CaFRS4A2cGTppuPcCIMlZhjhcPTWloPT CC6HjeT6AjWvFyWxMDO3EqWZh754PWKUiFfRdCelYWyYyaprRvfB1bSmL17DUsiAfNQY DaVkoUUs2vmwwLrYQcVcfkt0nz7uTLgQR2+G0YwvSvg7AsQB5RYctYNSxUtw/255PJIy wLOw== X-Gm-Message-State: AOJu0Yxf63ppdeAuZlWPYCdc7AqWVCiGkx4QNc0659UabZZUjtrfbhOW BmkyVvSw1O/sK8qOvffeyM4IGatBo/4AzAqSu7bYTA== X-Google-Smtp-Source: AGHT+IGewhnOOGlILTjwtBIDAcMbdjRegaFiWjdUSXeP7DVdS6N5Ykdt/fZjd2VI6/hidFpfx7CaAA== X-Received: by 2002:a05:6000:4006:b0:32f:62d5:79f0 with SMTP id cp6-20020a056000400600b0032f62d579f0mr1439000wrb.48.1698324750558; Thu, 26 Oct 2023 05:52:30 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id f5-20020a056000128500b0032179c4a46dsm14125678wrx.100.2023.10.26.05.52.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 05:52:30 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 26 Oct 2023 13:50:38 +0100 Message-Id: <20231026125038.27985-1-william.vinnicombe@raspberrypi.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] py: libcamera: Improve python binding installation 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: , X-Patchwork-Original-From: William Vinnicombe via libcamera-devel From: William Vinnicombe Reply-To: William Vinnicombe Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The existing meson.build file installs the bindings to an architecture specific libdir (eg /usr/local/lib/aarch64-linux-gnu/), which is not picked up by default python which only looks in the non architecture specific libdir (eg /usr/local/lib/python3.11/). It also will always build using the system python, rather than building using the same python as meson is using. This prevents a user being able to build the bindings for a different version of python, without changing their system python to that version. Modify the build process to use the meson Python module to build the python bindings targets, so it installs them to the correct directories for python, and builds them for the version of python that meson is running with. For cross-compiling, still use the previous method to build the bindings, as the host machine version of python should be used instead. Signed-off-by: William Vinnicombe --- src/py/libcamera/meson.build | 60 +++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build index f58c7198..128793aa 100644 --- a/src/py/libcamera/meson.build +++ b/src/py/libcamera/meson.build @@ -1,10 +1,25 @@ # SPDX-License-Identifier: CC0-1.0 -py3_dep = dependency('python3', required : get_option('pycamera')) - -if not py3_dep.found() - pycamera_enabled = false - subdir_done() +if meson.is_cross_build() + py3_dep = dependency('python3', required : get_option('pycamera')) + + if not py3_dep.found() + pycamera_enabled = false + subdir_done() + endif +else + py = import('python').find_installation('python3', required : get_option('pycamera')) + + if not py.found() + pycamera_enabled = false + subdir_done() + else + py3_dep = py.dependency(required : get_option('pycamera')) + if not py3_dep.found() + pycamera_enabled = false + subdir_done() + endif + endif endif pybind11_dep = dependency('pybind11', required : get_option('pycamera')) @@ -78,15 +93,24 @@ pycamera_args = [ '-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT', ] -destdir = get_option('libdir') / ('python' + py3_dep.version()) / 'site-packages' / 'libcamera' - -pycamera = shared_module('_libcamera', - pycamera_sources, - install : true, - install_dir : destdir, - name_prefix : '', - dependencies : pycamera_deps, - cpp_args : pycamera_args) +if meson.is_cross_build() + destdir = get_option('libdir') / ('python' + py3_dep.version()) / 'site-packages' / 'libcamera' + + pycamera = shared_module('_libcamera', + pycamera_sources, + install : true, + install_dir : destdir, + name_prefix : '', + dependencies : pycamera_deps, + cpp_args : pycamera_args) +else + pycamera = py.extension_module('_libcamera', + pycamera_sources, + install : true, + subdir : 'libcamera', + dependencies : pycamera_deps, + cpp_args : pycamera_args) +endif # Create symlinks from the build dir to the source dir so that we can use the # Python module directly from the build dir. @@ -99,7 +123,13 @@ run_command('ln', '-fsrT', meson.current_source_dir() / 'utils', meson.current_build_dir() / 'utils', check : true) -install_data(['__init__.py'], install_dir : destdir) +if meson.is_cross_build() + install_data(['__init__.py'], install_dir : destdir) +else + py.install_sources(['__init__.py'], + subdir : 'libcamera', + pure : false) +endif # \todo Generate stubs when building. See https://peps.python.org/pep-0484/#stub-files # Note: Depends on pybind11-stubgen. To generate pylibcamera stubs: