meson: port python bindings to build natively via meson and meson-python

We get full build parallelism and fewer confusing ancient distutils
paths. The python wheels build fully standalone, including linking
libfdt as a static library.

For convenience, when running pip install a meson option is passed that
prevents building tools or installing headers/pkgconfig files.
meson-python would otherwise include them in the wheel itself, in case
they are needed, but this is essentially a bit useless so don't bother.

The old setuptools-based build is now redundant and goes away.

Signed-off-by: Eli Schwartz <eschwartz@gentoo.org>
Message-ID: <20250430152601.43554-3-eschwartz@gentoo.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
Eli Schwartz 2025-04-30 11:25:26 -04:00 committed by David Gibson
parent 7ebfcac852
commit ecb21febfd
9 changed files with 73 additions and 213 deletions

View file

@ -1,13 +1,21 @@
setup_py = find_program('../setup.py')
setup_py = [setup_py, '--quiet', '--top-builddir', meson.project_build_root()]
pylibfdt = custom_target(
'pylibfdt',
libfdt_c = custom_target(
'swig',
input: 'libfdt.i',
depends: libfdt,
output: '_libfdt.so',
command: [setup_py, 'build_ext'],
build_by_default: true,
output: ['libfdt.c', 'libfdt.py'],
install: true,
install_dir: [false, py.get_install_dir(pure: false)],
command: [swig, '-python', '-I'+meson.current_source_dir() / '../libfdt', '-o', '@OUTPUT0@', '@INPUT@']
)
meson.add_install_script(setup_py, 'install', '--prefix=' + get_option('prefix'), '--root=$DESTDIR')
nowarn_gen = cc.get_supported_arguments(
'-Wno-cast-qual',
'-Wno-missing-prototypes',
'-Wno-redundant-decls',
)
pylibfdt = py.extension_module(
'_libfdt',
libfdt_c,
c_args: ['-DPY_SSIZE_T_CLEAN'] + nowarn_gen,
dependencies: [libfdt_dep, py.dependency()],
install: true,
)