Cargo ros-new and cargo ros-add plugin
โ Rust ๐ 2025-08-05 ๐ค surdeus ๐๏ธ 11Overview
To streamline ROS 2 development in Rust, I have developed two Cargo plugins that simplify package creation and dependency management: cargo-ros-new and cargo-ros-add. The primary goal of these tools is simplify the management of the dual-manifest system (Cargo.toml and package.xml), reducing boilerplate and ensuring consistency.
ros_new
This plugin extends the standard cargo new command to bootstrap a new Rust package that is also a valid ROS 2 package. It automates the initial setup process, creating all the necessary files with the correct configurations.
Features:
-
Standard Package Scaffolding: Leverages
cargo newto create a standard Rust package, inheriting all its native features and directory structure. -
Automated
package.xmlGeneration: Simultaneously generates a ROS 2-compliantpackage.xmlmanifest, automatically populating it with:-
Package name and version, synchronized from
Cargo.toml. -
Maintainer information (name and email).
-
License identifier, consistent with
Cargo.toml. -
Package description.
-
The required XML format specification (
<package format="3">). -
The
ament_cargobuild type declaration (<build_type>ament_cargo</build_type>), making the package compatible with Colcon.
-
-
Full
cargo newArgument Passthrough: Supports all standardcargo newoptions, allowing for complete control over the initial setup, including:-
--bin/--lib -
--edition <YEAR> -
--vcs <VCS> -
--name <NAME>
-
ros_add
This plugin enhances cargo add by synchronizing Rust dependencies with your ROS 2 package manifest. When you add a dependency, it ensures both configuration files are updated correctly.
Features:
-
Synchronized Dependency Management: Updates both the Rust manifest (
Cargo.toml) and the ROS 2 manifest (package.xml) with a single command, ensuring they never go out of sync. -
Intelligent XML Updates: Atomically adds the corresponding
<depend>tag topackage.xmlwhile preserving the original documentโs formatting, indentation, and comments. -
Idempotent Operations: The plugin is idempotent, meaning it will safely skip adding a dependency tag if it already exists in
package.xml, preventing duplicates. -
Robust Error Handling: Provides clear and actionable error messages for common failure scenarios, such as a missing
package.xmlfile or malformed configuration.
No matter which tool youโre using, you should enjoy using it. If people donโt enjoy using a tool, they tend to use it less. Hopefully, these two plugins will improve your experience of developing ROS 2 Rust packages.
1 post - 1 participant
๐ท๏ธ Rust_feed