You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*Note: Once `rclrs` is published on crates.io, it's not technically needed anymore to clone the `ros2_rust` repo, and this section will be modified to reflect that.*
23
-
24
22
25
23
## Environment setup
26
24
@@ -151,47 +149,7 @@ The plugin to build `cargo` projects with `colcon` currently has the issue that
151
149
Rust packages for ROS 2 can also be built with pure `cargo`, and still integrate with ROS 2 tools like `ros2 run`.
152
150
153
151
154
-
### Learning by doing
155
-
156
-
*Note: The following needs to be adapted once we publish `rclrs` on crates.io.*
157
-
158
-
If you `cd` into e.g. `rclrs` before ever having built it with `colcon` and try to `cargo build` it, you'll see an error like
159
-
160
-
```
161
-
Updating crates.io index
162
-
error: no matching package named `rosidl_runtime_rs` found
163
-
location searched: registry `crates-io`
164
-
required by package `rclrs v0.2.0 (/workspace/ros2_rust/rclrs)`
165
-
```
166
-
167
-
Why is that? It's because `rclrs/Cargo.toml` contains `rosidl_runtime_rs = "*"` instead of `rosidl_runtime_rs = { path = "../rosidl_runtime_rs" }`, even though the package at that path is the one that is meant. If that's confusing, please read on. The reason is that it is a principle of ROS 2 and `colcon` for packages to reference their dependencies only by their _name_, and not by their path. This allows packages to be moved around freely in a workspace, or replaced by versions installed through `apt`, with no changes to the source code.
168
-
169
-
Unfortunately, referring to a package only by its name makes `cargo` assume that it should download that package from `crates.io`. `colcon-ros-cargo` works around this with a little hack: At build-time, it resolves these names to concrete paths to the local package, which are then written into `.cargo/config.toml`. The entries in that file override the original locations on `crates.io`, and therefore the _local_ packages will be used instead.
170
-
171
-
So, the problem above is fixed by doing one initial build of the package, or the whole workspace, with `colcon`. This creates the `.cargo/config.toml` file, and `cargo` will now use it to find `rosidl_runtime_rs`. Of course, if you don't want to install/use `colcon`forsome reason, you can also create that file yourself, or replace the name-only dependenciesin`rclrs/Cargo.toml` with paths.
172
-
173
-
Running `cargo build`in`rclrs` will now work, as well as `cargo doc`, `cargo test` and all the other `cargo` commands. Unfortunately, `cargo` may sometimes print messages saying
174
-
175
-
> warning: Patch `rclrs v0.1.0 (/workspace/install/rclrs/share/rclrs/rust)` was not used in the crate graph.
176
-
177
-
This can be ignored.
178
-
179
-
To summarize:
180
-
181
-
```shell
182
-
# Initial build of the package with colcon
183
-
# The --lookup-in-workspace flag is recommended for a cargo-based workflow
184
-
# Compare .cargo/config.toml with and without it to see its effect
# Run cargo build, or cargo check, cargo doc, etc.
188
-
cargo build
189
-
```
190
-
191
-
If you'd like to not have any of that "overriding dependencies through `.cargo/config.toml`", you can do that too of course. You just need to use concrete paths for any dependency that isn't published on `crates.io`, such as message packages. For instance, you might have to write `std_msgs = {path = '/workspace/install/std_msgs/share/std_msgs/rust'}`.
192
-
193
-
194
-
### Integration with ROS 2 tools
152
+
## Integration with ROS 2 tools
195
153
196
154
How can a binary created in Rust be made available to `ros2 run`, `ros2 launch` etc.? And how can other ROS 2 packages use a `cdylib` created in Rust? For that to work, the correct files must be placed at the correct location in the install directory, see [REP 122](https://www.ros.org/reps/rep-0122.html).
0 commit comments