Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix (re-)detection of libmodbus RTU USB support with static libmodbus builds #2677

Merged
merged 10 commits into from
Nov 13, 2024

Conversation

jimklimov
Copy link
Member

@jimklimov jimklimov commented Nov 12, 2024

...and allow users to require configure --with-modbus+usb to avoid surprises with a wrong choice of the library.

Should help with investigation for #2666 and fixes a bug detected in that discussion.

Also revise configuration script report.

Closes: #2676

Example runs with failsafe firing (where the OS has a packaged standard shared libmodbus; a custom static build with USB support is installed into --prefix=/tmp)

NEGATIVE CASES

  • Use new options and cause use of OS-provided library (by default):
:: ./autogen.sh && ./configure --with-modbus+usb
  • Legacy common case: explicitly request apc_modbus and libusb among configure options (and still use OS-provided library):
:; ./configure --with-drivers=apc_modbus --with-usb
  • Legacy common case: explicitly request libmodbus and libusb, but passing --with-modbus-includes and/or --with-modbus-libs for a build that is not USB-capable (done here via bad location of --with-modbus-libs):
:; ./configure --with-modbus --with-usb --with-modbus-includes=-I/tmp/include/modbus --with-modbus-libs="-L/tmp/libxxx -lmodbus"

These all end with:

...
checking for modbus.h... yes
checking for modbus_new_rtu... yes
checking for modbus_new_tcp... yes
checking for modbus_set_byte_timeout... yes
checking for modbus_set_response_timeout... yes
checking for modbus_new_rtu_usb... no
configure: Retry detection of libmodbus USB support
checking for modbus_new_rtu_usb... no
configure: WARNING: Both --with-modbus and --with-usb were requested, and a libmodbus was found, but it seems to not support USB. You may require a custom build per https://github.com/networkupstools/nut/wiki/APC-UPS-with-Modbus-protocol
...
configure: error: modbus library variant with RTU USB support not found, required for USB-capable Modbus drivers

POSITIVE CASES

  • Legacy common case: explicitly request libmodbus and libusb, explicitly passing correct --with-modbus-includes and --with-modbus-libs for a build that is USB-capable:
:; ./configure --with-modbus --with-usb --with-modbus-includes=-I/tmp/include/modbus --with-modbus-libs="-L/tmp/lib -lmodbus"
  • Request the apc_modbus driver AND libusb, explicitly passing correct --with-modbus-includes and --with-modbus-libs for a build that is USB-capable:
:; ./configure --with-drivers=apc_modbus --with-usb --with-modbus-includes=-I/tmp/include/modbus --with-modbus-libs="-L/tmp/lib -lmodbus"
  • Use new option and pass correct --with-modbus-includes and --with-modbus-libs for a build that is USB-capable:
:: ./configure --with-modbus+usb --with-modbus-includes=-I/tmp/include/modbus --with-modbus-libs="-L/tmp/lib -lmodbus"
```

These all end with:
```
...
checking for libmodbus version via pkg-config... 3.1.6 found
checking for libmodbus cflags... -I/tmp/include/modbus
checking for libmodbus ldflags... -L/tmp/lib -lmodbus
checking for modbus.h... yes
checking for modbus_new_rtu... yes
checking for modbus_new_tcp... yes
checking for modbus_set_byte_timeout... yes
checking for modbus_set_response_timeout... yes
checking for modbus_new_rtu_usb... no
configure: Retry detection of libmodbus USB support
checking for modbus_new_rtu_usb... yes
checking types of arguments for modbus_set_byte_timeout... sec_usec_uint32_cast_timeval_fields
Found types to use for modbus_set_byte_timeout: sec_usec_uint32_cast_timeval_fields
...
* build Modbus drivers: yes
* build Modbus drivers with RTU USB support:    yes

The resulting driver build reports its USB-capability early in debug log now (see second [D1] line) as well as via DRIVER_NAME seen in banner and protocol (upsc etc.):

:; ./drivers/apc_modbus -D -V
Network UPS Tools 2.8.2.1179.10-1189-geb99e125f (development iteration after 2.8.2) - NUT APC Modbus driver with USB support 0.10
   0.000000     [D1] Using USB implementation: libusb-1.0.25 (API: 0x1000109)
   0.000040     [D1] This build of the driver is USB-capable; also Serial and TCP Modbus RTU are supported
   0.000055     [D1] Network UPS Tools version 2.8.2.1179.10-1189-geb99e125f (development iteration after 2.8.2) built with gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 and configured with flags: --with-modbus+usb --without-docs --with-modbus-includes=-I/tmp/include/modbus --with-modbus-libs='-L/tmp/lib -lmodbus'
   0.000088     [D1] upsnotify: notify about state 4 with libsystemd: was requested, but not running as a service unit now, will not spam more about it
   0.000117     [D1] upsnotify: failed to notify about state 4: no notification tech defined, will not spam more about it

NEUTRAL CASES

The apc_modbus driver is build using OS packaged libmodbus, without USB support, without aborting NUT build (common packaging).

  • Explicitly requesting the apc_modbus driver but not explicitly requesting libusb:
:; ./configure --with-drivers=apc_modbus
...
* build Modbus drivers: yes
* build Modbus drivers with RTU USB support:    no
...

:; ./drivers/apc_modbus -D -V
Network UPS Tools 2.8.2.1179.10-1189-geb99e125f (development iteration after 2.8.2) - NUT APC Modbus driver without USB support 0.10
   0.000000     [D1] This build of the driver is not USB-capable, only Serial and TCP Modbus RTU are supported
   0.000030     [D1] Network UPS Tools version 2.8.2.1179.10-1189-geb99e125f (development iteration after 2.8.2) built with gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 and configured with flags: --with-drivers=apc_modbus --without-docs
   0.000061     [D1] upsnotify: notify about state 4 with libsystemd: was requested, but not running as a service unit now, will not spam more about it
   0.000098     [D1] upsnotify: failed to notify about state 4: no notification tech defined, will not spam more about it
  • Default build requesting everything (but not specific combos explicitly expected by fallbacks tested above):
:; ./configure --with-all
  • Even a build with libusb and libmodbus but without custom options for the latter (nor the specific driver):
:; ./configure --without-docs --with-usb --with-modbus

@jimklimov jimklimov added enhancement documentation APC USB CI Entries related to continuous integration infrastructure (historically also recipes like Makefiles) modbus portability We want NUT to build and run everywhere possible impacts-release-2.8.2 Issues reported against NUT release 2.8.2 (maybe vanilla or with minor packaging tweaks) labels Nov 12, 2024
@jimklimov jimklimov added this to the 2.8.3 milestone Nov 12, 2024
@jimklimov jimklimov merged commit eb99e12 into networkupstools:master Nov 13, 2024
30 checks passed
@jimklimov jimklimov deleted the issue-2666 branch November 13, 2024 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
APC CI Entries related to continuous integration infrastructure (historically also recipes like Makefiles) documentation enhancement impacts-release-2.8.2 Issues reported against NUT release 2.8.2 (maybe vanilla or with minor packaging tweaks) modbus portability We want NUT to build and run everywhere possible USB
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CI: Configuration report of features (first block) can benefit from some line-grouping
1 participant