[libcamera-devel] [PATCH] py: Use Meson python module

Tomi Valkeinen tomi.valkeinen at ideasonboard.com
Tue May 17 08:53:43 CEST 2022


On 16/05/2022 22:01, Chris Mayo wrote:
>> Hi,
>>
>> On 15/05/2022 20:02, Chris Mayo via libcamera-devel wrote:
>>> Detection with dependency('python3') can fail because not all
>>> distributions install python-3.pc. Installation is invalid if
>>> site-packages is not below get_option('libdir').
>>
>> I don't understand the comment about libdir. Do you mean that this
>> installs to the wrong dir if the platform's python site-packages are not
>> located under get_option('libdir')?
> 
> Yes. On Gentoo Linux:
> 
> /usr/lib/python3.10/site-packages/libcamera
> 
> and:
> 
> /usr/lib64/libcamera.so
> 
>>> Signed-off-by: Chris Mayo <aklhfex at gmail.com>
>>> ---
>>>    src/py/libcamera/meson.build | 27 ++++++++++++---------------
>>>    1 file changed, 12 insertions(+), 15 deletions(-)
>>>
>>> diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build
>>> index 0cd7c75b..130c1be6 100644
>>> --- a/src/py/libcamera/meson.build
>>> +++ b/src/py/libcamera/meson.build
>>> @@ -1,6 +1,8 @@
>>>    # SPDX-License-Identifier: CC0-1.0
>>>
>>> -py3_dep = dependency('python3', required : get_option('pycamera'))
>>> +pymod = import('python')
>>> +py3 = pymod.find_installation('python3')
>>> +py3_dep = py3.dependency(required : get_option('pycamera'))
>>>
>>>    if not py3_dep.found()
>>>        pycamera_enabled = false
>>> @@ -44,21 +46,16 @@ pycamera_args = [
>>>        '-DLIBCAMERA_BASE_PRIVATE',
>>>    ]
>>>
>>> -destdir = get_option('libdir') / ('python' + py3_dep.version()) / 'site-packages' / 'libcamera'
>>> +py3.extension_module('_libcamera',
>>> +                     pycamera_sources,
>>> +                     install : true,
>>> +                     dependencies : pycamera_deps,
>>> +                     cpp_args : pycamera_args,
>>> +                     subdir : 'libcamera')
>>
>> The problem is that this doesn't work with cross-compiling. When I
>> compile for ARM, I get "_libcamera.cpython-310-x86_64-linux-gnu.so".
>>
>> If I remember right, I discussed the use of py.extension_module() on
>> meson chat, but the conclusion was that it doesn't work for
>> cross-compiling. This may have changed, but at least here it doesn't work.
> 
> OK. Instead of using py.extension_module() this works for me:
> 
> destdir = py3.get_install_dir() / 'libcamera'

For me, when not cross-compiling, py3.get_install_dir() returns 
"/usr/local/lib/python3/dist-packages/". Afaics, that is not correct, as 
"python3 -m site" doesn't contain that dir, but does contain, e.g. :

     '/usr/local/lib/python3.10/dist-packages',
     '/usr/lib/python3/dist-packages',

When I cross-compile, py3.get_install_dir() again returns the same path 
hinting that the py3 is really the host python (as also indicated by the 
module name). On my ARM device, "python3 -m site" returns 
'/usr/lib/python3.10/site-packages'.

So... the meson python module just seems to be totally broken. Or I'm 
somehow confused. I admit I know quite little about Python installations.

  Tomi


More information about the libcamera-devel mailing list