Skip to content

Commit 1ff04a1

Browse files
committed
Enable building docs with use_ros_shim feature!
1 parent 5530f1b commit 1ff04a1

3 files changed

Lines changed: 200 additions & 1 deletion

File tree

rclrs/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ tokio-stream = "0.1"
5656
# Needed by action clients to generate UUID values for their goals
5757
uuid = { version = "1", features = ["v4"] }
5858

59+
paste = { version = "1", optional = true}
60+
5961
[dev-dependencies]
6062
# Needed for e.g. writing yaml files in tests
6163
tempfile = "3.3.0"
@@ -79,7 +81,7 @@ dyn_msg = ["ament_rs", "libloading"]
7981
serde = ["dep:serde", "dep:serde-big-array", "rosidl_runtime_rs/serde"]
8082
# This feature is solely for the purpose of being able to generate documetation without a ROS installation
8183
# The only intended usage of this feature is for docs.rs builders to work, and is not intended to be used by end users
82-
use_ros_shim = ["rosidl_runtime_rs/use_ros_shim"]
84+
use_ros_shim = ["paste", "rosidl_runtime_rs/use_ros_shim"]
8385

8486
[package.metadata.docs.rs]
8587
features = ["use_ros_shim"]

rclrs/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,13 @@ include!(concat!(env!("OUT_DIR"), "/interfaces.rs"));
209209
#[cfg(feature = "dyn_msg")]
210210
pub mod dynamic_message;
211211

212+
#[cfg(feature="use_ros_shim")]
213+
#[allow(missing_docs)]
214+
pub mod vendor;
215+
216+
#[cfg(feature="use_ros_shim")]
217+
pub use vendor::*;
218+
212219
pub use action::*;
213220
pub use arguments::*;
214221
pub use client::*;

rclrs/src/vendor.rs

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
//! Stubs for ROS 2 interfaces to enable documentation builds without any ROS 2 installation sourced.
2+
//!
3+
//! This module provides no useful implementation and should only be used for building documentation.
4+
5+
macro_rules! impl_message_stub {
6+
($name:ident) => {
7+
#[derive(Clone, Default, Debug, PartialEq)]
8+
pub struct $name;
9+
10+
impl rosidl_runtime_rs::Message for $name {
11+
type RmwMsg = rmw::$name;
12+
fn into_rmw_message(
13+
_: std::borrow::Cow<'_, Self>,
14+
) -> std::borrow::Cow<'_, Self::RmwMsg> {
15+
todo!()
16+
}
17+
fn from_rmw_message(_: Self::RmwMsg) -> Self {
18+
todo!()
19+
}
20+
}
21+
};
22+
}
23+
24+
macro_rules! impl_rmw_message_stub {
25+
($name:ident) => {
26+
#[derive(Clone, Default, Debug, PartialEq)]
27+
pub struct $name;
28+
29+
impl rosidl_runtime_rs::Message for $name {
30+
type RmwMsg = Self;
31+
fn into_rmw_message(
32+
_: std::borrow::Cow<'_, Self>,
33+
) -> std::borrow::Cow<'_, Self::RmwMsg> {
34+
todo!()
35+
}
36+
fn from_rmw_message(_: Self::RmwMsg) -> Self {
37+
todo!()
38+
}
39+
}
40+
41+
impl rosidl_runtime_rs::RmwMessage for $name
42+
where
43+
Self: Sized,
44+
{
45+
const TYPE_NAME: &'static str = "";
46+
fn get_type_support() -> *const std::ffi::c_void {
47+
todo!()
48+
}
49+
}
50+
};
51+
}
52+
53+
macro_rules! impl_service_stub {
54+
($name:ident) => {
55+
pub struct $name;
56+
57+
impl rosidl_runtime_rs::Service for $name {
58+
paste::paste! {
59+
type Request = [<$name _Request>];
60+
type Response = [<$name _Response>];
61+
}
62+
63+
fn get_type_support() -> *const std::ffi::c_void {
64+
todo!()
65+
}
66+
}
67+
68+
paste::paste! {
69+
impl_rmw_message_stub!([<$name _Request>]);
70+
impl_rmw_message_stub!([<$name _Response>]);
71+
}
72+
};
73+
}
74+
75+
macro_rules! impl_sequence_alloc_stub {
76+
($name:ident) => {
77+
impl rosidl_runtime_rs::SequenceAlloc for $name {
78+
fn sequence_init(_: &mut rosidl_runtime_rs::Sequence<Self>, _: usize) -> bool {
79+
todo!()
80+
}
81+
fn sequence_fini(_: &mut rosidl_runtime_rs::Sequence<Self>) {
82+
todo!()
83+
}
84+
fn sequence_copy(
85+
_: &rosidl_runtime_rs::Sequence<Self>,
86+
_: &mut rosidl_runtime_rs::Sequence<Self>,
87+
) -> bool {
88+
todo!()
89+
}
90+
}
91+
};
92+
}
93+
94+
#[allow(non_camel_case_types)]
95+
/// Stub module for the [action_msgs](https://github.com/ros2/rcl_interfaces/tree/rolling/action_msgs) ROS 2 package.
96+
///
97+
/// Not all messages and services are implemented, only the ones used internally by [rclrs](crate).
98+
pub mod action_msgs {
99+
pub mod msg {
100+
impl_message_stub!(GoalInfo);
101+
102+
pub mod rmw {
103+
impl_rmw_message_stub!(GoalInfo);
104+
}
105+
}
106+
pub mod srv {
107+
impl_message_stub!(CancelGoal_Response);
108+
impl_message_stub!(CancelGoal_Request);
109+
110+
pub mod rmw {
111+
impl_rmw_message_stub!(CancelGoal_Response);
112+
impl_rmw_message_stub!(CancelGoal_Request);
113+
}
114+
}
115+
}
116+
117+
/// Stub module for the [builtin_interfaces](https://github.com/ros2/rcl_interfaces/tree/rolling/builtin_interfaces) ROS 2 package.
118+
///
119+
/// Not all messages are implemented, only the ones used internally by [rclrs](crate).
120+
pub mod builtin_interfaces {
121+
pub mod msg {
122+
impl_message_stub!(Time);
123+
124+
pub mod rmw {
125+
impl_rmw_message_stub!(Time);
126+
}
127+
}
128+
}
129+
130+
/// Stub module for the [unique_identifier_msgs](https://github.com/ros2/unique_identifier_msgs/tree/rolling) ROS 2 package.
131+
///
132+
/// Not all messages are implemented, only the ones used internally by [rclrs](crate).
133+
pub mod unique_identifier_msgs {
134+
pub mod msg {
135+
impl_message_stub!(UUID);
136+
137+
pub mod rmw {
138+
impl_rmw_message_stub!(UUID);
139+
}
140+
}
141+
}
142+
143+
/// Stub module for the [rosgraph_msgs](https://github.com/ros2/rcl_interfaces/tree/rolling/rosgraph_msgs) ROS 2 package.
144+
///
145+
/// Not all messages are implemented, only the ones used internally by [rclrs](crate).
146+
pub mod rosgraph_msgs {
147+
pub mod msg {
148+
impl_message_stub!(Clock);
149+
150+
pub mod rmw {
151+
impl_rmw_message_stub!(Clock);
152+
}
153+
}
154+
}
155+
156+
#[allow(non_camel_case_types)]
157+
/// Stub module for the [rcl_interfaces](https://github.com/ros2/rcl_interfaces/tree/rolling/rcl_interfaces) ROS 2 package.
158+
///
159+
/// Not all messages and services are implemented, only the ones used internally by [rclrs](crate).
160+
pub mod rcl_interfaces {
161+
pub mod msg {
162+
impl_message_stub!(ParameterType);
163+
impl_message_stub!(ParameterValue);
164+
165+
impl_message_stub!(FloatingPointRange);
166+
impl_message_stub!(IntegerRange);
167+
168+
pub mod rmw {
169+
impl_rmw_message_stub!(ParameterType);
170+
impl_rmw_message_stub!(ParameterValue);
171+
172+
impl_rmw_message_stub!(FloatingPointRange);
173+
impl_sequence_alloc_stub!(FloatingPointRange);
174+
175+
impl_rmw_message_stub!(IntegerRange);
176+
impl_sequence_alloc_stub!(IntegerRange);
177+
}
178+
}
179+
180+
pub mod srv {
181+
pub mod rmw {
182+
impl_service_stub!(DescribeParameters);
183+
impl_service_stub!(GetParameters);
184+
impl_service_stub!(GetParameterTypes);
185+
impl_service_stub!(ListParameters);
186+
impl_service_stub!(SetParameters);
187+
impl_service_stub!(SetParametersAtomically);
188+
}
189+
}
190+
}

0 commit comments

Comments
 (0)