[PATCH v2 0/2] port python bindings to native Meson
Eli Schwartz <[email protected]>
| Newsgroups | org.kernel.vger.devicetree-compiler |
|---|---|
| Message-ID | <[email protected]> |
Eli Schwartz (2):
Makefile: deprecate in favor of Meson
meson: port python bindings to build natively via meson and
meson-python
MANIFEST.in | 12 -----
Makefile | 55 +++------------------
libfdt/meson.build | 32 +++++++------
meson.build | 3 +-
meson_options.txt | 2 +
pylibfdt/Makefile.pylibfdt | 30 ------------
pylibfdt/meson.build | 28 +++++++----
pyproject.toml | 33 +++++++++++++
setup.py | 97 --------------------------------------
9 files changed, 79 insertions(+), 213 deletions(-)
delete mode 100644 MANIFEST.in
delete mode 100644 pylibfdt/Makefile.pylibfdt
create mode 100644 pyproject.toml
delete mode 100755 setup.py
Range-diff against v1:
-: ------- > 1: 142d7e4 Makefile: deprecate in favor of Meson
1: f23b5eb ! 2: 5d0590f meson: port python bindings to build natively via meson and meson-python
@@ Commit message
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.
+
## MANIFEST.in (deleted) ##
@@
-# SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
@@ MANIFEST.in (deleted)
-include libfdt/libfdt_env.h
-include VERSION.txt
- ## libfdt/meson.build ##
-@@ libfdt/meson.build: else
- endif
+ ## Makefile ##
+@@ Makefile: BISON = bison
+ LEX = flex
+ SWIG = swig
+ PKG_CONFIG ?= pkg-config
+-PYTHON ?= python3
+
+ INSTALL = install
+ INSTALL_PROGRAM = $(INSTALL)
+@@ Makefile: INCLUDEDIR = $(PREFIX)/include
+ HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | \
+ sed -e 's/\(cygwin\|msys\).*/\1/')
+
+-NO_PYTHON ?= 0
+-
+ NO_VALGRIND := $(shell $(PKG_CONFIG) --exists valgrind; echo $$?)
+ ifeq ($(NO_VALGRIND),1)
+ CPPFLAGS += -DNO_VALGRIND
+@@ Makefile: SCRIPTS = dtdiff
+
+ all: $(BIN) libfdt
+
+-# We need both Python and swig to build/install pylibfdt.
+-# This builds the given make ${target} if those deps are found.
+-check_python_deps = \
+- if $(PKG_CONFIG) --cflags $(PYTHON) >/dev/null 2>&1; then \
+- if which swig >/dev/null 2>&1; then \
+- can_build=yes; \
+- fi; \
+- fi; \
+- if [ "$${can_build}" = "yes" ]; then \
+- $(MAKE) $${target}; \
+- else \
+- echo "\#\# Skipping pylibfdt (install python dev and swig to build)"; \
+- fi ;
+-
+-.PHONY: maybe_pylibfdt
+-maybe_pylibfdt: FORCE
+- target=pylibfdt; $(check_python_deps)
+-
+-ifeq ($(NO_PYTHON),0)
+-all: maybe_pylibfdt
+-endif
+-
+-
+ ifneq ($(DEPTARGETS),)
+ ifneq ($(MAKECMDGOALS),libfdt)
+ -include $(DTC_OBJS:%.o=%.d)
+@@ Makefile: install-includes:
+
+ install: install-bin install-lib install-includes
+
+-.PHONY: maybe_install_pylibfdt
+-maybe_install_pylibfdt: FORCE
+- target=install_pylibfdt; $(check_python_deps)
+-
+-ifeq ($(NO_PYTHON),0)
+-install: maybe_install_pylibfdt
+-endif
+-
+ $(VERSION_FILE): Makefile FORCE
+ $(call filechk,version)
+
+@@ Makefile: dist:
+ gzip -9 > ../dtc-$(dtc_version).tar.gz
+
- link_args += version_script
--libfdt = both_libraries(
-+libfdt = library(
- 'fdt', sources,
+-#
+-# Rules for pylibfdt
+-#
+-PYLIBFDT_dir = pylibfdt
+-
+-include $(PYLIBFDT_dir)/Makefile.pylibfdt
+-
+-.PHONY: pylibfdt
+-pylibfdt: $(PYLIBFDT_dir)/_libfdt.so
+-
+ #
+ # Release signing and uploading
+ # This is for maintainer convenience, don't try this at home.
+@@ Makefile: TESTS_BIN += fdtput
+ TESTS_BIN += fdtget
+ TESTS_BIN += fdtdump
+ TESTS_BIN += fdtoverlay
+-ifeq ($(NO_PYTHON),0)
+-TESTS_PYLIBFDT += maybe_pylibfdt
+-endif
+
+ ifneq ($(MAKECMDGOALS),libfdt)
+ include tests/Makefile.tests
+@@ Makefile: endif
+ STD_CLEANFILES = *~ *.o *.$(SHAREDLIB_EXT) *.d *.a *.i *.s core a.out vgcore.* \
+ *.tab.[ch] *.lex.c *.output
+
+-clean: libfdt_clean pylibfdt_clean tests_clean
++clean: libfdt_clean tests_clean
+ @$(VECHO) CLEAN
+ rm -f $(STD_CLEANFILES)
+ rm -f $(VERSION_FILE)
+
+ ## libfdt/meson.build ##
+@@ libfdt/meson.build: libfdt = library(
version: meson.project_version(),
link_args: link_args,
link_depends: 'version.lds',
@@ libfdt/meson.build: else
+ install: get_option('default_library') != 'static' or not wheel_only,
)
- if static_build
-- link_with = libfdt.get_static_lib()
-+ link_with = libfdt
- else
-- link_with = libfdt.get_shared_lib()
-+ link_with = libfdt
- endif
-
libfdt_inc = include_directories('.')
@@ libfdt/meson.build: libfdt_dep = declare_dependency(
- link_with: link_with,
+ link_with: libfdt,
)
-install_headers(
@@ meson.build: util_dep = declare_dependency(
## meson_options.txt ##
-@@ meson_options.txt: option('static-build', type: 'boolean', value: false,
- description: 'Build static binaries')
+@@ meson_options.txt: option('python', type: 'feature', value: 'auto',
+ description: 'Build pylibfdt Python library')
option('tests', type: 'boolean', value: true,
description: 'Build tests')
+option('wheel-only', type: 'boolean', value: false,
+ description: 'building from meson-python')
+ ## pylibfdt/Makefile.pylibfdt (deleted) ##
+@@
+-# SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
+-# Makefile.pylibfdt
+-#
+-
+-PYLIBFDT_srcs = $(PYLIBFDT_dir)/libfdt.i
+-PYMODULE = $(PYLIBFDT_dir)/_libfdt.so
+-PYLIBFDT_CLEANFILES_L = libfdt_wrap.c libfdt.py *.pyc *.so
+-PYLIBFDT_CLEANFILES = $(PYLIBFDT_CLEANFILES_L:%=$(PYLIBFDT_dir)/%)
+-PYLIBFDT_CLEANDIRS_L = __pycache__ libfdt.egg-info
+-PYLIBFDT_CLEANDIRS = build $(PYLIBFDT_CLEANDIRS_L:%=$(PYLIBFDT_dir)/%)
+-
+-SETUP = ./setup.py
+-
+-ifndef V
+-SETUPFLAGS += --quiet
+-endif
+-
+-$(PYMODULE): WARNINGS = # suppress warnings from generated code
+-$(PYMODULE): $(PYLIBFDT_srcs) $(LIBFDT_archive) $(SETUP)
+- @$(VECHO) PYMOD $@
+- CFLAGS="$(CFLAGS) -Wno-error" $(PYTHON) $(SETUP) $(SETUPFLAGS) build_ext
+-
+-install_pylibfdt: $(PYMODULE)
+- @$(VECHO) INSTALL-PYLIB
+- $(PYTHON) $(SETUP) $(SETUPFLAGS) install --prefix=$(PREFIX)
+-
+-pylibfdt_clean:
+- @$(VECHO) CLEAN "(pylibfdt)"
+- rm -f $(PYLIBFDT_CLEANFILES)
+- rm -rf $(PYLIBFDT_CLEANDIRS)
+
## pylibfdt/meson.build ##
@@
-setup_py = find_program('../setup.py')
@@ pyproject.toml (new)
+[project.urls]
+'homepage' = 'https://git.kernel.org/pub/scm/utils/dtc/dtc.git'
+
++# These arguments are applied only when building a redistributable binary wheel
++# for uploading to PyPI. We don't want to install libraries (or headers /
++# pkgconfig files / executables) that clash with system C installs, so we
++# disable everything other than the python bindings themselves, and build the
++# python C-API extension using static linkage to avoid juggling "libdir" /
++# LD_LIBRARY_PATH / RPATH around. When building both the C library and the
++# python bindings for a distro, `meson setup` will still default to shared
++# libraries.
+[tool.meson-python.args]
-+'setup' = ['-Ddefault_library=static', '-Dwheel-only=true']
++setup = ['-Ddefault_library=static', '-Dwheel-only=true']
## setup.py (deleted) ##
@@
--
2.49.0