From fffd8564551a87d26dda4e7f8e4127e6fd39ec48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20M=C3=A4rdian?= Date: Mon, 31 Jul 2023 15:29:39 +0200 Subject: [PATCH] rework cffi build --- python-cffi/_build_cffi.py | 8 ++++++-- python-cffi/meson.build | 32 +++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/python-cffi/_build_cffi.py b/python-cffi/_build_cffi.py index 4e9c7f264..ddb5d4569 100644 --- a/python-cffi/_build_cffi.py +++ b/python-cffi/_build_cffi.py @@ -16,6 +16,7 @@ # along with this program. If not, see . import os +import sys from cffi import FFI ffibuilder = FFI() @@ -51,6 +52,9 @@ NetplanBackend netplan_state_get_backend(const NetplanState* np_state); """) +cffi_inc = os.getenv('CFFI_INC', sys.argv[1]) +cffi_lib = os.getenv('CFFI_LIB', sys.argv[2]) + # set_source() gives the name of the python extension module to # produce, and some C source code as a string. This C code needs # to make the declarated functions, types and globals available, @@ -62,8 +66,8 @@ #include "parse.h" #include "parse-nm.h" """, - include_dirs=[os.getenv('CFFI_INC')], - library_dirs=[os.getenv('CFFI_LIB')], + include_dirs=[cffi_inc], + library_dirs=[cffi_lib], libraries=['netplan', 'glib-2.0']) # library name, for the linker if __name__ == "__main__": diff --git a/python-cffi/meson.build b/python-cffi/meson.build index 72c13f862..baf976910 100644 --- a/python-cffi/meson.build +++ b/python-cffi/meson.build @@ -3,17 +3,31 @@ python = pymod.find_installation( 'python3', modules: ['cffi'] ) +python_dep = python.dependency(required: true) -#https://mesonbuild.com/FAQ.html#but-i-really-want-to-use-wildcards -out = run_command( - 'sh', '-c', 'python3 _build_cffi.py && find -name _libnetplan*.so', - env: [ - 'CFFI_INC=' + join_paths(meson.project_source_root(), 'include'), - 'CFFI_LIB=' + join_paths(meson.current_build_dir(), 'src'), +cffi_srcs = configure_file( + command: [ + python, + files('_build_cffi.py'), + join_paths(meson.project_source_root(), 'include'), + join_paths(meson.current_build_dir(), 'src'), ], - check: true, + output: '_libnetplan0.c', +) + +cffi_pyext = python.extension_module( + '_libnetplan0', + link_whole: static_library( + '_libnetplan0', + cffi_srcs, + dependencies: [python_dep, glib], + include_directories: [include_directories(join_paths('..', 'include'))], + ), + dependencies: [python_dep], + include_directories: [include_directories(join_paths('..', 'include'))], + subdir: 'netplan', + install: true, ) -cffi_so = out.stdout().strip().split('\n') bindings_sources = ''' __init__.py @@ -22,5 +36,5 @@ bindings_sources = ''' '''.split() bindings = python.install_sources( - [bindings_sources, cffi_so], + [bindings_sources], subdir: 'netplan')