Repository navigation
Conversation
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>
There was a problem hiding this comment.
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.
| PUBLIC ${console_bridge_INCLUDE_DIRS}) | ||
| target_link_libraries(${PROJECT_NAME} ${console_bridge_LIBRARIES}) | ||
| target_link_libraries(${PROJECT_NAME} PUBLIC ${console_bridge_LIBRARIES}) |
There was a problem hiding this comment.
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?
| ${console_bridge_LIBRARIES} | ||
| ) | ||
| file(READ "${CMAKE_CURRENT_SOURCE_DIR}/package.xml" _package_xml) | ||
| string(REGEX MATCH "<version>([^<]*)</version>" _ "${_package_xml}") |
There was a problem hiding this comment.
This misses <version compatibility="..."> and would leave PROJECT_VERSION empty. Maybe message(FATAL_ERROR) if CMAKE_MATCH_1 is empty.
| if(NOT CLASS_LOADER_USE_RCPPUTILS) | ||
| set(PKGCONFIG_CFLAGS "-DCLASS_LOADER_NO_RCPPUTILS") |
There was a problem hiding this comment.
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.
| else() | ||
| set(_use_rcpputils_default ON) | ||
| endif() | ||
| option(CLASS_LOADER_USE_RCPPUTILS |
There was a problem hiding this comment.
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.
| # 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}) |
There was a problem hiding this comment.
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.
| 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]) { |
There was a problem hiding this comment.
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.
| if (handle_) { | ||
| const std::string error = closeLibrary(handle_); | ||
| if (!error.empty()) { | ||
| std::cerr << error << std::endl; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
| env: | ||
| INSTALL_PREFIX: ${{ github.workspace }}/install | ||
| steps: | ||
| - uses: actions/checkout@v2 |
There was a problem hiding this comment.
actions/checkout@v2 is deprecated; please use @v4 for the new job. Optional.
There was a problem hiding this comment.
I would update to @v7 in that case (v4 also gives deprecation warnings). And I would upgrade both
This fixes #211. @mjcarroll
Adding a new option
CLASS_LOADER_USE_RCPPUTILS(default:NOT CLASS_LOADER_IGNORE_AMENT)If
ON, this is essentially just doesand 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:
console_bridge_vendorifCLASS_LOADER_IGNORE_AMENT=ONCLASS_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)