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:
ros2_launch Bazel macro.ros2_test Bazel macro.ros2_plugin Bazel macro.spdlog (default): --@com_github_mvukov_rules_ros2//ros2:rcl_logging_impl=spdlogsyslog: --@com_github_mvukov_rules_ros2//ros2:rcl_logging_impl=syslogfoxglove_bridge for visualization and debuggingros2_bag for handling rosbagsros2_lifecycle for handling node lifecycleros2_node for handling nodesros2_param for handling parametersros2_service for handling servicesros2_topic for handling topicsxacro for Xacro to URDF conversionPlease 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.