-
Notifications
You must be signed in to change notification settings - Fork 190
Description
Description
Currently, ros2 pkg create
only supports ament_cmake
and ament_python
build types. There is no way to generate a new package skeleton for Rust. This forces developers using rclrs or similar crates to manually create a Cargo crate, add a package.xml
, and configure ament_cargo
.
This workflow is inconsistent with the developer experience in C++/Python and adds unnecessary friction for those exploring/have to use Rust in the ROS 2 ecosystem.
Motivation
To lower the entry barrier of Rust for ROS2 ecosystem, add an additional build type ament_cargo
to ros2 pkg create
, which would generate a minimal Rust crate structure alongside the usual ROS 2 metadata.
Design / Implementation Considerations
Proposed Generated Structure:
my_rust_pkg/
├── Cargo.toml
├── package.xml
└── src/
└── main.rs
Cargo.toml:
[package]
name = "my-rust-pkg"
version = "0.1.0"
edition = "2021"
[dependencies]
anyhow = "1.0"
rclrs = "0.5.1"
[workspace]
package.xml:
<package format="3">
<name>my_rust_pkg</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="[email protected]">user</maintainer>
<license></license>
<buildtool_depend>ament_cargo</buildtool_depend>
<depend>rclrs</depend>
<export>
<build_type>ament_cargo</build_type>
</export>
</package>
src/main.rs:
use anyhow::Result;
use rclrs::{Context, CreateBasicExecutor, RclrsErrorFilter, SpinOptions};
/// Creates a ROS 2 context and node, prints a hello message,
/// then spins until shutdown.
fn main() -> Result<()> {
let context: Context = Context::default_from_env()?;
let mut executor = context.create_basic_executor();
let _node = executor.create_node("hello_rust_node")?;
println!("Hello from rclrs 0.5.1!");
executor.spin(SpinOptions::default()).first_error()?;
Ok(())
}
Additional Information
This feature will
- Provide a consistent developer experience across C++, Python, and Rust.
- Lower the entry barrier for trying Rust in ROS 2.
- Encourage the adoption of Rust within the ecosystem by providing a first-class workflow.
The above proposal is off the top of my head. If I get a positive feedback on this,I would like to improve the idea and contribute a PR to add this functionality. Two questions:
- Is this within the intended scope of
ros2 pkg create
? - Would you prefer this support to live in the core tool, or in a separate plugin (Which I believe does exist)?
If accepted, I am willing to prepare and maintain the PR.