ROS2 for Rust (rclrs)
Write ROS2 applications in Rust
Basic Installation Method from GitHub
# Install Rust, e.g. as described in https://rustup.rs/
# Install ROS 2 as described in https://docs.ros.org/en/humble/Installation.html
# Assuming you installed the minimal version of ROS 2, you need these additional packages:
sudo apt install -y git libclang-dev python3-pip python3-vcstool # libclang-dev is required by bindgen
# Install these plugins for cargo and colcon:
pip install git+https://github.com/colcon/colcon-cargo.git
pip install git+https://github.com/colcon/colcon-ros-cargo.git
mkdir -p workspace/src && cd workspace
git clone https://github.com/ros2-rust/ros2_rust.git src/ros2_rust
vcs import src < src/ros2_rust/ros2_rust_humble.repos
source /opt/ros/humble/setup.bash
colcon buildThe Question: Should We Build This in Every Workspace?
What if we could apply this system-wide?
Looking at the ROS installation:
$ cd /opt
$ ls
rosThe ROS system folder is here, so why donāt we clone the āros2_rustā folder here as well?
System-wide Installation Steps
1. Create the system directory
cd /opt
sudo mkdir -p rust_ros2/src && cd rust_ros22. Clone the repository
git clone https://github.com/ros2-rust/ros2_rust.git src/ros2_rustIf you encounter a permission error:
fatal: could not create work tree dir 'src/ros2_rust': Permission denied
3. Fix permissions
sudo chown -R $USER:$USER .4. Import dependencies and build
vcs import src < src/ros2_rust/ros2_rust_humble.repos
colcon build --symlink-installSource System-wide
Edit your shell configuration file:
vim ~/.bashrc # for bash
# or
vim ~/.zshrc # for zshAdd these lines:
source /opt/ros/humble/setup.zsh # Original ROS2
source /opt/rust_ros2/install/setup.zsh # ROS2 RustBenefits of System-wide Installation
- No need to rebuild for each workspace
- Consistent environment across all projects
- Reduced disk usage by avoiding duplicate builds
- Easier maintenance with a single installation point
Adding Custom Message Types
If you want to use additional message types (like Ackermann messages), you can add them to the system-wide installation:
cd /opt/rust_ros2/src/ros2_rust/common_interfaces
git clone https://github.com/ros-drivers/ackermann_msgs.git -b ros2Then rebuild the system-wide installation:
cd /opt/rust_ros2
colcon build --symlink-installThis will make the new message types available system-wide for all your ROS2 Rust projects.
Usage
After completing the system-wide installation and sourcing the setup files, you can use ROS2 Rust in any workspace without additional setup steps. Simply create your Rust ROS2 packages and build them with colcon build as usual.