Cargo ros-new and cargo ros-add plugin

โš“ Rust    ๐Ÿ“… 2025-08-05    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 5      

surdeus

Warning

This post was published 31 days ago. The information described in this article may have changed.

Overview

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 new to create a standard Rust package, inheriting all its native features and directory structure.

  • Automated package.xml Generation: Simultaneously generates a ROS 2-compliant package.xml manifest, 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_cargo build type declaration (<build_type>ament_cargo</build_type>), making the package compatible with Colcon.

  • Full cargo new Argument Passthrough: Supports all standard cargo new options, 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 to package.xml while 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.xml file 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

Read full topic

๐Ÿท๏ธ Rust_feed