This repo provides functionality to build and use ROS 2 with Bazel.
You will need to install Bazel, see here. Besides Bazel, you will need a C++ compiler and a Python 3 interpreter.
And no, you don't have to install any ROS 2 packages via apt.
The code is developed and tested on Ubuntu 22.04 with Python 3.10.
Available features:
- Building of C++, Python and Rust nodes.
- C/C++/Python/Rust code generation for interfaces (messages, services and actions).
- Defining ROS 2 deployments with
ros2_launchBazel macro. - Defining ROS 2 tests with
ros2_testBazel macro. - Defining ROS 2 plugins with
ros2_pluginBazel macro. - Only CycloneDDS middleware can be used at the moment.
- Zero copy transport via shared memory backend (iceoryx) for CycloneDDS.
- Logging backends:
spdlog(default):--@com_github_mvukov_rules_ros2//ros2:rcl_logging_impl=spdlogsyslog:--@com_github_mvukov_rules_ros2//ros2:rcl_logging_impl=syslog
- Utilities:
foxglove_bridgefor visualization and debuggingros2_bagfor handling rosbagsros2_lifecyclefor handling node lifecycleros2_nodefor handling nodesros2_paramfor handling parametersros2_servicefor handling servicesros2_topicfor handling topicsxacrofor Xacro to URDF conversion
Please take a look at the examples folder to get started.
ROS 2 packages are by default locked to versions from release-humble-20250721.
Note
Unlike ROS genmsg which refuses to generate code if the deps between interface targets are not set correctly, code generation for ROS 2 seems to not care about this. If the deps are not correctly set, you'll only see failures during compilation of the generated code.
For alternative approaches, see:
ApexAI/rules_rosRobotLocomotion/drake-ros/bazel_ros2_rules, which includes a brief analysis of this and other approaches.