Rust Client for ROS2

Create a Rust Client for ROS2 from Scratch. Part 1.1: Create the Dynamic Library via CMake & Empy

The easiest way to create an interface code for a target app is by using `CMake` and `empy`. Explore the simplest version of how both can be used in ROS2.

Marshal SHI
8 min readOct 19, 2020


Image by author

This is the second article appearing in this series: Rust Client for ROS2 from Scratch.

The other parts are: 0. Integrate C API to Create ROS2 node


It has been quite some time since I published the first article in this series. Over the last month, I’ve been busy moving into a new apartment and spent most of my time helping set-up our new place — which gave me little time for other things. With the move now complete, it’s been a load off my back and I’ve been able to resume my writing, thinking and working at my regular pace.

Our first article in this series creates a ROS2 interface for our Rust code using bindgen. That article highlights how we can create a node and register it onto the ROS2 network. As we advance through the series, our next goal is to create a ROS2 node in Rust and then send some topic messages out, through that node.

In hindsight, after going through the methods of deploying msg in rclcpp and rclpy, I realized that CMake plays an important role in the msg system. CMake is not only used for installation, but it also helps generate the msg interface files for our target language. (Furthermore, srv and action are handled in CMake as well).

That being said, the CMake code is really hard to follow, since it creates “global” variables (if we use the function in CMake, it results in local scope; but using macro, sets it variable) as well as giving us no “return” value. This makes the usage of CMake code appear super flat, thereby making it difficult to view the bigger picture of overall code.

One way to simplify this process is to dive right into creating a Rust msginterface file. However, a simpler method to implement this process is to create some sample code to mimic the simplest version of creating or using a dynamic library via CMake.



Marshal SHI

Robots make our life easier | Robotics, Reinforcement Learning, Web, Python, Rust & Life Hacking. At