Skip to content

Make rcpputils optional - #251

Open
chhtz wants to merge 7 commits into
ros:rollingfrom
dfki-ric:optional-rcpputils
Open

chhtz wants to merge 7 commits into
ros:rollingfrom
dfki-ric:optional-rcpputils

Conversation

@chhtz

@chhtz chhtz commented Nov 20, 2026

Copy link
Copy Markdown

This fixes #211. @mjcarroll

Adding a new option CLASS_LOADER_USE_RCPPUTILS (default: NOT CLASS_LOADER_IGNORE_AMENT)
If ON, this is essentially just does

using SharedLibrary = rcpputils::SharedLibrary;
using rcpputils::get_platform_library_name;

and corresponding changes where these are used. Keeps the ABI completely unchanged.
Otherwise, it provides a lightweight re-implementation of SharedLibrary (only of required functionality).
Code is modeled on rcutils implementation of rcutils_load_shared_library(), etc.

Additional changes:

  • Don't require console_bridge_vendor if CLASS_LOADER_IGNORE_AMENT=ON
  • Fix pkg-config and install CMake configuration files when building without ament
  • Allow running unit tests without ament
  • Add CI to build with CLASS_LOADER_USE_RCPPUTILS=OFF, or with no ROS at all (main issue in ROS independent builds with rolling release? #211).

I split these into logical steps to help reviewing.

Successfully tested locally in Ubuntu 24 and 26 dockers (Windows+macOS paths are untested).

Backport to lyrical would be possible with some adaptations (this would allow using this with C++17 instead of C++20)

Disclaimer: Code was written with assistance of Claude Opus 5.5, but all generated code was reviewed by a human (me)

console_bridge_vendor only builds console_bridge on platforms where it
is not found otherwise, and makes it findable via environment hooks.
Finding console_bridge_vendor does not influence which console_bridge
is found, so builds without ament (CLASS_LOADER_IGNORE_AMENT) only need
console_bridge itself, which is available from the usual package
managers.

Signed-off-by: Christoph Hertzberg <christoph.hertzberg@dfki.de>
rcpputils (and thereby rcutils) was only used for
rcpputils::SharedLibrary and rcpputils::get_platform_library_name().
The new CMake option CLASS_LOADER_USE_RCPPUTILS (default: ON, or OFF
if CLASS_LOADER_IGNORE_AMENT is set) allows to use a minimal built-in
replacement instead, so class_loader can be built without any ROS
packages.

The new header class_loader/shared_library.hpp selects the
implementation. Without rcpputils, CLASS_LOADER_NO_RCPPUTILS is defined
for the library and its users. With rcpputils, the exported symbols
are unchanged.

The public headers require C++20, which users previously only got
through rcpputils, so declare it as an interface requirement of
class_loader.

Fixes ros#211

Signed-off-by: Christoph Hertzberg <christoph.hertzberg@dfki.de>
The file is configured into CMAKE_CURRENT_BINARY_DIR, which differs
from CMAKE_BINARY_DIR if class_loader is built via add_subdirectory()
or FetchContent.

Signed-off-by: Christoph Hertzberg <christoph.hertzberg@dfki.de>
- The headers are installed into include/class_loader/class_loader, so
  add include/class_loader to the include path (as the CMake target
  does).
- Require console_bridge instead of adding ${console_bridge_LIBRARIES},
  which is a CMake target name.
- Set the version (from package.xml) and a description.
- Add -DCLASS_LOADER_NO_RCPPUTILS if built without rcpputils.

Signed-off-by: Christoph Hertzberg <christoph.hertzberg@dfki.de>
This provides the target class_loader::class_loader and
class_loader_hide_library_symbols() as in ament builds. As in ament
builds, any newer version is considered compatible.

Signed-off-by: Christoph Hertzberg <christoph.hertzberg@dfki.de>
Without ament, use GoogleTest from the system and a minimal replacement
of ament_add_gtest(). It prepends the library directories to the
library path, so that the tests do not pick up an installed
class_loader.

Signed-off-by: Christoph Hertzberg <christoph.hertzberg@dfki.de>
- Add a configuration without rcpputils to the industrial_ci matrix.
- Add a job that builds class_loader without ament on plain Ubuntu,
  runs its tests, and builds one of the tests against the installed
  library, using both the CMake package configuration and pkg-config.

Signed-off-by: Christoph Hertzberg <christoph.hertzberg@dfki.de>

@mjcarroll mjcarroll left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice split, and the ON path being a pure alias keeps the ABI unchanged. The pkg-config/install fixes are good catches. Before merging I'd like to see the new Actions jobs run and a ci.ros2.org run including Windows, since the new LoadLibraryA/GetModuleFileNameA code is only compiled there.

Comment thread CMakeLists.txt
Comment on lines 85 to +86
PUBLIC ${console_bridge_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${console_bridge_LIBRARIES})
target_link_libraries(${PROJECT_NAME} PUBLIC ${console_bridge_LIBRARIES})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These get baked into the installed class_loaderTargets.cmake, and console_bridge_LIBRARIES is often a bare name or build-machine path that find_dependency(console_bridge) can't fix. Can we link console_bridge::console_bridge here too, like the ament branch?

Comment thread CMakeLists.txt
${console_bridge_LIBRARIES}
)
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/package.xml" _package_xml)
string(REGEX MATCH "<version>([^<]*)</version>" _ "${_package_xml}")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This misses <version compatibility="..."> and would leave PROJECT_VERSION empty. Maybe message(FATAL_ERROR) if CMAKE_MATCH_1 is empty.

Comment thread CMakeLists.txt
Comment on lines +129 to +130
if(NOT CLASS_LOADER_USE_RCPPUTILS)
set(PKGCONFIG_CFLAGS "-DCLASS_LOADER_NO_RCPPUTILS")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With CLASS_LOADER_USE_RCPPUTILS=ON and no ament, the .pc has no rcpputils flags (rcpputils ships no .pc), so pkg-config consumers can't build. Document it, or warn for that combination.

Comment thread CMakeLists.txt
else()
set(_use_rcpputils_default ON)
endif()
option(CLASS_LOADER_USE_RCPPUTILS

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document this option (and CLASS_LOADER_IGNORE_AMENT) in the README plus a changelog entry. Worth noting that OFF defines CLASS_LOADER_NO_RCPPUTILS publicly, since mixing it with consumers that define it differently is an ODR problem.

Comment thread test/CMakeLists.txt
# Only APPEND_LIBRARY_DIRS is supported. These dirs are prepended (not appended as by ament),
# so that the tests do not pick up an installed class_loader.
function(ament_add_gtest target)
cmake_parse_arguments(ARG "" "" "APPEND_LIBRARY_DIRS" ${ARGN})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other ament_add_gtest args (TIMEOUT, ENV, ...) end up in ARG_UNPARSED_ARGUMENTS and get passed to add_executable as sources, which fails confusingly. Parse the common keywords and warn that they're ignored.

Comment thread src/shared_library.cpp
Comment on lines +101 to +109
handle_ = dlopen(library_path.c_str(), RTLD_LAZY);
if (!handle_) {
const char * error = dlerror();
throw std::runtime_error(std::string("dlopen error: ") + (error ? error : "unknown error"));
}
library_path_ = library_path;
#ifdef CLASS_LOADER_HAS_DLINFO
struct link_map * map = nullptr;
if (dlinfo(handle_, RTLD_DI_LINKMAP, &map) == 0 && map && map->l_name && map->l_name[0]) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This path is untested on Windows/macOS. Could we add a small gtest for the new class: get_library_path() non-empty for a loaded plugin, unload_library() twice throws, bad path throws runtime_error? Right now it's only covered indirectly via class_loader_core.

Comment thread src/shared_library.cpp
if (handle_) {
const std::string error = closeLibrary(handle_);
if (!error.empty()) {
std::cerr << error << std::endl;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can run during static destruction (see #253). std::cerr is safe here, but CONSOLE_BRIDGE_logError would match the rest of the library. Optional.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude says that console_bridge's global handler may already be destroyed during static destruction and rcpputils::SharedLibrary's destructor does the same. I'll keep it

Comment thread .github/workflows/ci.yaml
env:
INSTALL_PREFIX: ${{ github.workspace }}/install
steps:
- uses: actions/checkout@v2

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actions/checkout@v2 is deprecated; please use @v4 for the new job. Optional.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would update to @v7 in that case (v4 also gives deprecation warnings). And I would upgrade both

@mjcarroll mjcarroll self-assigned this Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ROS independent builds with rolling release?

2 participants