Skip to contentSkip to conversation

package/hidapi: add support for build without hidraw support when udev is not available

PATCH New Tomas Mudrunka 1 participant 7 messages Mar 24 – Nov 13

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/hidapi: add support for build without hidraw support when udev is not available

This allows use of libhidapi on tiny systems without udev

---
 package/hidapi/Config.in | 28 ++++++++++++++++++++++++----
 package/hidapi/hidapi.mk | 20 +++++++++++++++-----
 2 files changed, 39 insertions(+), 9 deletions(-)
package/hidapi/Config.in +24 -4
index 1d3c86b677..efacd1aa26 100644
@@ -1,10 +1,8 @@
 config BR2_PACKAGE_HIDAPI
 	bool "hidapi"
-	depends on BR2_PACKAGE_HAS_UDEV
 	depends on BR2_TOOLCHAIN_HAS_THREADS_NPTL
 	depends on BR2_TOOLCHAIN_GCC_AT_LEAST_4_9 # libusb
 	select BR2_PACKAGE_LIBUSB
-	select BR2_PACKAGE_LIBGUDEV
 	select BR2_PACKAGE_LIBICONV if !BR2_ENABLE_LOCALE
 	# runtime UTF conversion support
 	select BR2_TOOLCHAIN_GLIBC_GCONV_LIBS_COPY if BR2_TOOLCHAIN_USES_GLIBC
@@ -13,9 +11,31 @@ config BR2_PACKAGE_HIDAPI
 	  to interface with USB and Bluetooth HID-Class devices on
 	  Windows, Linux, and Mac OS X.
 
+	  On Linux you can disable the hidraw backend (see below) to
+	  build only libhidapi-libusb, which does not require udev.
+
 	  http://github.com/libusb/hidapi/
 
-comment "hidapi needs udev /dev management and a toolchain w/ NPTL, gcc >= 4.9"
+if BR2_PACKAGE_HIDAPI
+
+comment "hidapi hidraw backend unavailable (no udev - enable eudev or systemd)"
+	depends on !BR2_PACKAGE_HAS_UDEV
+
+config BR2_PACKAGE_HIDAPI_HIDRAW
+	bool "hidraw backend"
+	default y if BR2_PACKAGE_HAS_UDEV
+	depends on BR2_PACKAGE_HAS_UDEV
+	help
+	  Build the Linux hidraw implementation (libhidapi-hidraw). This
+	  requires libudev from a udev provider (eudev or systemd).
+
+	  Say 'n' here to build only the libusb backend
+	  (libhidapi-libusb), which is enough for applications that
+	  link against hidapi-libusb and allows using HIDAPI on systems
+	  without udev.
+
+endif
+
+comment "hidapi needs a toolchain w/ NPTL and gcc >= 4.9"
 	depends on !BR2_TOOLCHAIN_HAS_THREADS_NPTL || \
-		!BR2_PACKAGE_HAS_UDEV || \
 		!BR2_TOOLCHAIN_GCC_AT_LEAST_4_9
package/hidapi/hidapi.mk +15 -5
index c4daf934ee..11b622a8ad 100644
@@ -7,16 +7,26 @@
 HIDAPI_VERSION = 0.15.0
 HIDAPI_SITE = $(call github,libusb,hidapi,hidapi-$(HIDAPI_VERSION))
 HIDAPI_INSTALL_STAGING = YES
-# No configure provided, so we need to autoreconf.
-HIDAPI_AUTORECONF = YES
+HIDAPI_SUPPORTS_IN_SOURCE_BUILD = NO
 HIDAPI_LICENSE = GPL-3.0 or BSD-3-Clause or HIDAPI license
 HIDAPI_LICENSE_FILES = LICENSE.txt LICENSE-gpl3.txt LICENSE-bsd.txt LICENSE-orig.txt
 
-HIDAPI_DEPENDENCIES = libusb libgudev
+HIDAPI_DEPENDENCIES = libusb
+
+HIDAPI_CONF_OPTS = \
+	-DHIDAPI_WITH_LIBUSB=ON \
+	-DHIDAPI_WITH_TESTS=OFF \
+	-DHIDAPI_BUILD_HIDTEST=OFF
+
+ifeq ($(BR2_PACKAGE_HIDAPI_HIDRAW),y)
+HIDAPI_CONF_OPTS += -DHIDAPI_WITH_HIDRAW=ON
+HIDAPI_DEPENDENCIES += udev
+else
+HIDAPI_CONF_OPTS += -DHIDAPI_WITH_HIDRAW=OFF
+endif
 
 ifeq ($(BR2_PACKAGE_LIBICONV),y)
 HIDAPI_DEPENDENCIES += libiconv
-HIDAPI_CONF_ENV += LIBS="-liconv"
 endif
 
-$(eval $(autotools-package))
+$(eval $(cmake-package))
Signature · 6 lines
2.53.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

v2 cover package/hidapi: allow building without udev

This series allows to use hidapi (libhidapi-libusb) on systems without udev, by making the hidraw backend optional.

To do so, the package is converted to cmake, which allows to select the backends to build. Before that, the bogus libgudev dependency is replaced by the udev one, as hidapi only uses libudev; libmanette, which relied on hidapi to get libgudev, now selects it directly.

Existing configurations keep building the same hidapi libraries: the hidraw backend is enabled by default when udev is available. libmanette, the only in-tree user that requires hidapi-hidraw, now selects it.

The last patch adds me to DEVELOPERS for hidapi, as we use it in production on systems without udev and I'm happy to look after it. Feel free to drop it if not wanted.

Changes v1 -> v2:
- rebased on top of commit 74def2cdd4 ("package/hidapi: propagate dependencies of libgudev")
- split into four patches (libmanette: select libgudev, libgudev -> udev, cmake conversion, optional hidraw backend)
- libmanette: select BR2_PACKAGE_HIDAPI_HIDRAW, as it only looks up hidapi-hidraw.pc
- new patch: libmanette selects libgudev, which it used to get through hidapi
- new patch: add myself to DEVELOPERS for hidapi
- drop HIDAPI_SUPPORTS_IN_SOURCE_BUILD = NO, not needed
- Config.in: use the usual "needs udev /dev management" comment, simplify the default of the hidraw option

Tested with utils/test-pkg (default toolchain set):
- BR2_PACKAGE_HIDAPI=y (no udev): all OK, armv7m-uclibc skipped (no NPTL)
- with eudev and the hidraw backend: OK, except bootlin-armv5-uclibc, which fails because wcsdup() is not declared by that toolchain's uClibc-ng headers; the same failure happens on master without this series (fixed in Buildroot's own uClibc by package/uclibc/0007-wchar.h-declare-wcsdup-for-POSIX.1-2008.patch)
- BR2_PACKAGE_LIBSIGROK=y and BR2_PACKAGE_AVRDUDE=y with hidapi, no udev, on bootlin-armv7-glibc: OK (both use hidapi-libusb)

Tomas Mudrunka (5):
package/libmanette: select libgudev package/hidapi: depend on udev instead of libgudev package/hidapi: convert to cmake-package package/hidapi: make the hidraw backend optional
DEVELOPERS: add Tomas Mudrunka for hidapi

 DEVELOPERS                       |  3 +++
 package/hidapi/Config.in         | 26 +++++++++++++++++++-------
 package/hidapi/hidapi.mk         | 19 ++++++++++++++-----
 package/libmanette/Config.in     |  4 +++-
 package/libmanette/libmanette.mk |  9 ++-------
 5 files changed, 41 insertions(+), 20 deletions(-)
Signature · 6 lines
2.56.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#2 lore raw

PATCH v2 1/5 package/libmanette: select libgudev

libmanette selects hidapi, which selects libgudev, so libmanette has always been built with gudev support (-Dgudev=enabled), which it uses to discover game controllers through udev.

hidapi does not actually need libgudev, and the following patch drops that dependency. Make libmanette select libgudev explicitly, and enable gudev unconditionally, so that its behavior does not depend on what hidapi selects.

All of libgudev's dependencies (BR2_PACKAGE_HAS_UDEV, BR2_USE_MMU, BR2_USE_WCHAR, threads) are already libmanette dependencies.

---
 package/libmanette/Config.in     | 1 +
 package/libmanette/libmanette.mk | 9 ++-------
 2 files changed, 3 insertions(+), 7 deletions(-)
package/libmanette/Config.in +1 -0
index d4f45e25ad..0f3a5a7bb0 100644
@@ -9,6 +9,7 @@ config BR2_PACKAGE_LIBMANETTE
 	select BR2_PACKAGE_HIDAPI
 	select BR2_PACKAGE_LIBEVDEV
 	select BR2_PACKAGE_LIBGLIB2
+	select BR2_PACKAGE_LIBGUDEV
 	help
 	  GObject library which provides access to game controllers.
 
package/libmanette/libmanette.mk +2 -7
index c320b84840..43b44efbe3 100644
@@ -14,6 +14,7 @@ LIBMANETTE_INSTALL_STAGING = YES
 LIBMANETTE_DEPENDENCIES = \
 	libevdev \
 	libglib2 \
+	libgudev \
 	hidapi \
 	$(TARGET_NLS_DEPENDENCIES)
 
@@ -24,6 +25,7 @@ LIBMANETTE_CONF_OPTS = \
 	-Dbuild-tests=false \
 	-Dinstall-tests=false \
 	-Ddoc=false \
+	-Dgudev=enabled \
 	-Dvapi=false
 
 ifeq ($(BR2_PACKAGE_GOBJECT_INTROSPECTION),y)
@@ -33,11 +35,4 @@ else
 LIBMANETTE_CONF_OPTS += -Dintrospection=false
 endif
 
-ifeq ($(BR2_PACKAGE_LIBGUDEV),y)
-LIBMANETTE_CONF_OPTS += -Dgudev=enabled
-LIBMANETTE_DEPENDENCIES += libgudev
-else
-LIBMANETTE_CONF_OPTS += -Dgudev=disabled
-endif
-
 $(eval $(meson-package))
Signature · 6 lines
2.56.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#3 lore raw

PATCH v2 2/5 package/hidapi: depend on udev instead of libgudev

In reply to Tomas Mudrunka

hidapi has never used libgudev: its hidraw backend only links against libudev (see PKG_CHECK_MODULES([libudev], ...) in configure.ac). The libgudev dependency is a leftover from commit e739dd5a11f5b2bd9648a45623bc174adae42b6e ("Use libgudev as regular dependency"), done when libgudev was split out of eudev.

Depend on the udev virtual package instead, which is what actually provides libudev, and drop the libgudev select. The BR2_USE_MMU and BR2_USE_WCHAR dependencies are kept, but their comments are updated:
MMU is needed by the udev providers, and wchar is needed by hidapi itself (wcsdup(), wcsncpy(), ...).

As hidapi no longer selects libgudev, packages that optionally use libgudev no longer get it implicitly when hidapi is enabled. libmanette, which selects hidapi, now selects libgudev itself (see previous patch). The other packages with optional libgudev support (gst1-plugins-good, gvfs, libqmi, modem-manager) only got it by accident when hidapi was also enabled; configurations relying on that need to enable BR2_PACKAGE_LIBGUDEV explicitly.

---
 package/hidapi/Config.in | 5 ++---
 package/hidapi/hidapi.mk | 2 +-
 2 files changed, 3 insertions(+), 4 deletions(-)
package/hidapi/Config.in +2 -3
index fa44288917..72ae32a6d8 100644
@@ -3,10 +3,9 @@ config BR2_PACKAGE_HIDAPI
 	depends on BR2_PACKAGE_HAS_UDEV
 	depends on BR2_TOOLCHAIN_HAS_THREADS_NPTL
 	depends on BR2_TOOLCHAIN_GCC_AT_LEAST_4_9 # libusb
-	depends on BR2_USE_MMU # libgudev
-	depends on BR2_USE_WCHAR # libgudev
+	depends on BR2_USE_MMU # udev
+	depends on BR2_USE_WCHAR # wcsdup()
 	select BR2_PACKAGE_LIBUSB
-	select BR2_PACKAGE_LIBGUDEV
 	select BR2_PACKAGE_LIBICONV if !BR2_ENABLE_LOCALE
 	# runtime UTF conversion support
 	select BR2_TOOLCHAIN_GLIBC_GCONV_LIBS_COPY if BR2_TOOLCHAIN_USES_GLIBC
package/hidapi/hidapi.mk +1 -1
index c4daf934ee..7e202f0eb5 100644
@@ -12,7 +12,7 @@ HIDAPI_AUTORECONF = YES
 HIDAPI_LICENSE = GPL-3.0 or BSD-3-Clause or HIDAPI license
 HIDAPI_LICENSE_FILES = LICENSE.txt LICENSE-gpl3.txt LICENSE-bsd.txt LICENSE-orig.txt
 
-HIDAPI_DEPENDENCIES = libusb libgudev
+HIDAPI_DEPENDENCIES = libusb udev
 
 ifeq ($(BR2_PACKAGE_LIBICONV),y)
 HIDAPI_DEPENDENCIES += libiconv
Signature · 6 lines
2.56.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#4 lore raw

PATCH v2 3/5 package/hidapi: convert to cmake-package

In reply to Tomas Mudrunka

Upstream considers the autotools build system deprecated and going to be obsolete, and recommends using CMake instead (see BUILD.autotools.md and BUILD.md). The CMake build system also allows to select which backends are built (see the HIDAPI_WITH_* options), and avoids the need to autoreconf the package.

Both backends (hidraw and libusb) are still built, so the installed shared libraries (with the same libhidapi-*.so.0 SONAME), headers and pkg-config files are unchanged; the .pc files are generated from the same pc/*.pc.in templates.

The LIBS="-liconv" workaround is no longer needed: the libusb backend uses find_package(Iconv) and links against libiconv when the C library does not provide iconv.

As usual with cmake-package, only shared libraries are built when BR2_SHARED_STATIC_LIBS=y, while the autotools build also installed the static ones. No in-tree package links statically against hidapi in that configuration.

The hidtest program and unit tests default to ON only for Debug builds; disable them explicitly so they are never built.

---
 package/hidapi/hidapi.mk | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
package/hidapi/hidapi.mk +7 -4
index 7e202f0eb5..5f0c482a95 100644
@@ -7,16 +7,19 @@
 HIDAPI_VERSION = 0.15.0
 HIDAPI_SITE = $(call github,libusb,hidapi,hidapi-$(HIDAPI_VERSION))
 HIDAPI_INSTALL_STAGING = YES
-# No configure provided, so we need to autoreconf.
-HIDAPI_AUTORECONF = YES
 HIDAPI_LICENSE = GPL-3.0 or BSD-3-Clause or HIDAPI license
 HIDAPI_LICENSE_FILES = LICENSE.txt LICENSE-gpl3.txt LICENSE-bsd.txt LICENSE-orig.txt
 
 HIDAPI_DEPENDENCIES = libusb udev
 
+HIDAPI_CONF_OPTS = \
+	-DHIDAPI_WITH_HIDRAW=ON \
+	-DHIDAPI_WITH_LIBUSB=ON \
+	-DHIDAPI_WITH_TESTS=OFF \
+	-DHIDAPI_BUILD_HIDTEST=OFF
+
 ifeq ($(BR2_PACKAGE_LIBICONV),y)
 HIDAPI_DEPENDENCIES += libiconv
-HIDAPI_CONF_ENV += LIBS="-liconv"
 endif
 
-$(eval $(autotools-package))
+$(eval $(cmake-package))
Signature · 6 lines
2.56.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#5 lore raw

PATCH v2 4/5 package/hidapi: make the hidraw backend optional

In reply to Tomas Mudrunka

The hidraw backend is the only part of hidapi that needs udev (for libudev); the libusb backend only needs libusb. Make the hidraw backend optional through a new BR2_PACKAGE_HIDAPI_HIDRAW option, available when a udev provider is enabled and enabled by default, so existing configurations are unchanged.

This allows hidapi (libhidapi-libusb) to be used on small systems without udev. The BR2_USE_MMU dependency, which was only needed for udev, is dropped from hidapi.

All in-tree users of hidapi, except libmanette, can use either backend (they look up hidapi-hidraw and hidapi-libusb, or load either library at runtime). libmanette only looks up hidapi-hidraw.pc, so make it select BR2_PACKAGE_HIDAPI_HIDRAW.

---
 package/hidapi/Config.in     | 23 ++++++++++++++++++-----
 package/hidapi/hidapi.mk     | 10 ++++++++--
 package/libmanette/Config.in |  3 ++-
 3 files changed, 28 insertions(+), 8 deletions(-)
package/hidapi/Config.in +18 -5
index 72ae32a6d8..aec90e9501 100644
@@ -1,9 +1,7 @@
 config BR2_PACKAGE_HIDAPI
 	bool "hidapi"
-	depends on BR2_PACKAGE_HAS_UDEV
 	depends on BR2_TOOLCHAIN_HAS_THREADS_NPTL
 	depends on BR2_TOOLCHAIN_GCC_AT_LEAST_4_9 # libusb
-	depends on BR2_USE_MMU # udev
 	depends on BR2_USE_WCHAR # wcsdup()
 	select BR2_PACKAGE_LIBUSB
 	select BR2_PACKAGE_LIBICONV if !BR2_ENABLE_LOCALE
@@ -14,11 +12,26 @@ config BR2_PACKAGE_HIDAPI
 	  to interface with USB and Bluetooth HID-Class devices on
 	  Windows, Linux, and Mac OS X.
 
+	  The libusb backend (libhidapi-libusb) is always built.
+
 	  http://github.com/libusb/hidapi/
 
-comment "hidapi needs udev /dev management and a toolchain w/ NPTL, gcc >= 4.9, wchar"
-	depends on BR2_USE_MMU
+if BR2_PACKAGE_HIDAPI
+
+config BR2_PACKAGE_HIDAPI_HIDRAW
+	bool "hidraw backend"
+	default y
+	depends on BR2_PACKAGE_HAS_UDEV
+	help
+	  Build the hidraw backend (libhidapi-hidraw), which uses the
+	  kernel hidraw interface and needs libudev.
+
+comment "hidraw backend needs udev /dev management"
+	depends on !BR2_PACKAGE_HAS_UDEV
+
+endif
+
+comment "hidapi needs a toolchain w/ NPTL, gcc >= 4.9, wchar"
 	depends on !BR2_TOOLCHAIN_HAS_THREADS_NPTL || \
-		!BR2_PACKAGE_HAS_UDEV || \
 		!BR2_TOOLCHAIN_GCC_AT_LEAST_4_9 || \
 		!BR2_USE_WCHAR
package/hidapi/hidapi.mk +8 -2
index 5f0c482a95..884912f175 100644
@@ -10,14 +10,20 @@ HIDAPI_INSTALL_STAGING = YES
 HIDAPI_LICENSE = GPL-3.0 or BSD-3-Clause or HIDAPI license
 HIDAPI_LICENSE_FILES = LICENSE.txt LICENSE-gpl3.txt LICENSE-bsd.txt LICENSE-orig.txt
 
-HIDAPI_DEPENDENCIES = libusb udev
+HIDAPI_DEPENDENCIES = libusb
 
 HIDAPI_CONF_OPTS = \
-	-DHIDAPI_WITH_HIDRAW=ON \
 	-DHIDAPI_WITH_LIBUSB=ON \
 	-DHIDAPI_WITH_TESTS=OFF \
 	-DHIDAPI_BUILD_HIDTEST=OFF
 
+ifeq ($(BR2_PACKAGE_HIDAPI_HIDRAW),y)
+HIDAPI_CONF_OPTS += -DHIDAPI_WITH_HIDRAW=ON
+HIDAPI_DEPENDENCIES += udev
+else
+HIDAPI_CONF_OPTS += -DHIDAPI_WITH_HIDRAW=OFF
+endif
+
 ifeq ($(BR2_PACKAGE_LIBICONV),y)
 HIDAPI_DEPENDENCIES += libiconv
 endif
package/libmanette/Config.in +2 -1
index 0f3a5a7bb0..9377f35a42 100644
@@ -2,11 +2,12 @@ config BR2_PACKAGE_LIBMANETTE
 	bool "libmanette"
 	depends on BR2_USE_MMU # libglib2, hidapi
 	depends on BR2_USE_WCHAR # libglib2, hidapi
-	depends on BR2_PACKAGE_HAS_UDEV # hidapi
+	depends on BR2_PACKAGE_HAS_UDEV # hidapi-hidraw
 	depends on BR2_TOOLCHAIN_HAS_THREADS_NPTL # hidapi
 	depends on BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_16
 	depends on BR2_TOOLCHAIN_GCC_AT_LEAST_4_9 # hidapi -> libusb
 	select BR2_PACKAGE_HIDAPI
+	select BR2_PACKAGE_HIDAPI_HIDRAW # needs hidapi-hidraw.pc
 	select BR2_PACKAGE_LIBEVDEV
 	select BR2_PACKAGE_LIBGLIB2
 	select BR2_PACKAGE_LIBGUDEV
Signature · 6 lines
2.56.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#6 lore raw

PATCH v2 5/5 DEVELOPERS: add Tomas Mudrunka for hidapi

In reply to Tomas Mudrunka
---
 DEVELOPERS | 3 +++
 1 file changed, 3 insertions(+)
DEVELOPERS +3 -0
index 1d2960f9b3..ad3c776d64 100644
@@ -3412,6 +3412,9 @@ F:	support/testing/tests/package/test_redis.py
 N:	Tobias Waldekranz <[email protected]>
 F:	package/kmemd/
 
+N:	Tomas Mudrunka <[email protected]>
+F:	package/hidapi/
+
 N:	Torben Voltmer <[email protected]>
 F:	package/espflash/
 
Signature · 6 lines
2.56.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot