Skip to content

Conversation

@lsk567
Copy link
Contributor

@lsk567 lsk567 commented Jan 21, 2026

Summary

Fixes the ROS2 C++ build integration by correcting how reactor-cpp exports its CMake configuration for the ament/colcon ecosystem.

Problem

When building LF programs with the ROS2 platform, downstream packages could not find the reactor-cpp library via CMake's find_package(reactor-cpp REQUIRED).

Root cause: The reactor-cpp library was being built and installed correctly by colcon, but its CMake export configuration wasn't set up properly for the ament/colcon ecosystem:

  • The install(EXPORT ...) command was in lib/CMakeLists.txt, but ament requires it to be in the root CMakeLists.txt alongside ament_package() for proper integration
  • The export lacked a NAMESPACE, which meant the generated CMake config file didn't create proper imported targets

Changes

  1. Added ament detection - Detect when building in a colcon/ament environment and set REACTOR_CPP_USE_AMENT

  2. Moved export installation to root CMakeLists.txt - For ament compatibility, the install(EXPORT ...) must be in the same file as ament_package()

  3. Added NAMESPACE to exports - Use NAMESPACE ${LIB_TARGET}:: so downstream packages can link via reactor-cpp::reactor-cpp

  4. Added proper ament exports:

    ament_export_targets(${LIB_TARGET} HAS_LIBRARY_TARGET)
    ament_export_include_directories(include)
    ament_export_libraries(${LIB_TARGET})
    ament_package()

Related PR

🤖 Generated with Claude Code

This commit fixes the ROS2/colcon build integration by properly configuring
CMake exports for the ament ecosystem.

Changes:
- Add ament detection when not building as LF subproject
- Move install(EXPORT) from lib/CMakeLists.txt to root CMakeLists.txt
  (required for ament compatibility - must be alongside ament_package())
- Add NAMESPACE to export for proper imported target creation
- Add ament_export_targets(), ament_export_include_directories(), and
  ament_export_libraries() for full ament integration

The key insight is that ament's build system requires the export installation
and ament_package() to be in the same CMakeLists.txt file. Using namespaced
targets (reactor-cpp::reactor-cpp) ensures proper linkage through CMake's
imported target mechanism.

Related: lf-lang/lingua-franca#2580

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@lsk567 lsk567 force-pushed the fix-ros2-cpp-build branch from ce95a94 to 09b9058 Compare January 21, 2026 17:22
@lsk567 lsk567 requested a review from edwardalee January 21, 2026 17:26
Copy link

@edwardalee edwardalee left a comment

Choose a reason for hiding this comment

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

Wow, this was a complicated one! Thanks for fixing.

@lsk567 lsk567 merged commit 1e520ff into master Jan 21, 2026
9 checks passed
@lsk567 lsk567 deleted the fix-ros2-cpp-build branch January 21, 2026 19:19
@cmnrd
Copy link
Contributor

cmnrd commented Jan 21, 2026

I don't know what prompted this change, but this PR is a regression and problematic in multiple ways.

  1. This change breaks regular installations of reactor-cpp.
  2. The build logic does not detect whether ament is used for the build, but whether ament is installed, which creates new problems for users that have ament installed but are not using it.
  3. reactor-cpp was never intended to be an ament package and the previous package.xml indicated that. I don't know the problem that prompted this "fix", but I don't think that forcing ament in is a solution. Ament should be able to handle pure cmake packages. Likely something changed in the way colcon/ament handle this. The real solution would be to find out what changed and fix the config with what cmake has to offer out of the box.

Could you revert this change as it is a regression and provide a proper fix in a new PR? I am happy to help with finding a fix, but for this I would need to understand the problem first. Also, I would like to ask everyone to stick to proper code reviews and not just blindly trust AI and sign off on PRs because they pass in CI (at least for the scope of this repo).

@edwardalee
Copy link

An alternative is to remove support for ROS altogether. In this PR, I've removed the ROS2 tests, though oddly, the tests remain permanently incomplete with this annotation:
image
Not sure how to fix that without purging the tests altogether.

lsk567 added a commit that referenced this pull request Jan 21, 2026
This reverts commit 1e520ff, reversing
changes made to d568ddd.
@lsk567
Copy link
Contributor Author

lsk567 commented Jan 21, 2026

@cmnrd You are right. Upon closer look, these changes are not ideal. A revert PR has been filed in #82.

The original problem detected, which occurred in this CI run, was that the ROS2 test failed because:

ament_target_dependencies() the passed package name 'reactor-cpp-default'
      was not found before`

This error led to this PR attempting to fix the problem in CI.

It would be really great if you could offer pointers on how to properly fix this problem. Thanks!

@lsk567
Copy link
Contributor Author

lsk567 commented Jan 22, 2026

A reversal of the LF repo is filed here: lf-lang/lingua-franca#2581.

The CI run should show the exact problem that caused the original failure.

cmnrd pushed a commit that referenced this pull request Jan 22, 2026
This reverts commit 1e520ff, reversing
changes made to d568ddd.
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.

4 participants