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

Chris Mayo aklhfex at gmail.com
Mon May 16 21:01:05 CEST 2022


> 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'

Still using the Meson python module as before.

> > -pycamera = shared_module('_libcamera',
> > -                         pycamera_sources,
> > -                         install : true,
> > -                         install_dir : destdir,
> > -                         name_prefix : '',
> > -                         dependencies : pycamera_deps,
> > -                         cpp_args : pycamera_args)
> > -
> > -run_command('ln', '-fsT', '../../../../src/py/libcamera/__init__.py',
> > -            meson.current_build_dir() / '__init__.py',
> > -            check: true)
>
> Was there a reason to remove this symlink? I want to be able to use the
> bindings without installing. That's the purpose of the symlink.

No, that's fine it doesn't cause any problems.

>   Tomi


On Mon, 16 May 2022 at 15:43, Tomi Valkeinen
<tomi.valkeinen at ideasonboard.com> 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')?
>
> > 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.
>
> > -pycamera = shared_module('_libcamera',
> > -                         pycamera_sources,
> > -                         install : true,
> > -                         install_dir : destdir,
> > -                         name_prefix : '',
> > -                         dependencies : pycamera_deps,
> > -                         cpp_args : pycamera_args)
> > -
> > -run_command('ln', '-fsT', '../../../../src/py/libcamera/__init__.py',
> > -            meson.current_build_dir() / '__init__.py',
> > -            check: true)
>
> Was there a reason to remove this symlink? I want to be able to use the
> bindings without installing. That's the purpose of the symlink.
>
>   Tomi


More information about the libcamera-devel mailing list