镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Fix rosidl_generator_py assuming incorect library names - #149

Merged
sloretz merged 1 commit into
masterfrom
fix_python_assuming_library_names
Jan 11, 2022
Merged

sloretz merged 1 commit into
masterfrom
fix_python_assuming_library_names

Conversation

@sloretz

@sloretz sloretz commented Dec 10, 2021 •

Copy link
Copy Markdown
Contributor

Requires ament/ament_cmake#371

rosidl_generator_py was assuming all interface packages being depended
upon call their interface generation target name "${PROJECT_NAME}", but
that's an incorrect assumption. The target name is a required argument
to rosidl_generate_interfaces(). This fixes it by exporting the python
library target using an existing CMake macro for that purpose called
rosidl_export_typesupport_targets() and ament_export_targets().

I works by adding a variable
"${PROJECT_NAME}_TARGETS__rosidl_generator_py" which is set when the
interface package is find_package()d. That variable contains the
targets generated by rosidl_generator_py so that downstream interface
packages can depend on it.

Since targets are being exported, a bug where build time include paths were marked PUBLIC also needed to be fixed.

I discovered this bug while working on ament/ament_cmake#365, and I need it fixed for ros2/rcl_interfaces#133

@sloretz sloretz self-assigned this Dec 10, 2021
@sloretz

sloretz commented Dec 10, 2021

Copy link
Copy Markdown
Contributor Author

CI (build: --packages-above-and-dependencies rosidl_generator_py test: --packages-above rosidl_generator_py)

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@sloretz

sloretz commented Dec 23, 2021 •

Copy link
Copy Markdown
Contributor Author

Trying Windows with repos file with this and ament/ament_cmake#371 Build Status

Re-run Build Status

re-re-run Build Status

re-re-re run Build Status

re-re-re-re run Build Status

re-re-re-re-re run Build Status

rosidl_generator_py was assuming all interface packages being depended
upon call their interface generation target name "${PROJECT_NAME}", but
that's an incorrect assumption. The target name is a required argument
to rosidl_generate_interfaces. This fixes it by exporting the python
library target using an existing CMake macro for that purpose called
rosidl_export_typesupport_targets() and amen_export_targets()

I works by adding a variable
"${PROJECT_NAME}_TARGETS__rosidl_generator_py" which is set when the
interface package is `find_package()`d. That variable contains the
targets generated by `rosidl_generator_py` so that downstream interface
packages can depend on it.

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
@sloretz
sloretz force-pushed the fix_python_assuming_library_names branch from 277ae86 to ffb0eea Compare January 4, 2022 19:45
@sloretz

sloretz commented Jan 4, 2022 •

Copy link
Copy Markdown
Contributor Author

CI re-run

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status
    • Re-run to see if test failures are consistent: Build Status
    • All appear in the repeated job except launch_testing_ros.test.examples.set_param_launch_test.set_param_launch_test, investigating.

@sloretz

sloretz commented Jan 10, 2022

Copy link
Copy Markdown
Contributor Author

launch_testing_ros.test.examples.set_param_launch_test.set_param_launch_test

I'm unable to reproduce this failure in a local windows VM. It's flakiness seems to be a known issue: ros2/launch_ros#280

@sloretz

sloretz commented Jan 10, 2022

Copy link
Copy Markdown
Contributor Author

CI re-run one last time because of flaky tests above (build: --packages-above-and-dependencies rosidl_generator_py test: --packages-above rosidl_generator_py)

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@sloretz

sloretz commented Jan 11, 2022

Copy link
Copy Markdown
Contributor Author

CI LGTM, only two windows test failures are rosbag2 ones that are also in the nightly.

@sloretz
sloretz merged commit 0f43ffc into master Jan 11, 2022
@delete-merged-branch
delete-merged-branch Bot deleted the fix_python_assuming_library_names branch January 11, 2022 18:05
mini-1235 added a commit to mini-1235/ros-rolling that referenced this pull request Sep 27, 2026
…RGETS

Replace the macOS-only patch with a cross-platform one:

- Restore rosidl_generator_py_suffix ("__rosidl_generator_py"), which
  ros2/rosidl_python#140 accidentally dropped. The existing dependency
  loop then links other interface packages' Python bindings through the
  dedicated <pkg>_TARGETS__rosidl_generator_py list again, as intended by
  ros2/rosidl_python#149.
- Export the library only in <pkg>_TARGETS__rosidl_generator_py (an
  installed export file plus a config extras file) instead of with
  ament_export_targets(), which always adds it to <pkg>_TARGETS. C/C++
  consumers of an interface package no longer link it.
- Link Python3::Module instead of Python3::Python on all platforms: the
  library is only linked by Python extension modules, which get the
  CPython symbols from the interpreter that loads them.

rosidl_generator_py is bumped to build 26 so CI rebuilds it, together
with rosidl_core_generators and rosidl_default_generators (so that
rattler-build builds the generator before the interface packages that
use it) and builtin_interfaces (std_msgs' Python bindings link its
Python bindings through the new list). The regression test added in the
previous commit now passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Maurice <mauricepurnawan@gmail.com>
mini-1235 added a commit to mini-1235/ros-rolling that referenced this pull request Sep 27, 2026
…RGETS

Replace the patch that compiled the Python bindings into the extension
modules with a smaller one that is closer to upstream's original design
(ros2/rosidl_python#149):

- Restore rosidl_generator_py_suffix ("__rosidl_generator_py"), which
  ros2/rosidl_python#140 accidentally dropped. The existing dependency
  loop then links other interface packages' Python bindings through the
  dedicated <pkg>_TARGETS__rosidl_generator_py list again.
- Export the library only in <pkg>_TARGETS__rosidl_generator_py (an
  installed export file plus a config extras file) instead of with
  ament_export_targets(), which always adds it to <pkg>_TARGETS. C/C++
  consumers of an interface package no longer link it.
- Link Python3::Module instead of Python3::Python on all platforms: the
  library is only linked by Python extension modules, which get the
  CPython symbols from the interpreter that loads them.

Also update the std_msgs regression test as suggested in review: build
the C++ consumer with cxx-compiler (no LDFLAGS, like a user environment)
instead of compiler('cxx') + clearing LDFLAGS, and depend on ros2-rclpy.

No build number bumps: this goes into the full rebuild, which rebuilds
all interface packages with the new generator.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Maurice <mauricepurnawan@gmail.com>
mini-1235 added a commit to mini-1235/ros-rolling that referenced this pull request Sep 27, 2026
…RGETS

Replace the patch that compiled the Python bindings into the extension
modules with a smaller one that is closer to upstream's original design
(ros2/rosidl_python#149):

- Restore rosidl_generator_py_suffix ("__rosidl_generator_py"), which
  ros2/rosidl_python#140 accidentally dropped. The existing dependency
  loop then links other interface packages' Python bindings through the
  dedicated <pkg>_TARGETS__rosidl_generator_py list again.
- Export the library without ament_export_targets(), which always adds it
  to <pkg>_TARGETS: install the export set and include it from a config
  extras file, and keep rosidl_export_typesupport_targets(), which adds the
  imported target to <pkg>_TARGETS__rosidl_generator_py only. C/C++
  consumers of an interface package no longer link it.
- Link Python3::Module instead of Python3::Python on all platforms: the
  library is only linked by Python extension modules, which get the
  CPython symbols from the interpreter that loads them.

Also update the std_msgs regression test as suggested in review: build
the C++ consumer with cxx-compiler (no LDFLAGS, like a user environment)
instead of compiler('cxx') + clearing LDFLAGS, and depend on ros2-rclpy.

No build number bumps: this goes into the full rebuild, which rebuilds
all interface packages with the new generator.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Maurice <mauricepurnawan@gmail.com>
traversaro pushed a commit to RoboStack/ros-rolling that referenced this pull request Sep 28, 2026
…RGETS

Replace the patch that compiled the Python bindings into the extension
modules with a smaller one that is closer to upstream's original design
(ros2/rosidl_python#149):

- Restore rosidl_generator_py_suffix ("__rosidl_generator_py"), which
  ros2/rosidl_python#140 accidentally dropped. The existing dependency
  loop then links other interface packages' Python bindings through the
  dedicated <pkg>_TARGETS__rosidl_generator_py list again.
- Export the library without ament_export_targets(), which always adds it
  to <pkg>_TARGETS: install the export set and include it from a config
  extras file, and keep rosidl_export_typesupport_targets(), which adds the
  imported target to <pkg>_TARGETS__rosidl_generator_py only. C/C++
  consumers of an interface package no longer link it.
- Link Python3::Module instead of Python3::Python on all platforms: the
  library is only linked by Python extension modules, which get the
  CPython symbols from the interpreter that loads them.

Also update the std_msgs regression test as suggested in review: build
the C++ consumer with cxx-compiler (no LDFLAGS, like a user environment)
instead of compiler('cxx') + clearing LDFLAGS, and depend on ros2-rclpy.

No build number bumps: this goes into the full rebuild, which rebuilds
all interface packages with the new generator.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Maurice <mauricepurnawan@gmail.com>
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.

2 participants