Skip to content

Commit 0918476

Browse files
committed
Merge with latest main
Signed-off-by: Michael X. Grey <[email protected]>
2 parents e1ceb70 + f706824 commit 0918476

27 files changed

+1570
-162
lines changed

.github/workflows/rust-minimal.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ jobs:
4545
- name: Search packages in this repository
4646
id: list_packages
4747
run: |
48-
echo ::set-output name=package_list::$(colcon list --names-only)
48+
{
49+
echo 'package_list<<EOF'
50+
colcon list --names-only
51+
echo EOF
52+
} >> "$GITHUB_OUTPUT"
4953
5054
- name: Setup ROS environment
5155
uses: ros-tooling/[email protected]
@@ -72,10 +76,6 @@ jobs:
7276
cd -
7377
done
7478
75-
- name: Install cargo-ament-build
76-
run: |
77-
cargo install --debug cargo-ament-build
78-
7979
- name: Build and test
8080
id: build
8181
uses: ros-tooling/[email protected]
@@ -93,9 +93,9 @@ jobs:
9393
echo "Running clippy in $path"
9494
# Run clippy for all features except generate_docs (needed for docs.rs)
9595
if [ "$(basename $path)" = "rclrs" ]; then
96-
cargo clippy --all-targets -F default,dyn_msg -- -D warnings
96+
cargo clippy --no-deps --all-targets -F default,dyn_msg -- -D warnings
9797
else
98-
cargo clippy --all-targets --all-features -- -D warnings
98+
cargo clippy --no-deps --all-targets --all-features -- -D warnings
9999
fi
100100
cd -
101101
done

.github/workflows/rust-stable.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ jobs:
4545
- name: Search packages in this repository
4646
id: list_packages
4747
run: |
48-
echo ::set-output name=package_list::$(colcon list --names-only)
48+
{
49+
echo 'package_list<<EOF'
50+
colcon list --names-only
51+
echo EOF
52+
} >> "$GITHUB_OUTPUT"
4953
5054
- name: Setup ROS environment
5155
uses: ros-tooling/[email protected]
@@ -72,10 +76,6 @@ jobs:
7276
cd -
7377
done
7478
75-
- name: Install cargo-ament-build
76-
run: |
77-
cargo install --debug cargo-ament-build
78-
7979
- name: Build and test
8080
id: build
8181
uses: ros-tooling/[email protected]
@@ -93,9 +93,9 @@ jobs:
9393
echo "Running clippy in $path"
9494
# Run clippy for all features except generate_docs (needed for docs.rs)
9595
if [ "$(basename $path)" = "rclrs" ]; then
96-
cargo clippy --all-targets -F default,dyn_msg -- -D warnings
96+
cargo clippy --no-deps --all-targets -F default,dyn_msg -- -D warnings
9797
else
98-
cargo clippy --all-targets --all-features -- -D warnings
98+
cargo clippy --no-deps --all-targets --all-features -- -D warnings
9999
fi
100100
cd -
101101
done

Dockerfile

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ RUN apt-get update && apt-get install -y \
1111
python3-pip \
1212
&& rm -rf /var/lib/apt/lists/*
1313

14-
# Install Rust and the cargo-ament-build plugin
15-
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain 1.74.0 -y
14+
# Install Rust
15+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain 1.75.0 -y
1616
ENV PATH=/root/.cargo/bin:$PATH
17-
RUN cargo install cargo-ament-build
1817

1918
RUN pip install --upgrade pytest
2019

README.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
ROS 2 for Rust
22
==============
33

4-
| Target | Status |
5-
|----------|--------|
6-
| **Ubuntu 20.04** | [![Build Status](https://github.com/ros2-rust/ros2_rust/actions/workflows/rust.yml/badge.svg?branch=main)](https://github.com/ros2-rust/ros2_rust/actions/workflows/rust.yml?branch=main) |
4+
[![Minimal Version Status](https://github.com/ros2-rust/ros2_rust/actions/workflows/rust-minimal.yml/badge.svg?branch=main)](https://github.com/ros2-rust/ros2_rust/actions/workflows/rust-minimal.yml)
5+
[![Stable CI Status](https://github.com/ros2-rust/ros2_rust/actions/workflows/rust-stable.yml/badge.svg?branch=main)](https://github.com/ros2-rust/ros2_rust/actions/workflows/rust-stable.yml)
6+
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
77

88
Introduction
99
------------
@@ -37,7 +37,6 @@ Here are the steps for building the `ros2_rust` examples in a vanilla Ubuntu Foc
3737
# Assuming you installed the minimal version of ROS 2, you need these additional packages:
3838
sudo apt install -y git libclang-dev python3-pip python3-vcstool # libclang-dev is required by bindgen
3939
# Install these plugins for cargo and colcon:
40-
cargo install --debug cargo-ament-build # --debug is faster to install
4140
pip install git+https://github.com/colcon/colcon-cargo.git
4241
pip install git+https://github.com/colcon/colcon-ros-cargo.git
4342

docs/building.md

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ The exact steps may differ between platforms, but as an example, here is how you
4343
# Assuming you installed the minimal version of ROS 2, you need these additional packages:
4444
sudo apt install -y git libclang-dev python3-pip python3-vcstool # libclang-dev is required by bindgen
4545
# Install these plugins for cargo and colcon:
46-
cargo install cargo-ament-build
4746
pip install git+https://github.com/colcon/colcon-cargo.git
4847
pip install git+https://github.com/colcon/colcon-ros-cargo.git
4948
```

examples/minimal_pub_sub/src/minimal_two_nodes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use anyhow::{Error, Result};
77

88
struct MinimalSubscriber {
99
num_messages: AtomicU32,
10-
node: rclrs::Node,
10+
node: Arc<rclrs::Node>,
1111
subscription: Mutex<Option<Arc<rclrs::Subscription<std_msgs::msg::String>>>>,
1212
}
1313

rclrs/build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ fn main() {
3535
}
3636
};
3737

38+
println!("cargo:rustc-check-cfg=cfg(ros_distro, values(\"humble\", \"iron\", \"jazzy\", \"rolling\"))");
3839
println!("cargo:rustc-cfg=ros_distro=\"{ros_distro}\"");
3940

4041
let mut builder = bindgen::Builder::default()

rclrs/src/context.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
vec::Vec,
77
};
88

9-
use crate::{rcl_bindings::*, Executor, RclrsError, ToResult};
9+
use crate::{rcl_bindings::*, Executor, LoggingLifecycle, RclrsError, ToResult};
1010

1111
/// This is locked whenever initializing or dropping any middleware entity
1212
/// because we have found issues in RCL and some RMW implementations that
@@ -56,6 +56,10 @@ unsafe impl Send for rcl_context_t {}
5656
/// - middleware-specific data, e.g. the domain participant in DDS
5757
/// - the allocator used (left as the default by `rclrs`)
5858
///
59+
/// The context also configures the rcl_logging_* layer to allow publication to /rosout
60+
/// (as well as the terminal). TODO: This behaviour should be configurable using an
61+
/// "auto logging initialise" flag as per rclcpp and rclpy.
62+
///
5963
pub struct Context {
6064
pub(crate) handle: Arc<ContextHandle>,
6165
}
@@ -68,6 +72,10 @@ pub struct Context {
6872
/// bindings in this library.
6973
pub(crate) struct ContextHandle {
7074
pub(crate) rcl_context: Mutex<rcl_context_t>,
75+
/// This ensures that logging does not get cleaned up until after this ContextHandle
76+
/// has dropped.
77+
#[allow(unused)]
78+
logging: Arc<LoggingLifecycle>,
7179
}
7280

7381
impl Default for Context {
@@ -149,9 +157,16 @@ impl Context {
149157
// Move the check after the last fini()
150158
ret?;
151159
}
160+
161+
// TODO: "Auto set-up logging" is forced but should be configurable as per rclcpp and rclpy
162+
// SAFETY: We created this context a moment ago and verified that it is valid.
163+
// No other conditions are needed.
164+
let logging = unsafe { LoggingLifecycle::configure(&rcl_context)? };
165+
152166
Ok(Self {
153167
handle: Arc::new(ContextHandle {
154168
rcl_context: Mutex::new(rcl_context),
169+
logging,
155170
}),
156171
})
157172
}

rclrs/src/executor.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
use crate::{
22
rcl_bindings::rcl_context_is_valid, ContextHandle, IntoNodeOptions, Node, RclrsError, WaitSet,
3-
WeakNode,
43
};
54
use std::{
6-
sync::{Arc, Mutex},
5+
sync::{Arc, Mutex, Weak},
76
time::Duration,
87
};
98

109
/// Single-threaded executor implementation.
1110
pub struct Executor {
1211
context: Arc<ContextHandle>,
13-
nodes_mtx: Mutex<Vec<WeakNode>>,
12+
nodes_mtx: Mutex<Vec<Weak<Node>>>,
1413
}
1514

1615
impl Executor {
1716
/// Create a [`Node`] that will run on this Executor.
1817
pub fn create_node<'a>(
1918
&'a self,
2019
options: impl IntoNodeOptions<'a>,
21-
) -> Result<Node, RclrsError> {
20+
) -> Result<Arc<Node>, RclrsError> {
2221
let options = options.into_node_options();
2322
let node = options.build(&self.context)?;
24-
self.nodes_mtx.lock().unwrap().push(node.downgrade());
23+
self.nodes_mtx.lock().unwrap().push(Arc::downgrade(&node));
2524
Ok(node)
2625
}
2726

@@ -55,7 +54,7 @@ impl Executor {
5554
fn spin_once(&self, timeout: Option<Duration>) -> Result<(), RclrsError> {
5655
for node in { self.nodes_mtx.lock().unwrap() }
5756
.iter()
58-
.filter_map(WeakNode::upgrade)
57+
.filter_map(Weak::upgrade)
5958
.filter(|node| unsafe {
6059
rcl_context_is_valid(&*node.handle.context_handle.rcl_context.lock().unwrap())
6160
})

rclrs/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ mod clock;
1111
mod context;
1212
mod error;
1313
mod executor;
14+
mod logging;
1415
mod node;
1516
mod parameter;
1617
mod publisher;
@@ -36,6 +37,7 @@ pub use clock::*;
3637
pub use context::*;
3738
pub use error::*;
3839
pub use executor::*;
40+
pub use logging::*;
3941
pub use node::*;
4042
pub use parameter::*;
4143
pub use publisher::*;

0 commit comments

Comments
 (0)