Link against ROS crates for a new ROS node
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
You are missing a colcon tool. Please install all the requirements mentionned in the README.
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
I don't know which one is missing.
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 🙂
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.