Re-Export Generated Messages in rclrs #556
Open
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.
Summary
Working example of re-exporting of the generated interface crates found on the AMENT_PREFIX_PATH env var. With this change generated interface symbols are available directly from
rclrs::, so for example,rclrs::std_msgs::msg::Stringis how you'd access the String type of the generated rust code for the std_msgs package.This depends on ros2-rust/rosidl_rust#12 for fully relocatable symbols.
The way we find the generated code is as follows
AMENT_PREFIX_PATH, look for ashare/directory.share/look for<package>/rust/Cargo.tomlwithin that entry, with the metadata to re-export symbols,include!all source files withinsrc/such that all symbols resolve the same.i.e.
std_msgs::msg::Stringfor a standalone crate build, is effectively the same symbol asrclrs::std_msgs::msg::String.There is still some work needed here, namely I do not have tests fully passing, but I wanted to get this out there early for folks to see it as an option. I believe it to be a viable alternative to patching, and also effectively eliminates the need for vendoring some messages.
Open questions
How does
AMENT_PREFIX_PATHget populated? If its populated as colcon is building packages (which I believe to be the case), then this will also re-export symbols in your own workspace as well as sourced overlays.Should this actually go into
rclrsor a separate crate (i.e. ros_msgs?) By going into rclrs we eliminate the need for vendoring.Its important to know that if we re-build rclrs, and the
AMENT_PREFIX_PATHenv var has changed, then the build.rs will be re-built, which will then re-build all of the generated code.Honestly, I'm not sure if we can really get around this. Rust just really wants you to recompile the code you're using each time you invoke
cargo. We can and should have everything in a colcon workspace share a target directory, but this won't stop all rebuilds. Its possible we expect compiled.rlibs in the share directory and we generate a file which hasextern cratecalls to force rustc to find the dependencies, but this will likely not work with any intellisense, and its overall pretty fragile IMO.