Declare rust_packages only when installing Rust IDL bindings #380
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As discussed here there was a strange error that made it impossible to use ros2_rust in an underlay workspace. Packages that have no association to Rust were declaring themselves in the
rust_packages
ament index. This was causing downstream colcon workspaces to redirect their.cargo/config.toml
file towards non-existent directories. When cargo is directed towards non-existent directories, it considers the situation a build error and exits immediately.After some challenging investigation, I narrowed the problem down to this: Packages that contain any message definitions were invoking the
rosidl_generator_rs
's extension to the ROS IDL generation pipeline. That extension included the lineament_index_register_resource("rust_packages")
. For a normal message package that would be fine, but some packages have message definitions that are purely internal to the package for testing purposes and not installed (using theSKIP_INSTALL
option ofrosidl_generate_interfaces
). Since the messages are not installed in these cases, we also do not install the Rust bindings, which makes perfect sense. However, if we declare the package under therust_packages
index, then colcon-ros-cargo will expect a Rust package even though one does not exist.This PR solves the problem in an extremely simple way: The
rosidl_generator_rs
extension will only declare a package into therust_packages
index if the message package is being installed. I've done an A/B test on this change and confirmed that building an rclrs node in a downstream workspace is impossible without this, but works perfectly fine with the changes in this PR.