Skip to contentSkip to conversation

tools: provide a shared library with high-level functions used by gpio-tools

PATCH Applied Bartosz Golaszewski 2 participants 5 messages May 13 – May 18

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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]>
#1 lore raw

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
index 8c5b5dff54721fe4ccc9f3049e6c2c3f484cb911..3ee98ab21c0412a6d62d50686981c82cb3c8f464 100644
@@ -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
index e4bf5847315ce93859bd4179df306a43a0445fec..2876970e4028451b05f7b20a551fc97d0a1685c2 100644
@@ -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
new file mode 100644
index 0000000000000000000000000000000000000000..2931f950d4b60c4e445e6d8c9d29dad1a4975214
@@ -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
index 4ec1e575820ff64245b52823312b57e8e09127d9..0bf970eb155178394410c4fbd680eb7544834637 100644
@@ -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
index b26718ba69679d03d210562768f71ea02bc3ed01..d755167cfbd7c2a7400d28cf5e5d5f9eece699d7 100644
@@ -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
#2 lore raw

PATCH 2/2 tools: reuse libgpiotools

In reply to Bartosz Golaszewski

Reuse 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
index d755167cfbd7c2a7400d28cf5e5d5f9eece699d7..5ecf7dc5d221d52243478f9a126e6512d2408981 100644
@@ -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
Acked-by on the v1 series
#3 lore raw
In reply to Bartosz Golaszewski
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

---
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]>
author Applied
#4 lore raw
In reply to Bartosz Golaszewski
Quoted 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]>