colcon-cargo-ros2 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. colcon_cargo_ros2-0.2.0/PKG-INFO +300 -0
  2. colcon_cargo_ros2-0.2.0/README.md +264 -0
  3. colcon_cargo_ros2-0.2.0/cargo-ros2/Cargo.toml +31 -0
  4. colcon_cargo_ros2-0.2.0/cargo-ros2/src/ament_installer.rs +576 -0
  5. colcon_cargo_ros2-0.2.0/cargo-ros2/src/cache.rs +343 -0
  6. colcon_cargo_ros2-0.2.0/cargo-ros2/src/config_patcher.rs +259 -0
  7. colcon_cargo_ros2-0.2.0/cargo-ros2/src/dependency_parser.rs +249 -0
  8. colcon_cargo_ros2-0.2.0/cargo-ros2/src/lib.rs +289 -0
  9. colcon_cargo_ros2-0.2.0/cargo-ros2/src/main.rs +107 -0
  10. colcon_cargo_ros2-0.2.0/cargo-ros2/src/package_discovery.rs +314 -0
  11. colcon_cargo_ros2-0.2.0/cargo-ros2/src/workflow.rs +601 -0
  12. colcon_cargo_ros2-0.2.0/cargo-ros2/tests/fixtures/.gitignore +5 -0
  13. colcon_cargo_ros2-0.2.0/cargo-ros2/tests/fixtures/README.md +26 -0
  14. colcon_cargo_ros2-0.2.0/cargo-ros2/tests/integration_tests.rs +670 -0
  15. colcon_cargo_ros2-0.2.0/colcon-cargo-ros2/Cargo.lock +1309 -0
  16. colcon_cargo_ros2-0.2.0/colcon-cargo-ros2/Cargo.toml +17 -0
  17. colcon_cargo_ros2-0.2.0/colcon-cargo-ros2/README.md +264 -0
  18. colcon_cargo_ros2-0.2.0/colcon-cargo-ros2/colcon_cargo_ros2/__init__.py +1 -0
  19. colcon_cargo_ros2-0.2.0/colcon-cargo-ros2/colcon_cargo_ros2/package_augmentation/__init__.py +82 -0
  20. colcon_cargo_ros2-0.2.0/colcon-cargo-ros2/colcon_cargo_ros2/task/__init__.py +0 -0
  21. colcon_cargo_ros2-0.2.0/colcon-cargo-ros2/colcon_cargo_ros2/task/ament_cargo/__init__.py +0 -0
  22. colcon_cargo_ros2-0.2.0/colcon-cargo-ros2/colcon_cargo_ros2/task/ament_cargo/build.py +245 -0
  23. colcon_cargo_ros2-0.2.0/colcon-cargo-ros2/colcon_cargo_ros2/task/ament_cargo/test.py +52 -0
  24. colcon_cargo_ros2-0.2.0/colcon-cargo-ros2/colcon_cargo_ros2/workspace_bindgen.py +353 -0
  25. colcon_cargo_ros2-0.2.0/colcon-cargo-ros2/setup.cfg +79 -0
  26. colcon_cargo_ros2-0.2.0/colcon-cargo-ros2/setup.py +5 -0
  27. colcon_cargo_ros2-0.2.0/colcon-cargo-ros2/src/lib.rs +190 -0
  28. colcon_cargo_ros2-0.2.0/colcon-cargo-ros2/stdeb.cfg +6 -0
  29. colcon_cargo_ros2-0.2.0/colcon-cargo-ros2/test/test_build.py +127 -0
  30. colcon_cargo_ros2-0.2.0/colcon-cargo-ros2/test/test_flake8.py +72 -0
  31. colcon_cargo_ros2-0.2.0/colcon_cargo_ros2/__init__.py +1 -0
  32. colcon_cargo_ros2-0.2.0/colcon_cargo_ros2/package_augmentation/__init__.py +82 -0
  33. colcon_cargo_ros2-0.2.0/colcon_cargo_ros2/task/__init__.py +0 -0
  34. colcon_cargo_ros2-0.2.0/colcon_cargo_ros2/task/ament_cargo/__init__.py +0 -0
  35. colcon_cargo_ros2-0.2.0/colcon_cargo_ros2/task/ament_cargo/build.py +245 -0
  36. colcon_cargo_ros2-0.2.0/colcon_cargo_ros2/task/ament_cargo/test.py +52 -0
  37. colcon_cargo_ros2-0.2.0/colcon_cargo_ros2/workspace_bindgen.py +353 -0
  38. colcon_cargo_ros2-0.2.0/pyproject.toml +71 -0
  39. colcon_cargo_ros2-0.2.0/rosidl-bindgen/Cargo.toml +25 -0
  40. colcon_cargo_ros2-0.2.0/rosidl-bindgen/README.md +135 -0
  41. colcon_cargo_ros2-0.2.0/rosidl-bindgen/askama.toml +2 -0
  42. colcon_cargo_ros2-0.2.0/rosidl-bindgen/src/ament.rs +380 -0
  43. colcon_cargo_ros2-0.2.0/rosidl-bindgen/src/generator.rs +903 -0
  44. colcon_cargo_ros2-0.2.0/rosidl-bindgen/src/lib.rs +6 -0
  45. colcon_cargo_ros2-0.2.0/rosidl-bindgen/templates/action.rs.jinja +42 -0
  46. colcon_cargo_ros2-0.2.0/rosidl-bindgen/templates/lib.rs.jinja +18 -0
  47. colcon_cargo_ros2-0.2.0/rosidl-bindgen/templates/msg.rs.jinja +42 -0
  48. colcon_cargo_ros2-0.2.0/rosidl-bindgen/templates/srv.rs.jinja +33 -0
  49. colcon_cargo_ros2-0.2.0/rosidl-bindgen/tests/integration_tests.rs +204 -0
  50. colcon_cargo_ros2-0.2.0/rosidl-codegen/Cargo.toml +24 -0
  51. colcon_cargo_ros2-0.2.0/rosidl-codegen/PARSER_LIMITATIONS.md +128 -0
  52. colcon_cargo_ros2-0.2.0/rosidl-codegen/askama.toml +2 -0
  53. colcon_cargo_ros2-0.2.0/rosidl-codegen/benches/generation_benchmark.rs +126 -0
  54. colcon_cargo_ros2-0.2.0/rosidl-codegen/scripts/check_parser_failures.sh +89 -0
  55. colcon_cargo_ros2-0.2.0/rosidl-codegen/src/generator.rs +592 -0
  56. colcon_cargo_ros2-0.2.0/rosidl-codegen/src/idl_generator.rs +437 -0
  57. colcon_cargo_ros2-0.2.0/rosidl-codegen/src/lib.rs +48 -0
  58. colcon_cargo_ros2-0.2.0/rosidl-codegen/src/templates.rs +134 -0
  59. colcon_cargo_ros2-0.2.0/rosidl-codegen/src/types.rs +641 -0
  60. colcon_cargo_ros2-0.2.0/rosidl-codegen/src/utils.rs +140 -0
  61. colcon_cargo_ros2-0.2.0/rosidl-codegen/templates/action_idiomatic.rs.jinja +459 -0
  62. colcon_cargo_ros2-0.2.0/rosidl-codegen/templates/action_rmw.rs.jinja +750 -0
  63. colcon_cargo_ros2-0.2.0/rosidl-codegen/templates/build.rs.jinja +5 -0
  64. colcon_cargo_ros2-0.2.0/rosidl-codegen/templates/cargo.toml.jinja +21 -0
  65. colcon_cargo_ros2-0.2.0/rosidl-codegen/templates/lib.rs.jinja +128 -0
  66. colcon_cargo_ros2-0.2.0/rosidl-codegen/templates/message_idiomatic.rs.jinja +194 -0
  67. colcon_cargo_ros2-0.2.0/rosidl-codegen/templates/message_rmw.rs.jinja +98 -0
  68. colcon_cargo_ros2-0.2.0/rosidl-codegen/templates/service_idiomatic.rs.jinja +277 -0
  69. colcon_cargo_ros2-0.2.0/rosidl-codegen/templates/service_rmw.rs.jinja +188 -0
  70. colcon_cargo_ros2-0.2.0/rosidl-codegen/tests/comparison_test.rs +206 -0
  71. colcon_cargo_ros2-0.2.0/rosidl-codegen/tests/compilation_test.rs +425 -0
  72. colcon_cargo_ros2-0.2.0/rosidl-codegen/tests/edge_case_test.rs +318 -0
  73. colcon_cargo_ros2-0.2.0/rosidl-codegen/tests/fixtures/reference_outputs/geometry_msgs/Point/msg_idiomatic.rs +41 -0
  74. colcon_cargo_ros2-0.2.0/rosidl-codegen/tests/fixtures/reference_outputs/geometry_msgs/Point/msg_rmw.rs +21 -0
  75. colcon_cargo_ros2-0.2.0/rosidl-codegen/tests/fixtures/reference_outputs/std_msgs/Bool/msg_idiomatic.rs +29 -0
  76. colcon_cargo_ros2-0.2.0/rosidl-codegen/tests/fixtures/reference_outputs/std_msgs/Bool/msg_rmw.rs +17 -0
  77. colcon_cargo_ros2-0.2.0/rosidl-codegen/tests/fixtures/reference_outputs/std_msgs/String/msg_idiomatic.rs +33 -0
  78. colcon_cargo_ros2-0.2.0/rosidl-codegen/tests/fixtures/reference_outputs/std_msgs/String/msg_rmw.rs +17 -0
  79. colcon_cargo_ros2-0.2.0/rosidl-codegen/tests/integration_test.rs +392 -0
  80. colcon_cargo_ros2-0.2.0/rosidl-codegen/tests/parity_helpers.rs +192 -0
  81. colcon_cargo_ros2-0.2.0/rosidl-codegen/tests/parity_test.rs +337 -0
  82. colcon_cargo_ros2-0.2.0/rosidl-codegen/tests/test_template_fixes.rs +45 -0
  83. colcon_cargo_ros2-0.2.0/rosidl-parser/Cargo.toml +17 -0
  84. colcon_cargo_ros2-0.2.0/rosidl-parser/src/ast.rs +162 -0
  85. colcon_cargo_ros2-0.2.0/rosidl-parser/src/idl/ast.rs +351 -0
  86. colcon_cargo_ros2-0.2.0/rosidl-parser/src/idl/lexer.rs +692 -0
  87. colcon_cargo_ros2-0.2.0/rosidl-parser/src/idl/mod.rs +16 -0
  88. colcon_cargo_ros2-0.2.0/rosidl-parser/src/idl/parser.rs +838 -0
  89. colcon_cargo_ros2-0.2.0/rosidl-parser/src/idl/types.rs +184 -0
  90. colcon_cargo_ros2-0.2.0/rosidl-parser/src/lexer.rs +301 -0
  91. colcon_cargo_ros2-0.2.0/rosidl-parser/src/lib.rs +30 -0
  92. colcon_cargo_ros2-0.2.0/rosidl-parser/src/parser.rs +661 -0
@@ -0,0 +1,300 @@
1
+ Metadata-Version: 2.4
2
+ Name: colcon-cargo-ros2
3
+ Version: 0.2.0
4
+ Classifier: Development Status :: 3 - Alpha
5
+ Classifier: Environment :: Plugins
6
+ Classifier: Intended Audience :: Developers
7
+ Classifier: License :: OSI Approved :: Apache Software License
8
+ Classifier: Operating System :: MacOS
9
+ Classifier: Operating System :: Microsoft :: Windows
10
+ Classifier: Operating System :: POSIX
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.8
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Rust
18
+ Classifier: Topic :: Software Development :: Build Tools
19
+ Classifier: Topic :: Software Development :: Code Generators
20
+ Classifier: Topic :: Scientific/Engineering
21
+ Requires-Dist: colcon-core
22
+ Requires-Dist: colcon-library-path
23
+ Requires-Dist: colcon-ros
24
+ Summary: Extension for colcon to build Rust ROS 2 packages with automatic binding generation and ament installation
25
+ Keywords: ROS,ROS2,Rust,colcon,build-tool,robotics,message-generation,bindings
26
+ Author-email: Nikolai Morin <nnmmgit@gmail.com>
27
+ License: Apache-2.0
28
+ Requires-Python: >=3.8
29
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
30
+ Project-URL: Homepage, https://github.com/jerry73204/colcon-cargo-ros2
31
+ Project-URL: Repository, https://github.com/jerry73204/colcon-cargo-ros2
32
+ Project-URL: Documentation, https://github.com/jerry73204/colcon-cargo-ros2#readme
33
+ Project-URL: Issues, https://github.com/jerry73204/colcon-cargo-ros2/issues
34
+ Project-URL: Changelog, https://github.com/jerry73204/colcon-cargo-ros2/releases
35
+
36
+ # colcon-cargo-ros2
37
+
38
+ **Build Rust ROS 2 packages with automatic message binding generation.**
39
+
40
+ `colcon-cargo-ros2` is a colcon extension that enables seamless integration of Rust packages in ROS 2 workspaces. It automatically generates Rust bindings for ROS message types, manages dependencies, and installs packages in ament-compatible layout.
41
+
42
+ ## Features
43
+
44
+ - **Automatic Binding Generation**: Generates Rust bindings for messages, services, and actions on-demand
45
+ - **Smart Caching**: SHA256-based checksums for fast incremental builds
46
+ - **Workspace-Level Bindings**: Bindings generated once and shared across all packages
47
+ - **Zero Configuration**: Just add dependencies to `Cargo.toml` - bindings are handled automatically
48
+ - **Ament Compatible**: Installs to standard ament locations for seamless ROS 2 integration
49
+
50
+ ## Installation
51
+
52
+ ### From PyPI (Recommended)
53
+
54
+ ```bash
55
+ pip install colcon-cargo-ros2
56
+ ```
57
+
58
+ ### From Source
59
+
60
+ ```bash
61
+ git clone https://github.com/jerry73204/colcon-cargo-ros2.git
62
+ cd colcon-cargo-ros2
63
+ pip install packages/colcon-cargo-ros2/
64
+ ```
65
+
66
+ ## Quick Start
67
+
68
+ ### 1. Create a ROS 2 Workspace
69
+
70
+ ```bash
71
+ mkdir -p ~/ros2_ws/src
72
+ cd ~/ros2_ws
73
+ ```
74
+
75
+ ### 2. Create a Rust ROS 2 Package
76
+
77
+ ```bash
78
+ cd src
79
+ cargo new --bin my_robot_node
80
+ cd my_robot_node
81
+ ```
82
+
83
+ ### 3. Add ROS Dependencies
84
+
85
+ **Cargo.toml**:
86
+ ```toml
87
+ [package]
88
+ name = "my_robot_node"
89
+ version = "0.1.0"
90
+ edition = "2021"
91
+
92
+ [dependencies]
93
+ rclrs = "0.6"
94
+ std_msgs = "*"
95
+ geometry_msgs = "*"
96
+ ```
97
+
98
+ **package.xml**:
99
+ ```xml
100
+ <?xml version="1.0"?>
101
+ <?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
102
+ <package format="3">
103
+ <name>my_robot_node</name>
104
+ <version>0.1.0</version>
105
+ <description>Example Rust ROS 2 node</description>
106
+ <maintainer email="you@example.com">Your Name</maintainer>
107
+ <license>Apache-2.0</license>
108
+
109
+ <buildtool_depend>ament_cmake</buildtool_depend>
110
+
111
+ <depend>rclrs</depend>
112
+ <depend>std_msgs</depend>
113
+ <depend>geometry_msgs</depend>
114
+
115
+ <export>
116
+ <build_type>ament_cargo</build_type>
117
+ </export>
118
+ </package>
119
+ ```
120
+
121
+ **src/main.rs**:
122
+ ```rust
123
+ use rclrs::{Context, Node, RclrsError};
124
+ use std_msgs::msg::String as StringMsg;
125
+
126
+ fn main() -> Result<(), RclrsError> {
127
+ let context = Context::new(std::env::args())?;
128
+ let node = Node::new(&context, "my_robot_node")?;
129
+
130
+ let publisher = node.create_publisher::<StringMsg>("chatter", 10)?;
131
+
132
+ let mut count = 0;
133
+ loop {
134
+ let mut msg = StringMsg::default();
135
+ msg.data = format!("Hello from Rust! {}", count);
136
+ publisher.publish(msg)?;
137
+
138
+ println!("Published: {}", count);
139
+ count += 1;
140
+
141
+ std::thread::sleep(std::time::Duration::from_secs(1));
142
+ }
143
+ }
144
+ ```
145
+
146
+ ### 4. Build with colcon
147
+
148
+ ```bash
149
+ cd ~/ros2_ws
150
+ source /opt/ros/jazzy/setup.bash # Or your ROS 2 distro
151
+ colcon build --symlink-install
152
+ ```
153
+
154
+ The extension will:
155
+ 1. Discover ROS dependencies from `Cargo.toml` and `package.xml`
156
+ 2. Generate Rust bindings for `std_msgs` and `geometry_msgs`
157
+ 3. Build your Rust package with cargo
158
+ 4. Install binaries to `install/my_robot_node/lib/my_robot_node/`
159
+
160
+ ### 5. Run Your Node
161
+
162
+ ```bash
163
+ source install/setup.bash
164
+ ros2 run my_robot_node my_robot_node
165
+ ```
166
+
167
+ ## Package Structure
168
+
169
+ For `colcon-cargo-ros2` to recognize your package:
170
+ - **Both files required**: `package.xml` AND `Cargo.toml` in the package root
171
+ - **Build type**: `package.xml` must specify `<build_type>ament_cargo</build_type>` in the `<export>` section
172
+ - **Dependencies**: List ROS dependencies in both `Cargo.toml` and `package.xml`
173
+
174
+ Verify packages are detected:
175
+ ```bash
176
+ $ colcon list
177
+ my_robot_node src/my_robot_node (ament_cargo)
178
+ ```
179
+
180
+ ## Building
181
+
182
+ ### Basic Commands
183
+
184
+ ```bash
185
+ # Build all packages
186
+ colcon build
187
+
188
+ # Build specific package
189
+ colcon build --packages-select my_robot_node
190
+
191
+ # Build with release optimizations
192
+ colcon build --cargo-args --release
193
+
194
+ # Verbose output
195
+ colcon build --event-handlers console_direct+
196
+ ```
197
+
198
+ ### Using Custom Interfaces
199
+
200
+ Custom interface packages follow the standard ROS 2 procedure (CMake-based with `rosidl_generate_interfaces`). Simply add them as dependencies in your Rust package's `Cargo.toml`:
201
+
202
+ ```toml
203
+ [dependencies]
204
+ my_custom_interfaces = "*"
205
+ ```
206
+
207
+ Bindings will be generated automatically during the build.
208
+
209
+ ## How It Works
210
+
211
+ ### Workspace-Level Binding Generation
212
+
213
+ When building a colcon workspace, `colcon-cargo-ros2`:
214
+
215
+ 1. **Discovers Packages**: Finds all ROS dependencies via ament index
216
+ 2. **Generates Bindings**: Creates Rust bindings in `build/ros2_bindings/`
217
+ 3. **Configures Cargo**: Updates each package's `.cargo/config.toml` with patches
218
+ 4. **Builds**: Runs `cargo build` with workspace-level config
219
+ 5. **Installs**: Copies binaries and creates ament markers
220
+
221
+ **Workspace Structure**:
222
+ ```
223
+ ros2_ws/
224
+ ├── build/
225
+ │ └── ros2_bindings/ # Shared bindings (generated once)
226
+ │ ├── std_msgs/
227
+ │ ├── geometry_msgs/
228
+ │ └── my_interfaces/
229
+ ├── install/
230
+ │ ├── my_robot_node/
231
+ │ │ ├── lib/my_robot_node/ # Binaries
232
+ │ │ └── share/ # Metadata
233
+ │ └── my_interfaces/
234
+ └── src/
235
+ ├── my_robot_node/
236
+ │ ├── Cargo.toml
237
+ │ ├── package.xml
238
+ │ └── .cargo/config.toml # Auto-generated patches
239
+ └── my_interfaces/
240
+ ```
241
+
242
+ ### Benefits
243
+
244
+ - **No Duplication**: `std_msgs` generated once, not per-package
245
+ - **Fast Builds**: Intelligent caching skips regeneration when possible
246
+ - **Clean Workspace**: `colcon clean` removes all generated code
247
+ - **Standard Cargo**: Normal Cargo workflows work as expected
248
+
249
+ ## Troubleshooting
250
+
251
+ ### "Package not found in ament index"
252
+
253
+ Make sure the ROS 2 environment is sourced:
254
+ ```bash
255
+ source /opt/ros/jazzy/setup.bash
256
+ ```
257
+
258
+ ### "error: failed to select a version"
259
+
260
+ This usually means bindings weren't generated. Try:
261
+ ```bash
262
+ # Clean and rebuild
263
+ rm -rf build install
264
+ colcon build
265
+ ```
266
+
267
+ ### Build fails with linking errors
268
+
269
+ Ensure all dependencies are listed in both `Cargo.toml` and `package.xml`:
270
+ ```xml
271
+ <depend>std_msgs</depend>
272
+ <depend>geometry_msgs</depend>
273
+ ```
274
+
275
+ ## Requirements
276
+
277
+ - **Python**: 3.8 or later
278
+ - **ROS 2**: Humble, Iron, or Jazzy
279
+ - **Rust**: 1.70 or later (stable toolchain)
280
+ - **colcon**: Latest version
281
+
282
+ ## License
283
+
284
+ Apache-2.0 (compatible with ROS 2 ecosystem)
285
+
286
+ ## Contributing
287
+
288
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, architecture details, and guidelines.
289
+
290
+ ## Related Projects
291
+
292
+ - [ros2_rust](https://github.com/ros2-rust/ros2_rust) - Official Rust bindings for ROS 2
293
+ - [r2r](https://github.com/sequenceplanner/r2r) - Alternative Rust bindings
294
+ - [colcon](https://colcon.readthedocs.io) - Build tool for ROS 2
295
+
296
+ ## Support
297
+
298
+ - **Issues**: [GitHub Issues](https://github.com/jerry73204/colcon-cargo-ros2/issues)
299
+ - **Discussions**: [GitHub Discussions](https://github.com/jerry73204/colcon-cargo-ros2/discussions)
300
+
@@ -0,0 +1,264 @@
1
+ # colcon-cargo-ros2
2
+
3
+ **Build Rust ROS 2 packages with automatic message binding generation.**
4
+
5
+ `colcon-cargo-ros2` is a colcon extension that enables seamless integration of Rust packages in ROS 2 workspaces. It automatically generates Rust bindings for ROS message types, manages dependencies, and installs packages in ament-compatible layout.
6
+
7
+ ## Features
8
+
9
+ - **Automatic Binding Generation**: Generates Rust bindings for messages, services, and actions on-demand
10
+ - **Smart Caching**: SHA256-based checksums for fast incremental builds
11
+ - **Workspace-Level Bindings**: Bindings generated once and shared across all packages
12
+ - **Zero Configuration**: Just add dependencies to `Cargo.toml` - bindings are handled automatically
13
+ - **Ament Compatible**: Installs to standard ament locations for seamless ROS 2 integration
14
+
15
+ ## Installation
16
+
17
+ ### From PyPI (Recommended)
18
+
19
+ ```bash
20
+ pip install colcon-cargo-ros2
21
+ ```
22
+
23
+ ### From Source
24
+
25
+ ```bash
26
+ git clone https://github.com/jerry73204/colcon-cargo-ros2.git
27
+ cd colcon-cargo-ros2
28
+ pip install packages/colcon-cargo-ros2/
29
+ ```
30
+
31
+ ## Quick Start
32
+
33
+ ### 1. Create a ROS 2 Workspace
34
+
35
+ ```bash
36
+ mkdir -p ~/ros2_ws/src
37
+ cd ~/ros2_ws
38
+ ```
39
+
40
+ ### 2. Create a Rust ROS 2 Package
41
+
42
+ ```bash
43
+ cd src
44
+ cargo new --bin my_robot_node
45
+ cd my_robot_node
46
+ ```
47
+
48
+ ### 3. Add ROS Dependencies
49
+
50
+ **Cargo.toml**:
51
+ ```toml
52
+ [package]
53
+ name = "my_robot_node"
54
+ version = "0.1.0"
55
+ edition = "2021"
56
+
57
+ [dependencies]
58
+ rclrs = "0.6"
59
+ std_msgs = "*"
60
+ geometry_msgs = "*"
61
+ ```
62
+
63
+ **package.xml**:
64
+ ```xml
65
+ <?xml version="1.0"?>
66
+ <?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
67
+ <package format="3">
68
+ <name>my_robot_node</name>
69
+ <version>0.1.0</version>
70
+ <description>Example Rust ROS 2 node</description>
71
+ <maintainer email="you@example.com">Your Name</maintainer>
72
+ <license>Apache-2.0</license>
73
+
74
+ <buildtool_depend>ament_cmake</buildtool_depend>
75
+
76
+ <depend>rclrs</depend>
77
+ <depend>std_msgs</depend>
78
+ <depend>geometry_msgs</depend>
79
+
80
+ <export>
81
+ <build_type>ament_cargo</build_type>
82
+ </export>
83
+ </package>
84
+ ```
85
+
86
+ **src/main.rs**:
87
+ ```rust
88
+ use rclrs::{Context, Node, RclrsError};
89
+ use std_msgs::msg::String as StringMsg;
90
+
91
+ fn main() -> Result<(), RclrsError> {
92
+ let context = Context::new(std::env::args())?;
93
+ let node = Node::new(&context, "my_robot_node")?;
94
+
95
+ let publisher = node.create_publisher::<StringMsg>("chatter", 10)?;
96
+
97
+ let mut count = 0;
98
+ loop {
99
+ let mut msg = StringMsg::default();
100
+ msg.data = format!("Hello from Rust! {}", count);
101
+ publisher.publish(msg)?;
102
+
103
+ println!("Published: {}", count);
104
+ count += 1;
105
+
106
+ std::thread::sleep(std::time::Duration::from_secs(1));
107
+ }
108
+ }
109
+ ```
110
+
111
+ ### 4. Build with colcon
112
+
113
+ ```bash
114
+ cd ~/ros2_ws
115
+ source /opt/ros/jazzy/setup.bash # Or your ROS 2 distro
116
+ colcon build --symlink-install
117
+ ```
118
+
119
+ The extension will:
120
+ 1. Discover ROS dependencies from `Cargo.toml` and `package.xml`
121
+ 2. Generate Rust bindings for `std_msgs` and `geometry_msgs`
122
+ 3. Build your Rust package with cargo
123
+ 4. Install binaries to `install/my_robot_node/lib/my_robot_node/`
124
+
125
+ ### 5. Run Your Node
126
+
127
+ ```bash
128
+ source install/setup.bash
129
+ ros2 run my_robot_node my_robot_node
130
+ ```
131
+
132
+ ## Package Structure
133
+
134
+ For `colcon-cargo-ros2` to recognize your package:
135
+ - **Both files required**: `package.xml` AND `Cargo.toml` in the package root
136
+ - **Build type**: `package.xml` must specify `<build_type>ament_cargo</build_type>` in the `<export>` section
137
+ - **Dependencies**: List ROS dependencies in both `Cargo.toml` and `package.xml`
138
+
139
+ Verify packages are detected:
140
+ ```bash
141
+ $ colcon list
142
+ my_robot_node src/my_robot_node (ament_cargo)
143
+ ```
144
+
145
+ ## Building
146
+
147
+ ### Basic Commands
148
+
149
+ ```bash
150
+ # Build all packages
151
+ colcon build
152
+
153
+ # Build specific package
154
+ colcon build --packages-select my_robot_node
155
+
156
+ # Build with release optimizations
157
+ colcon build --cargo-args --release
158
+
159
+ # Verbose output
160
+ colcon build --event-handlers console_direct+
161
+ ```
162
+
163
+ ### Using Custom Interfaces
164
+
165
+ Custom interface packages follow the standard ROS 2 procedure (CMake-based with `rosidl_generate_interfaces`). Simply add them as dependencies in your Rust package's `Cargo.toml`:
166
+
167
+ ```toml
168
+ [dependencies]
169
+ my_custom_interfaces = "*"
170
+ ```
171
+
172
+ Bindings will be generated automatically during the build.
173
+
174
+ ## How It Works
175
+
176
+ ### Workspace-Level Binding Generation
177
+
178
+ When building a colcon workspace, `colcon-cargo-ros2`:
179
+
180
+ 1. **Discovers Packages**: Finds all ROS dependencies via ament index
181
+ 2. **Generates Bindings**: Creates Rust bindings in `build/ros2_bindings/`
182
+ 3. **Configures Cargo**: Updates each package's `.cargo/config.toml` with patches
183
+ 4. **Builds**: Runs `cargo build` with workspace-level config
184
+ 5. **Installs**: Copies binaries and creates ament markers
185
+
186
+ **Workspace Structure**:
187
+ ```
188
+ ros2_ws/
189
+ ├── build/
190
+ │ └── ros2_bindings/ # Shared bindings (generated once)
191
+ │ ├── std_msgs/
192
+ │ ├── geometry_msgs/
193
+ │ └── my_interfaces/
194
+ ├── install/
195
+ │ ├── my_robot_node/
196
+ │ │ ├── lib/my_robot_node/ # Binaries
197
+ │ │ └── share/ # Metadata
198
+ │ └── my_interfaces/
199
+ └── src/
200
+ ├── my_robot_node/
201
+ │ ├── Cargo.toml
202
+ │ ├── package.xml
203
+ │ └── .cargo/config.toml # Auto-generated patches
204
+ └── my_interfaces/
205
+ ```
206
+
207
+ ### Benefits
208
+
209
+ - **No Duplication**: `std_msgs` generated once, not per-package
210
+ - **Fast Builds**: Intelligent caching skips regeneration when possible
211
+ - **Clean Workspace**: `colcon clean` removes all generated code
212
+ - **Standard Cargo**: Normal Cargo workflows work as expected
213
+
214
+ ## Troubleshooting
215
+
216
+ ### "Package not found in ament index"
217
+
218
+ Make sure the ROS 2 environment is sourced:
219
+ ```bash
220
+ source /opt/ros/jazzy/setup.bash
221
+ ```
222
+
223
+ ### "error: failed to select a version"
224
+
225
+ This usually means bindings weren't generated. Try:
226
+ ```bash
227
+ # Clean and rebuild
228
+ rm -rf build install
229
+ colcon build
230
+ ```
231
+
232
+ ### Build fails with linking errors
233
+
234
+ Ensure all dependencies are listed in both `Cargo.toml` and `package.xml`:
235
+ ```xml
236
+ <depend>std_msgs</depend>
237
+ <depend>geometry_msgs</depend>
238
+ ```
239
+
240
+ ## Requirements
241
+
242
+ - **Python**: 3.8 or later
243
+ - **ROS 2**: Humble, Iron, or Jazzy
244
+ - **Rust**: 1.70 or later (stable toolchain)
245
+ - **colcon**: Latest version
246
+
247
+ ## License
248
+
249
+ Apache-2.0 (compatible with ROS 2 ecosystem)
250
+
251
+ ## Contributing
252
+
253
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, architecture details, and guidelines.
254
+
255
+ ## Related Projects
256
+
257
+ - [ros2_rust](https://github.com/ros2-rust/ros2_rust) - Official Rust bindings for ROS 2
258
+ - [r2r](https://github.com/sequenceplanner/r2r) - Alternative Rust bindings
259
+ - [colcon](https://colcon.readthedocs.io) - Build tool for ROS 2
260
+
261
+ ## Support
262
+
263
+ - **Issues**: [GitHub Issues](https://github.com/jerry73204/colcon-cargo-ros2/issues)
264
+ - **Discussions**: [GitHub Discussions](https://github.com/jerry73204/colcon-cargo-ros2/discussions)
@@ -0,0 +1,31 @@
1
+ [package]
2
+ name = "cargo-ros2"
3
+ version.workspace = true
4
+ authors.workspace = true
5
+ edition.workspace = true
6
+ license.workspace = true
7
+ repository.workspace = true
8
+ description = "All-in-one build tool for ROS 2 Rust projects"
9
+
10
+ [lib]
11
+ name = "cargo_ros2"
12
+ path = "src/lib.rs"
13
+
14
+ [[bin]]
15
+ name = "cargo-ros2"
16
+ path = "src/main.rs"
17
+
18
+ [dependencies]
19
+ clap = { version = "4.5", features = ["derive"] }
20
+ eyre = "0.6"
21
+ serde = { version = "1.0", features = ["derive"] }
22
+ serde_json = "1.0"
23
+ cargo_metadata = "0.18"
24
+ toml = "0.8"
25
+ sha2 = "0.10"
26
+ rosidl-bindgen = { path = "../rosidl-bindgen" }
27
+ rayon = "1.10"
28
+ indicatif = "0.17"
29
+
30
+ [dev-dependencies]
31
+ tempfile = "3.8"