ros2_rust icon indicating copy to clipboard operation
ros2_rust copied to clipboard

Link against ROS crates for a new ROS node

Open George-Gi opened this issue 8 months ago • 5 comments

I have created a new ROS node and I have declared its dependencies in its Cargo.toml. If I do a symlink of my node's .cargo to the /ros2_ws/.cargo , cargo build works fine. However, if I don't do this symlink, the ROS crates can't be found or I have to explicitly declare their path like sensor_msgs = { version = "5.3.6", path = "/workspace/ros2_ws/install/sensor_msgs/share/sensor_msgs/rust" }. Is there another method that I am missing? I want to avoid the overhead of explicitly adding the paths and I still need the .cargo of my project to declare some env variables in the config.toml

George-Gi avatar May 12 '25 15:05 George-Gi

You are missing a colcon tool. Please install all the requirements mentionned in the README.

romainreignier avatar May 12 '25 16:05 romainreignier

You are missing a colcon tool. Please install all the requirements mentionned in the README.

Thank you for the answer. I have followed the instructions of the Readme, could you please indicate which exactly tool is missing so that I can verify? I went through the instructions again but with no luck

George-Gi avatar May 13 '25 08:05 George-Gi

I don't know which one is missing.

romainreignier avatar May 13 '25 08:05 romainreignier

Double check that you've got colcon-ros-cargo installed, and rosidl_rust needs to be built and sourced in your ros2_ws/.

I think this is essentially the same issue you saw here https://github.com/ros2-rust/ros2_rust/issues/472

colcon-ros-cargo will write to a .cargo/config.toml file in your workspace root (or wherever you're calling colcon build from). Cargo has some rules about what .cargo/ folder is actually looked at during a build as well. ~~I don't know your project setup, but if you also have a .cargo/ config folder floating around, our dependency patching needs to go into that same folder, otherwise one will be ignored.~~

EDIT: Turns out cargo will actually attempt to unify them. So it shouldn't matter if your .cargo/ is in a different location, unless you're using a cargo workspace

At present, when being invoked from a workspace, Cargo does not read config files from crates within the workspace.

If you're still stuck a high level view of your project structure would help me to assist you further 🙂

maspe36 avatar May 31 '25 15:05 maspe36

You can do it without Colcon-ROS-Cargo if your non-crates.io dependencies are explicitly set.

[dependencies]
rclrs = {version="*",path ="../ros2_rust/rclrs/"}
std_msgs = {version="*", path ="../../install/std_msgs/share/std_msgs/rust"}
geometry_msgs={version="*",path="../../install/geometry_msgs/share/geometry_msgs/rust"}

However, you'll still need to find a way to source your setup bash script, because the rosidl_runtime_rs needs it. Not using colcon has the benefit, that you're for example able to use clippy.

Guelakais avatar Aug 13 '25 12:08 Guelakais