Skip to content

Commit 6b57344

Browse files
authored
Add detailed guide for building ros2_rust packages (#129)
1 parent 0fc3f23 commit 6b57344

File tree

5 files changed

+317
-122
lines changed

5 files changed

+317
-122
lines changed

CONTRIBUTING.md

Lines changed: 0 additions & 49 deletions
This file was deleted.

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ ARG DEBIAN_FRONTEND=noninteractive
33

44
# Install dependencies
55
RUN apt-get update && apt-get install -y \
6-
clang \
76
curl \
87
git \
98
libclang-dev \

README.md

Lines changed: 26 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
ROS2 for Rust
2-
=============
3-
4-
Build status
5-
------------
1+
ROS 2 for Rust
2+
==============
63

74
| Target | Status |
85
|----------|--------|
@@ -11,94 +8,51 @@ Build status
118
Introduction
129
------------
1310

14-
This is a set of projects (bindings, code generator, examples and more) that enables developers to write ROS2
15-
applications in Rust.
11+
This is a set of projects (the `rclrs` client library, code generator, examples and more) that
12+
enables developers to write ROS 2 applications in Rust.
1613

17-
Features
18-
--------
14+
Features and limitations
15+
------------------------
1916

2017
The current set of features include:
21-
- Generation of all builtin ROS types
18+
- Message generation
2219
- Support for publishers and subscriptions
2320
- Tunable QoS settings
2421

25-
What's missing?
26-
---------------
27-
28-
Lots of things!
29-
- Component nodes
30-
- Clients and services
31-
- Tests
32-
- Documentation
22+
Lots of things are still missing however, see the [issue list](https://github.com/ros2-rust/ros2_rust/issues) for an overview. You are very welcome to [contribute](docs/CONTRIBUTING.md)!
3323

34-
### Limitations
35-
36-
- The `rclrs` interface is very limited for now and might not be idiomatic yet, any help and suggestion on the interface would be greatly appreciated
37-
- Due to the current ROS2 support of non-default clients, packages containing definitions of messages used in Rust crates must be present in the current workspace; otherwise message crates generation won't be triggered
24+
Since the client library is still rapidly evolving, there are no stability guarantees for the moment.
3825

3926
Sounds great, how can I try this out?
4027
-------------------------------------
4128

42-
Here, the Foxy distribution of ROS 2 is used, but newer distributions can be used by simply replacing 'foxy' with the distribution name.
29+
Here are the steps for building the `ros2_rust` examples in a vanilla Ubuntu Focal installation. See the [in-depth guide for building `ros2_rust` packages](docs/BUILDING.md) for more details and options, including a Docker-based setup.
4330

44-
```
45-
# First, make sure to have ROS 2 and vcstool installed (alternatively, install vcstool with pip):
46-
# sudo apt install ros-foxy-desktop ros-foxy-test-interface-files python3-vcstool libclang-dev clang
47-
# Install the colcon-cargo and colcon-ros-cargo plugins
48-
pip install git+https://github.com/colcon/colcon-cargo.git git+https://github.com/colcon/colcon-ros-cargo.git
49-
# Install the cargo-ament-build plugin
31+
<!--- These steps should be kept in sync with docs/Building.md --->
32+
```shell
33+
# Install Rust, e.g. as described in https://rustup.rs/
34+
# Install ROS 2 as described in https://docs.ros.org/en/foxy/Installation.html
35+
# Assuming you installed the minimal version of ROS 2, you need these additional packages:
36+
sudo apt install -y git libclang-dev python3-pip python3-vcstool # libclang-dev is required by bindgen
37+
# Install these plugins for cargo and colcon:
5038
cargo install cargo-ament-build
39+
pip install git+https://github.com/colcon/colcon-cargo.git
40+
pip install git+https://github.com/colcon/colcon-ros-cargo.git
5141

52-
# In your workspace directory (ideally an empty one), run
53-
mkdir src
42+
mkdir -p workspace/src && cd workspace
5443
git clone https://github.com/ros2-rust/ros2_rust.git src/ros2_rust
5544
vcs import src < src/ros2_rust/ros2_rust_foxy.repos
5645
. /opt/ros/foxy/setup.sh
57-
cd /src
58-
colcon build --packages-up-to examples_rclrs_minimal_pub_sub
59-
```
60-
61-
It's normal to see a `Some selected packages are already built in one or more underlay workspace` warning. This is because the standard message definitions that are part of ROS 2 need to be regenerated in order to create Rust bindings.
62-
63-
If something goes very wrong and you want to start fresh, make sure to delete all `install*`, `build*` and `.cargo` directories. Also, make sure your terminal does not have any install sourced (check with `echo $AMENT_PREFIX_PATH`, which should be empty).
64-
65-
66-
### Building with `cargo`
67-
As an alternative to `colcon`, Rust packages can be built with pure `cargo`.
68-
69-
However, this will not work out of the box, since the `Cargo.toml` files contain dependencies like `rclrs = "*"`, even though `rclrs` is not published on crates.io. This is intentional and follows ROS 2's principle for packages to reference their dependencies only with their name, and not with their path. At build-time, these dependencies are resolved to a path to the local package by `colcon`, and written into `.cargo/config.toml`. Therefore, the package in question should be built with `colcon` once, and after that `cargo` will be able to use the `.cargo/config.toml` file to find all dependencies.
70-
71-
A second catch is that `cargo` message packages link against native libraries. A convenient way to ensure that they are found is to also source the setup script produced by `colcon`.
72-
73-
As an example, here is how to build `rclcrs_examples` with `cargo`:
74-
46+
colcon build
7547
```
76-
# Initial build of the package with colcon
77-
# Compare .cargo/config.toml with and without the --lookup-in-workspace flag to see its effect
78-
colcon build --packages-up-to examples_rclrs_minimal_pub_sub --lookup-in-workspace
79-
# Source the install directory
80-
. install/setup.sh
81-
cd examples_rclrs_minimal_pub_sub
82-
# Run cargo build, or cargo check, cargo doc, etc.
83-
cargo build
84-
```
85-
86-
### Running the publisher and subscriber
8748

88-
Publisher:
49+
Then, to run the minimal pub-sub example, do this:
8950

90-
```
91-
# Do this in a new terminal
51+
```shell
52+
# In a new terminal (or tmux window)
9253
. ./install/setup.sh
93-
ros2 run examples_rclrs_minimal_pub_sub minimal_publisher
94-
```
95-
96-
Subscriber:
97-
98-
```
99-
# Do this in a new terminal
54+
ros2 run rclrs_examples minimal_publisher
55+
# In a new terminal (or tmux window)
10056
. ./install/setup.sh
10157
ros2 run examples_rclrs_minimal_pub_sub minimal_subscriber
10258
```
103-
104-
Enjoy!

0 commit comments

Comments
 (0)