tools: provide a shared library with high-level functions used by gpio-tools
Subsystems (2)
cover tools: provide a shared library with high-level functions used by gpio-tools
The API of libgpiod v2 is a bit more limited than that of v1. Notably:
the whole category of high-level helpers as well as functions allowing to look up lines and chips by names/labels have been removed and replaced by low-level interfaces which require users to implement the look-up logic locally.
It's been requested several times that equivalents of these functions should be provided in some form. I don't want to expose more functionality in libgpiod core API than what the linux kernel uAPI provides. However, the gpio-tools already contain a shared library - tools-common - which implements the bulk of the desired functions in a new form.
This series splits out parts of tools-common into a new shared library:
libgpiotools, and reuses it in tools-common while keeping the existing interface facing the gpio-tools in order to not have to adapt them to the new API.
Kent: I allowed myself to change the license of the factored out code to LGPL-v2.1-or-later to enable linking against libgpiotools in line with libgpiod and other shared libraries from this project. Your Ack would be appreciated.
---
Bartosz Golaszewski (2):
tools: provide the libgpiotools shared library
tools: reuse libgpiotools
docs/Doxyfile | 1 + docs/gpio_tools.rst | 16 ++ docs/gpio_tools_lib.rst | 12 ++ meson.build | 3 + tools/gpiotools.c | 437 ++++++++++++++++++++++++++++++++++++++++++++++++ tools/gpiotools.h | 236 ++++++++++++++++++++++++++ tools/meson.build | 28 +++- tools/tools-common.c | 316 ++++------------------------------ tools/tools-common.h | 63 +------ 9 files changed, 772 insertions(+), 340 deletions(-)
---
base-commit: 5eed939e0d544afa311a4dd6dac90833d38d7d29
change-id: 20260311-tools-common-shared-lib-97b58de050e2
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>
PATCH 1/2 tools: provide the libgpiotools shared library
In order to enable users of the project to reuse the high-level functions provided to gpio-tools via the static tools-common library (for
instance: for line lookup by name), expose a sub-set of its functionality in new shared library: libgpiotools, accompanied by a new public header and providing a stable API/ABI.
Add a new rst page documenting the public API of the libgpiotools shared library and integrate it into the sphinx build.
--- docs/Doxyfile | 1 + docs/gpio_tools.rst | 16 ++ docs/gpio_tools_lib.rst | 12 ++ meson.build | 3 + tools/gpiotools.c | 437 ++++++++++++++++++++++++++++++++++++++++++++++++ tools/gpiotools.h | 236 ++++++++++++++++++++++++++ tools/meson.build | 20 +++ 7 files changed, 725 insertions(+)
docs/Doxyfile +1 -0
@@ -4,6 +4,7 @@ PROJECT_NAME = libgpiod OUTPUT_DIRECTORY = doxygen-output INPUT = ../include/gpiod.h \ + ../tools/gpiotools.h \ ../bindings/cxx/gpiod.hpp \ ../bindings/cxx/gpiodcxx/ GENERATE_XML = YES
docs/gpio_tools.rst +16 -0
@@ -33,6 +33,22 @@ There are currently six command-line tools available: changes to watch for, how many events to process before exiting, or if the events should be reported to the console +Shared library +-------------- + +A number of functions used to implement **gpio-tools** has been made available +in a shared library separate from the low-level, core libgpiod API in the form +of libgpiotools. + +.. note:: + The libgpiotools library does not get nearly as much attention and care as + the core libgpiod C library so your mileage may vary. + +.. toctree:: + :maxdepth: 1 + + libgpiotools API documentation<gpio_tools_lib> + .. toctree:: :maxdepth: 1 :caption: Manual entries
docs/gpio_tools_lib.rst new file +12 -0
@@ -0,0 +1,12 @@ +.. + SPDX-License-Identifier: CC-BY-SA-4.0 + SPDX-FileCopyrightText: 2026 Qualcomm Technologies, Inc. and/or its subsidiaries + +.. + This file is part of libgpiod. + +libgpiotools API +================ + +.. doxygengroup:: gpiotools + :members:
meson.build +3 -0
@@ -33,6 +33,9 @@ libgpiosim_version = '1.0.1' # ... and another one for GLib bindings: libgpiod_glib_soversion = 1 libgpiod_glib_version = '1.0.0' +# ... and another for the libgpiotools shared library: +libgpiotools_soversion = 1 +libgpiotools_version = '1.0.0' add_project_arguments( '-D_GNU_SOURCE',
tools/gpiotools.c new file +437 -0
437 lines not on this page · raw message
tools/gpiotools.h new file +236 -0
236 lines not on this page · raw message
tools/meson.build +20 -0
@@ -1,6 +1,26 @@ # SPDX-License-Identifier: GPL-2.0-or-later # SPDX-FileCopyrightText: 2026 Qualcomm Technologies, Inc. and/or its subsidiaries +libgpiotools_lib = library('gpiotools', + sources: ['gpiotools.c'], + include_directories: libgpiod_inc, + c_args: ['-fvisibility=hidden'], + dependencies: [libgpiod_dep], + version: libgpiotools_version, + soversion: libgpiotools_soversion, + install: true, +) + +install_headers('gpiotools.h') + +pkgconfig = import('pkgconfig') +pkgconfig.generate(libgpiotools_lib, + name: 'libgpiotools', + description: 'Collection of high-level functions for building programs using libgpiod', + url: project_url, + version: meson.project_version(), +) + tools_common_lib = static_library('tools-common', sources: ['tools-common.c'], include_directories: libgpiod_inc,
Signature · 1 line
2.47.3
PATCH 2/2 tools: reuse libgpiotools
In reply to Bartosz GolaszewskiReuse as much of the functionality provided by the new libgpiotools shared library in tools-common while retaining the functions used to validate command-line arguments, print help text or bail-out on errors. We keep the existing interfaces to gpio-tools and use them to wrap the API exposed by libgpiotools as we want to keep bailing out on errors without requiring tools to do a lot of repeated error checking.
--- tools/meson.build | 8 +- tools/tools-common.c | 316 ++++++--------------------------------------------- tools/tools-common.h | 63 +--------- 3 files changed, 47 insertions(+), 340 deletions(-)
tools/meson.build +7 -1
@@ -21,9 +21,15 @@ pkgconfig.generate(libgpiotools_lib, version: meson.project_version(), ) +libgpiotools_dep = declare_dependency( + link_with: libgpiotools_lib, + include_directories: include_directories('.'), +) + tools_common_lib = static_library('tools-common', sources: ['tools-common.c'], include_directories: libgpiod_inc, + dependencies: [libgpiotools_dep], pic: true, )
@@ -33,7 +39,7 @@ tools_common_dep = declare_dependency( ) tools_c_args = [] -tools_deps = [libgpiod_dep, tools_common_dep] +tools_deps = [libgpiod_dep, libgpiotools_dep, tools_common_dep] if opt_gpioset_interactive.allowed() and libedit_dep.found() tools_c_args += ['-DGPIOSET_INTERACTIVE']
tools/tools-common.c +35 -281
408 lines not on this page · raw message
tools/tools-common.h +5 -58
75 lines not on this page · raw message
Signature · 1 line
2.47.3
Quoted 18 lines · Bartosz Golaszewski
The API of libgpiod v2 is a bit more limited than that of v1. Notably:
the whole category of high-level helpers as well as functions allowing to look up lines and chips by names/labels have been removed and replaced by low-level interfaces which require users to implement the look-up logic locally.It's been requested several times that equivalents of these functions should be provided in some form. I don't want to expose more functionality in libgpiod core API than what the linux kernel uAPI provides. However, the gpio-tools already contain a shared library - tools-common - which implements the bulk of the desired functions in a new form.
This series splits out parts of tools-common into a new shared library:
libgpiotools, and reuses it in tools-common while keeping the existing interface facing the gpio-tools in order to not have to adapt them to the new API.
Quoted 5 lines
Kent: I allowed myself to change the license of the factored out code to LGPL-v2.1-or-later to enable linking against libgpiotools in line with libgpiod and other shared libraries from this project. Your Ack would be appreciated.
Makes sense and works for me.
Quoted 24 lines
Signed-off-by Bartosz Golaszewski <[email protected]>---
Bartosz Golaszewski (2):
tools: provide the libgpiotools shared library
tools: reuse libgpiotoolsdocs/Doxyfile | 1 + docs/gpio_tools.rst | 16 ++ docs/gpio_tools_lib.rst | 12 ++ meson.build | 3 + tools/gpiotools.c | 437 ++++++++++++++++++++++++++++++++++++++++++++++++ tools/gpiotools.h | 236 ++++++++++++++++++++++++++ tools/meson.build | 28 +++- tools/tools-common.c | 316 ++++------------------------------ tools/tools-common.h | 63 +------ 9 files changed, 772 insertions(+), 340 deletions(-)---
base-commit:5eed939e0d544afa311a4dd6dac90833d38d7d29
change-id: 20260311-tools-common-shared-lib-97b58de050e2Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>
Bartosz Golaszewski
AppliedQuoted 6 lines · Bartosz Golaszewski
The API of libgpiod v2 is a bit more limited than that of v1. Notably:
the whole category of high-level helpers as well as functions allowing to look up lines and chips by names/labels have been removed and replaced by low-level interfaces which require users to implement the look-up logic locally.
Quoted 8 lines
It's been requested several times that equivalents of these functions should be provided in some form. I don't want to expose more functionality in libgpiod core API than what the linux kernel uAPI provides. However, the gpio-tools already contain a shared library - tools-common - which implements the bulk of the desired functions in a new form.
[...]
Applied, thanks!
[1/2] tools: provide the libgpiotools shared library
https://git.kernel.org/brgl/c/78fd3f3b62f4d3155e2ded904a9591669c0b2813 [2/2] tools: reuse libgpiotools https://git.kernel.org/brgl/c/0fe66719dddf1a206cb14baba136a36a32fd2f54
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>