-
Notifications
You must be signed in to change notification settings - Fork 49
Refactor code generation using quote, syn and rayon. #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
3baaa97
to
fa703cb
Compare
fa703cb
to
b659c0d
Compare
b659c0d
to
76c8af9
Compare
The |
Great work @jerry73204 . As discussed in #50 lets go ahead with this pr. I have just rebased this on top of #51 and pushed to master, so it will be easier to make new PRs from here in case @JiangengDong wants to contribute. I also fixed up the last commit with a refresh of the the docs with just the standard ros install to make it pass CI. |
@m-dahl Thanks you merge my work. Just a reminder that the generated bindings in this PR are huge. That's because I installed almost everything on my laptop. It will cause a very long compile time (~5 minutes) for the doc-only feature. Could you please re-generate the bindings for docs.rs using this IDL_PACKAGE_FILTER? The package list comes from the official ROS 2 doc here. export IDL_PACKAGE_FILTER='action_msgs;diagnostic_msgs;geometry_msgs;lifecycle_msgs;map_msgs;move_base_msgs;nav_msgs;pendulum_msgs;rosgraph_msgs;sensor_msgs;shape_msgs;statistics_msgs;std_msgs;stereo_msgs;test_msgs;tf2_geometry_msgs;tf2_msgs;trajectory_msgs;unique_identifier_msgs;visualization_msgs' I use this procedure to refresh the bindings. rm -rf target
rm r2r*/bindings/*
cargo build --features save-bindgen
cargo build --features doc-only # make sure the bindings work |
Yes I noticed it was huge so I modified your last commit before pushing. I refreshed them using humble-desktop + test_msgs. Perhaps we should make a script for refreshing using that standard package list? |
Refresh bindings with new codegen by #58
This work thoroughly rewrites the code generation parts of this project. With the help of
syn
andquote
, it processes code in tokens instead of string manipulation. It applies several tricks to speed up the codegen process, including parallelism and bindgen allowlist. It fixes thedoc-only
feature so that it can create API docs without ROS installed.quote
andsyn
crates to parse the bindgen code into tokens instead of string manipulation. The approach promises error-free code generation. It fixes a known bug that it did not parse array typed fields[T; N]
correctly.rayon
to speed up the code generation process. It enablesbuild.rs
to process manyRosMsg
in parallel on a multi-core machine, and now thebuild.rs
can finish in a few seconds.phf::Map
to speed up the lookup process in runtime. The changes are made inUntypedServiceSupport::new_from()
,INTROSPECTION_FNS,
andCONSTANTS_MAP.
bindgen
to speed up the codegen process. Though it's still the slowest part overall, it still saves a few minutes.doc-only
feature to produce API docs without actually linking ROS dynamic link libraries.