From: "Andrew Jeffery" <andrew@aj.id.au>
To: "Bartosz Golaszewski" <brgl@bgdev.pl>
Cc: "Viresh Kumar" <viresh.kumar@linaro.org>,
"Kent Gibson" <warthog618@gmail.com>,
"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
"Linus Walleij" <linus.walleij@linaro.org>,
linux-gpio@vger.kernel.org
Subject: Re: [libgpiod][WIP PATCH 0/2] Convert the build from autotools to meson
Date: Fri, 09 Dec 2022 08:21:00 +1030 [thread overview]
Message-ID: <38927236-d8b5-42fb-b867-5d761dc8afb6@app.fastmail.com> (raw)
In-Reply-To: <CAMRc=MfzNG-WzEox6Rb7QpFVP4mF_pkw2earWbjuKjCHu9eBuQ@mail.gmail.com>
On Fri, 9 Dec 2022, at 05:18, Bartosz Golaszewski wrote:
> On Thu, Dec 8, 2022 at 12:11 PM Andrew Jeffery <andrew@aj.id.au> wrote:
>>
>>
>>
>> On Thu, 8 Dec 2022, at 19:57, Bartosz Golaszewski wrote:
>> > On Thu, Dec 8, 2022 at 5:23 AM Andrew Jeffery <andrew@aj.id.au> wrote:
>> >>
>> >>
>> >>
>> >> On Tue, 6 Dec 2022, at 05:25, Bartosz Golaszewski wrote:
>> >> > On Mon, Dec 5, 2022 at 2:22 PM Andrew Jeffery <andrew@aj.id.au> wrote:
>> >> >>
>> >> >> Hello,
>> >> >>
>> >> >> Based on a recent poke [1] and in-between meetings I've put together a
>> >> >> WIP series that converts libgpiod's build from autotools to meson. As
>> >> >> far as I'm aware the meson build supports all the significant options to
>> >> >> enable or disable features exposed by the autotools build:
>> >> >>
>> >> >> * Tests
>> >> >> * Tools
>> >> >> * Interactive gpioset
>> >> >> * Bindings
>> >> >> * C++
>> >> >> * Python
>> >> >> * Rust
>> >> >> * Documentation
>> >> >> * Manpages
>> >> >> * Doxygen
>> >> >>
>> >> >> [1] https://lore.kernel.org/all/CAMRc=Mda8UnyH+_GxeX_4MyKd+DPN0BVH5K+J+VWnMJNC1vwTQ@mail.gmail.com/
>> >> >>
>> >> >> Meson has pretty good support for handling python and so the patch does
>> >> >> away with setup.py entirely.
>> >> >
>> >> > Eek! No, please do keep setup.py. Autotools too is capable of building
>> >> > python C extensions on its own and it's what we use in v1 but I want
>> >> > the python code to be built the standard python way. I actually plan
>> >> > to post libgpiod v2 on pypi and split out building python bindings
>> >> > into a separate bitbake recipe in meta-openembedded using the
>> >> > setuptools3 class.
>> >> >
>> >> > So let's keep setup.py and just call it from meson.
>> >>
>> >> I've poked at this for a little while and it's not a great experience.
>> >> Meson's design pushes back against calling out in this way, and I don't
>> >> really have the motivation to carry on fighting it to make it do what
>> >> you request. Unless someone else has that motivation, I think there are
>> >> two options if meson is still desired:
>> >>
>> >> 1. Use the meson python support as posted in this series
>> >> 2. Split out the python (and probably rust) bindings, keeping the
>> >> dependency relationships pointing in one direction and using the
>> >> language's own package management tooling.
>> >>
>> >> Given there's nothing to do in the install phase for rust we don't have
>> >> as big of an issue there, but it is problematic for python.
>> >>
>> >> Let me know which way you want to go, including if you want to abandon
>> >> meson :)
>> >>
>> >
>> > No, I don't want to abandon it. What is the problem exactly? Is meson
>> > unable to simply add external commands to its ninja output?
>>
>> Not as far as I'm aware. I think it's best covered by this policy
>> description:
>>
>> https://mesonbuild.com/Mixing-build-systems.html
>>
>> There are some things that might make it sound feasible but aren't
>> actually appropriate:
>>
>> 1. run_command(): https://mesonbuild.com/Reference-manual_functions.html#run_command
>> 2. run_target(): https://mesonbuild.com/Reference-manual_functions.html#run_target
>> 3. custom_target(): https://mesonbuild.com/Reference-manual_functions.html#custom_target
>>
>> run_command() isn't appropriate as it executes in the `meson setup`
>> phase. run_target() isn't appropriate as it disregards any output
>> artifacts and so has no impact in the `meson install` phase.
>>
>> custom_target() is probably closest to what is required, but there's a
>> lot of pain in trying to get the artifacts to line up for correct
>> deployment in the `meson install` phase. This is exacerbated by the
>> requirement that setup.py be run from its containing directory in the
>> source tree. Further, I couldn't get all the options to line up such
>> that setuptools would relocate its output into meson's own build tree
>> (and out of the source tree). Here's a not entirely working attempt at
>> abusing custom_target() to that end:
>>
>> ```
>> diff --git a/bindings/python/meson.build b/bindings/python/meson.build
>> index 26f7ff13e0dd..136d10824345 100644
>> --- a/bindings/python/meson.build
>> +++ b/bindings/python/meson.build
>> @@ -3,14 +3,31 @@
>>
>> python = import('python')
>> python3 = python.find_installation('python3')
>> -python3_dep = python3.dependency()
>>
>> -subdir('gpiod')
>> +python_build_dir = 'python-build'
>> +python_install_dir = 'python-install'
>> +python_include_dirs = '../../include:../../tests/gpiosim'
>> +python_lib_dirs = '@0@/lib:@0@/tests/gpiosim'.format(meson.project_build_root())
>> +python_install_cmd = [ python3.full_path(), '@INPUT@', '--no-user-cfg',
>> + 'build_ext', '--include-dirs', python_include_dirs, '--library-dirs', python_lib_dirs,
>> + 'install', '--root', python_build_dir, '--prefix', get_option('prefix')]
>>
>> -if get_option('examples')
>> - subdir('examples')
>> -endif
>> +python_env = environment()
>> +python_env.set('GPIOD_WITH_TESTS', get_option('tests').to_string())
>>
>> -if get_option('tests')
>> - subdir('tests')
>> -endif
>> +python_setuptools = custom_target('python-setuptools',
>> + input: 'setup.py',
>> + output: python_build_dir,
>> + depends: [gpiod, gpiosim],
>> + env: python_env,
>> + command: python_install_cmd)
>> +
>> +cp = find_program('cp')
>> +
>> +custom_target('python-install',
>> + input: 'setup.py',
>> + output: python_install_dir,
>> + depends: python_setuptools,
>> + command: [ cp, '-r', meson.current_source_dir() / python_build_dir, meson.current_build_dir() / python_install_dir ],
>> + install: true,
>> + install_dir: get_option('prefix'))
>> diff --git a/bindings/python/setup.py b/bindings/python/setup.py
>> index ec8f99d4013d..9eddae7466a1 100644
>> --- a/bindings/python/setup.py
>> +++ b/bindings/python/setup.py
>> @@ -1,9 +1,14 @@
>> # SPDX-License-Identifier: GPL-2.0-or-later
>> # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
>>
>> -from os import environ
>> +import os
>> +import sys
>> +
>> +from os import environ, path
>> from setuptools import setup, Extension, find_packages
>>
>> +os.chdir(path.dirname(sys.argv[0]) or '.')
>> +
>> gpiod_ext = Extension(
>> "gpiod._ext",
>> sources=[
>> ```
>>
>> This commits a bunch of crimes:
>>
>> 1. Assumes the structure of the meson build directory via the paths in
>> python_lib_dirs
>> 2. Adds a chdir() in setup.py to relocate the process out of the meson
>> build directory back into the source tree
>> 3. Assumes the chdir() operation in the setup of python_include_dirs
>> rather than relying on meson's built-in dependency tracking as the
>> inc objects are opaque[1]
>> 4. Hacks the setuptools output back into the meson build directory using
>> a crufty target invoking `cp` so meson can locate the artifacts in the
>> `meson install` phase
>> 5. Still doesn't correctly install the artifacts in the end due to
>> restrictions on path mangling (can't strip off the parent directory)
>> and the fact that we're trying to install an entire tree rather than
>> specific files.
>>
>> [1] https://mesonbuild.com/Reference-manual_returned_inc.html
>>
>> It might feel like install_data() or install_subdir() could be used
>> here, but from experiment their behaviour also seems unfit to be used
>> in this context.
>>
>> At least, that's what I've experimented with. Maybe others can see the
>> way through here, but it really is fighting against the policy linked
>> earlier.
>>
>> Andrew
>
> I see. I understand that meson doesn't like dealing with other build-systems.
>
> The thing I like about the current autotools setup is that with the
> following one-liner:
>
> ./autogen.sh --prefix=/tmp/gpio/inst --enable-bindings-cxx
> --enable-examples --enable-tests --enable-tools
> --enable-gpioset-interactive --enable-bindings-python
> --enable-bindings-rust && make -j16 && sudo ./tests/gpiod-test && sudo
> ./bindings/cxx/tests/gpiod-cxx-test && sudo
> PYTHONPATH=./bindings/python
> LD_LIBRARY_PATH=./lib/.libs/:./tests/gpiosim/.libs/:bindings/python/
> python -B -m tests && cd bindings/rust/; sudo
> CARGO_TARGET_DIR=/tmp/libgpiod-rust PATH=/home/brgl/.cargo/bin/:$PATH
> /home/brgl/.cargo/bin/cargo test; cd ../.. && sudo
> ./tools/gpio-tools-test
>
> I can configure, build and test the entire code base while also using
> the language specific build tools for python and rust.
Right; I agree it's desirable to retain that capability.
>
> I will try to play with your patches and maybe figure it out or even a
> close approximation of the current functionality but then again: I'm
> not well versed with meson yet. Between it and rust and dayjob my cup
> runneth over...
I recognise that feeling :)
Happy to bounce ideas around if you experiment with it.
Andrew
prev parent reply other threads:[~2022-12-08 21:51 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-05 13:22 [libgpiod][WIP PATCH 0/2] Convert the build from autotools to meson Andrew Jeffery
2022-12-05 13:22 ` [libgpiod][WIP PATCH 1/2] Introduce meson as a build system Andrew Jeffery
2022-12-05 13:22 ` [libgpiod][WIP PATCH 2/2] Remove autotools in favour of meson Andrew Jeffery
2022-12-05 18:55 ` [libgpiod][WIP PATCH 0/2] Convert the build from autotools to meson Bartosz Golaszewski
2022-12-05 23:42 ` Andrew Jeffery
2022-12-06 0:06 ` Viresh Kumar
2022-12-06 0:26 ` Andrew Jeffery
2022-12-06 3:40 ` Viresh Kumar
2022-12-06 3:54 ` Kent Gibson
2022-12-06 12:15 ` Miguel Ojeda
2022-12-06 14:54 ` Andy Shevchenko
2022-12-06 22:04 ` Andrew Jeffery
2022-12-06 22:21 ` Andy Shevchenko
2022-12-08 4:23 ` Andrew Jeffery
2022-12-08 9:27 ` Bartosz Golaszewski
2022-12-08 11:09 ` Andrew Jeffery
2022-12-08 18:48 ` Bartosz Golaszewski
2022-12-08 21:51 ` Andrew Jeffery [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=38927236-d8b5-42fb-b867-5d761dc8afb6@app.fastmail.com \
--to=andrew@aj.id.au \
--cc=andriy.shevchenko@linux.intel.com \
--cc=brgl@bgdev.pl \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=viresh.kumar@linaro.org \
--cc=warthog618@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).