From b17b7d4942b8de0782b1800f1930119934adcb09 Mon Sep 17 00:00:00 2001 From: Esteve Fernandez <33620+esteve@users.noreply.github.com> Date: Tue, 7 Nov 2023 16:51:38 +0100 Subject: [PATCH 1/4] Revert "Version 0.4.0 (#343)" This reverts commit e7065a7fb19d3d852bc9e978ac43cc4914750ca5. --- examples/message_demo/Cargo.toml | 8 ++++---- examples/message_demo/package.xml | 2 +- examples/minimal_client_service/Cargo.toml | 6 +++--- examples/minimal_client_service/package.xml | 2 +- examples/minimal_pub_sub/Cargo.toml | 6 +++--- examples/minimal_pub_sub/package.xml | 2 +- rclrs/Cargo.toml | 4 ++-- rclrs/package.xml | 2 +- rclrs_example_msgs/package.xml | 2 +- rclrs_tests/Cargo.toml | 2 +- rclrs_tests/package.xml | 2 +- rosidl_generator_rs/package.xml | 2 +- rosidl_generator_rs/resource/Cargo.toml.em | 2 +- rosidl_runtime_rs/Cargo.toml | 2 +- rosidl_runtime_rs/package.xml | 2 +- 15 files changed, 23 insertions(+), 23 deletions(-) diff --git a/examples/message_demo/Cargo.toml b/examples/message_demo/Cargo.toml index 94cd483e6..d3e5e210f 100644 --- a/examples/message_demo/Cargo.toml +++ b/examples/message_demo/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "examples_rclrs_message_demo" -version = "0.4.0" +version = "0.3.1" authors = ["Nikolai Morin "] edition = "2021" @@ -12,13 +12,13 @@ path = "src/message_demo.rs" anyhow = {version = "1", features = ["backtrace"]} [dependencies.rclrs] -version = "0.4" +version = "0.3" [dependencies.rosidl_runtime_rs] -version = "0.4" +version = "0.3" [dependencies.rclrs_example_msgs] -version = "0.4" +version = "0.3" features = ["serde"] [dependencies.serde_json] diff --git a/examples/message_demo/package.xml b/examples/message_demo/package.xml index 96eadd2fe..48cd14e4f 100644 --- a/examples/message_demo/package.xml +++ b/examples/message_demo/package.xml @@ -4,7 +4,7 @@ schematypens="http://www.w3.org/2001/XMLSchema"?> examples_rclrs_message_demo - 0.4.0 + 0.3.1 Package containing an example of message-related functionality in rclrs. Nikolai Morin Apache License 2.0 diff --git a/examples/minimal_client_service/Cargo.toml b/examples/minimal_client_service/Cargo.toml index e520c0d81..bd8b43144 100644 --- a/examples/minimal_client_service/Cargo.toml +++ b/examples/minimal_client_service/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "examples_rclrs_minimal_client_service" -version = "0.4.0" +version = "0.3.1" authors = ["Esteve Fernandez "] edition = "2021" @@ -21,10 +21,10 @@ anyhow = {version = "1", features = ["backtrace"]} tokio = { version = "1", features = ["macros", "rt", "rt-multi-thread", "time"] } [dependencies.rclrs] -version = "0.4" +version = "0.3" [dependencies.rosidl_runtime_rs] -version = "0.4" +version = "0.3" [dependencies.example_interfaces] version = "*" diff --git a/examples/minimal_client_service/package.xml b/examples/minimal_client_service/package.xml index 6ceab386c..2927b360e 100644 --- a/examples/minimal_client_service/package.xml +++ b/examples/minimal_client_service/package.xml @@ -4,7 +4,7 @@ schematypens="http://www.w3.org/2001/XMLSchema"?> examples_rclrs_minimal_client_service - 0.4.0 + 0.3.1 Package containing an example of the client-service mechanism in rclrs. Esteve Fernandez Apache License 2.0 diff --git a/examples/minimal_pub_sub/Cargo.toml b/examples/minimal_pub_sub/Cargo.toml index 43947fde3..0990d8555 100644 --- a/examples/minimal_pub_sub/Cargo.toml +++ b/examples/minimal_pub_sub/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "examples_rclrs_minimal_pub_sub" -version = "0.4.0" +version = "0.3.1" # This project is not military-sponsored, Jacob's employment contract just requires him to use this email address authors = ["Esteve Fernandez ", "Nikolai Morin ", "Jacob Hassold "] edition = "2021" @@ -29,10 +29,10 @@ path = "src/zero_copy_publisher.rs" anyhow = {version = "1", features = ["backtrace"]} [dependencies.rclrs] -version = "0.4" +version = "0.3" [dependencies.rosidl_runtime_rs] -version = "0.4" +version = "0.3" [dependencies.std_msgs] version = "*" diff --git a/examples/minimal_pub_sub/package.xml b/examples/minimal_pub_sub/package.xml index 2b84438ab..7ed97620f 100644 --- a/examples/minimal_pub_sub/package.xml +++ b/examples/minimal_pub_sub/package.xml @@ -4,7 +4,7 @@ schematypens="http://www.w3.org/2001/XMLSchema"?> examples_rclrs_minimal_pub_sub - 0.4.0 + 0.3.1 Package containing an example of the publish-subscribe mechanism in rclrs. Esteve Fernandez Nikolai Morin diff --git a/rclrs/Cargo.toml b/rclrs/Cargo.toml index d57a26cd5..a0ba674ae 100644 --- a/rclrs/Cargo.toml +++ b/rclrs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rclrs" -version = "0.4.0" +version = "0.3.1" # This project is not military-sponsored, Jacob's employment contract just requires him to use this email address authors = ["Esteve Fernandez ", "Nikolai Morin ", "Jacob Hassold "] edition = "2021" @@ -23,7 +23,7 @@ libloading = { version = "0.8", optional = true } # Needed for /clock topic subscription when using simulation time rosgraph_msgs = "*" # Needed for the Message trait, among others -rosidl_runtime_rs = "0.4" +rosidl_runtime_rs = "0.3" [dev-dependencies] # Needed for e.g. writing yaml files in tests diff --git a/rclrs/package.xml b/rclrs/package.xml index 86ff4b571..efe2541c7 100644 --- a/rclrs/package.xml +++ b/rclrs/package.xml @@ -4,7 +4,7 @@ schematypens="http://www.w3.org/2001/XMLSchema"?> rclrs - 0.4.0 + 0.3.1 Package containing the Rust client library. Esteve Fernandez Nikolai Morin diff --git a/rclrs_example_msgs/package.xml b/rclrs_example_msgs/package.xml index 5425a9c04..52ccbf6ef 100644 --- a/rclrs_example_msgs/package.xml +++ b/rclrs_example_msgs/package.xml @@ -2,7 +2,7 @@ rclrs_example_msgs - 0.4.0 + 0.3.1 A package containing some example message definitions. Nikolai Morin Apache License 2.0 diff --git a/rclrs_tests/Cargo.toml b/rclrs_tests/Cargo.toml index 3ba64af1e..51708f4e7 100644 --- a/rclrs_tests/Cargo.toml +++ b/rclrs_tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rclrs_tests" -version = "0.4.0" +version = "0.3.1" authors = ["Chris Reid "] edition = "2021" diff --git a/rclrs_tests/package.xml b/rclrs_tests/package.xml index d616c5dc7..82520d5d1 100644 --- a/rclrs_tests/package.xml +++ b/rclrs_tests/package.xml @@ -4,7 +4,7 @@ schematypens="http://www.w3.org/2001/XMLSchema"?> rclrs_tests - 0.4.0 + 0.3.1 Package containing tests for rclrs that make use of msgs and other dependencies Chris Reid Apache License 2.0 diff --git a/rosidl_generator_rs/package.xml b/rosidl_generator_rs/package.xml index 0cad2299a..18ff07f09 100644 --- a/rosidl_generator_rs/package.xml +++ b/rosidl_generator_rs/package.xml @@ -2,7 +2,7 @@ rosidl_generator_rs - 0.4.0 + 0.3.1 Generate the ROS interfaces in Rust. Esteve Fernandez Apache License 2.0 diff --git a/rosidl_generator_rs/resource/Cargo.toml.em b/rosidl_generator_rs/resource/Cargo.toml.em index 7c8f7fe30..fcf3461d7 100644 --- a/rosidl_generator_rs/resource/Cargo.toml.em +++ b/rosidl_generator_rs/resource/Cargo.toml.em @@ -4,7 +4,7 @@ version = "@(package_version)" edition = "2021" [dependencies] -rosidl_runtime_rs = "0.4" +rosidl_runtime_rs = "0.3" serde = { version = "1", optional = true, features = ["derive"] } serde-big-array = { version = "0.5.1", optional = true } @[for dep in dependency_packages]@ diff --git a/rosidl_runtime_rs/Cargo.toml b/rosidl_runtime_rs/Cargo.toml index 2a363be74..e15ef0ff3 100644 --- a/rosidl_runtime_rs/Cargo.toml +++ b/rosidl_runtime_rs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rosidl_runtime_rs" -version = "0.4.0" +version = "0.3.1" # This project is not military-sponsored, Jacob's employment contract just requires him to use this email address authors = ["Esteve Fernandez ", "Nikolai Morin ", "Jacob Hassold "] edition = "2021" diff --git a/rosidl_runtime_rs/package.xml b/rosidl_runtime_rs/package.xml index 5e97ba2c4..71bb5dbad 100644 --- a/rosidl_runtime_rs/package.xml +++ b/rosidl_runtime_rs/package.xml @@ -4,7 +4,7 @@ schematypens="http://www.w3.org/2001/XMLSchema"?> rosidl_runtime_rs - 0.4.0 + 0.3.1 Message generation code shared by Rust projects in ROS 2 Jacob Hassold From 6e9bf5d37581240904fb338342c98c2801dc94db Mon Sep 17 00:00:00 2001 From: Esteve Fernandez Date: Tue, 7 Nov 2023 17:04:17 +0100 Subject: [PATCH 2/4] Vendorize rosgraph_msgs Signed-off-by: Esteve Fernandez --- rclrs/Cargo.toml | 2 - rclrs/src/vendor/mod.rs | 1 + rclrs/src/vendor/rosgraph_msgs/mod.rs | 3 + rclrs/src/vendor/rosgraph_msgs/msg.rs | 131 ++++++++++++++++++++++++++ rclrs/vendor_interfaces.py | 12 ++- 5 files changed, 143 insertions(+), 6 deletions(-) create mode 100644 rclrs/src/vendor/rosgraph_msgs/mod.rs create mode 100644 rclrs/src/vendor/rosgraph_msgs/msg.rs diff --git a/rclrs/Cargo.toml b/rclrs/Cargo.toml index a0ba674ae..c7451db07 100644 --- a/rclrs/Cargo.toml +++ b/rclrs/Cargo.toml @@ -20,8 +20,6 @@ ament_rs = { version = "0.2", optional = true } futures = "0.3" # Needed for dynamic messages libloading = { version = "0.8", optional = true } -# Needed for /clock topic subscription when using simulation time -rosgraph_msgs = "*" # Needed for the Message trait, among others rosidl_runtime_rs = "0.3" diff --git a/rclrs/src/vendor/mod.rs b/rclrs/src/vendor/mod.rs index f1e33f75a..fe87087b1 100644 --- a/rclrs/src/vendor/mod.rs +++ b/rclrs/src/vendor/mod.rs @@ -4,3 +4,4 @@ pub mod builtin_interfaces; pub mod rcl_interfaces; +pub mod rosgraph_msgs; diff --git a/rclrs/src/vendor/rosgraph_msgs/mod.rs b/rclrs/src/vendor/rosgraph_msgs/mod.rs new file mode 100644 index 000000000..a6365b3b8 --- /dev/null +++ b/rclrs/src/vendor/rosgraph_msgs/mod.rs @@ -0,0 +1,3 @@ +#![allow(non_camel_case_types)] + +pub mod msg; diff --git a/rclrs/src/vendor/rosgraph_msgs/msg.rs b/rclrs/src/vendor/rosgraph_msgs/msg.rs new file mode 100644 index 000000000..1f4af8b70 --- /dev/null +++ b/rclrs/src/vendor/rosgraph_msgs/msg.rs @@ -0,0 +1,131 @@ +pub mod rmw { + #[cfg(feature = "serde")] + use serde::{Deserialize, Serialize}; + + #[link(name = "rosgraph_msgs__rosidl_typesupport_c")] + extern "C" { + fn rosidl_typesupport_c__get_message_type_support_handle__rosgraph_msgs__msg__Clock( + ) -> *const std::os::raw::c_void; + } + + #[link(name = "rosgraph_msgs__rosidl_generator_c")] + extern "C" { + fn rosgraph_msgs__msg__Clock__init(msg: *mut Clock) -> bool; + fn rosgraph_msgs__msg__Clock__Sequence__init( + seq: *mut rosidl_runtime_rs::Sequence, + size: usize, + ) -> bool; + fn rosgraph_msgs__msg__Clock__Sequence__fini(seq: *mut rosidl_runtime_rs::Sequence); + fn rosgraph_msgs__msg__Clock__Sequence__copy( + in_seq: &rosidl_runtime_rs::Sequence, + out_seq: *mut rosidl_runtime_rs::Sequence, + ) -> bool; + } + + // Corresponds to rosgraph_msgs__msg__Clock + #[repr(C)] + #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] + #[derive(Clone, Debug, PartialEq, PartialOrd)] + pub struct Clock { + pub clock: crate::vendor::builtin_interfaces::msg::rmw::Time, + } + + impl Default for Clock { + fn default() -> Self { + unsafe { + let mut msg = std::mem::zeroed(); + if !rosgraph_msgs__msg__Clock__init(&mut msg as *mut _) { + panic!("Call to rosgraph_msgs__msg__Clock__init() failed"); + } + msg + } + } + } + + impl rosidl_runtime_rs::SequenceAlloc for Clock { + fn sequence_init(seq: &mut rosidl_runtime_rs::Sequence, size: usize) -> bool { + // SAFETY: This is safe since the pointer is guaranteed to be valid/initialized. + unsafe { rosgraph_msgs__msg__Clock__Sequence__init(seq as *mut _, size) } + } + fn sequence_fini(seq: &mut rosidl_runtime_rs::Sequence) { + // SAFETY: This is safe since the pointer is guaranteed to be valid/initialized. + unsafe { rosgraph_msgs__msg__Clock__Sequence__fini(seq as *mut _) } + } + fn sequence_copy( + in_seq: &rosidl_runtime_rs::Sequence, + out_seq: &mut rosidl_runtime_rs::Sequence, + ) -> bool { + // SAFETY: This is safe since the pointer is guaranteed to be valid/initialized. + unsafe { rosgraph_msgs__msg__Clock__Sequence__copy(in_seq, out_seq as *mut _) } + } + } + + impl rosidl_runtime_rs::Message for Clock { + type RmwMsg = Self; + fn into_rmw_message( + msg_cow: std::borrow::Cow<'_, Self>, + ) -> std::borrow::Cow<'_, Self::RmwMsg> { + msg_cow + } + fn from_rmw_message(msg: Self::RmwMsg) -> Self { + msg + } + } + + impl rosidl_runtime_rs::RmwMessage for Clock + where + Self: Sized, + { + const TYPE_NAME: &'static str = "rosgraph_msgs/msg/Clock"; + fn get_type_support() -> *const std::os::raw::c_void { + // SAFETY: No preconditions for this function. + unsafe { + rosidl_typesupport_c__get_message_type_support_handle__rosgraph_msgs__msg__Clock() + } + } + } +} // mod rmw + +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + +#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] +#[derive(Clone, Debug, PartialEq, PartialOrd)] +pub struct Clock { + pub clock: crate::vendor::builtin_interfaces::msg::Time, +} + +impl Default for Clock { + fn default() -> Self { + ::from_rmw_message( + crate::vendor::rosgraph_msgs::msg::rmw::Clock::default(), + ) + } +} + +impl rosidl_runtime_rs::Message for Clock { + type RmwMsg = crate::vendor::rosgraph_msgs::msg::rmw::Clock; + + fn into_rmw_message(msg_cow: std::borrow::Cow<'_, Self>) -> std::borrow::Cow<'_, Self::RmwMsg> { + match msg_cow { + std::borrow::Cow::Owned(msg) => std::borrow::Cow::Owned(Self::RmwMsg { + clock: crate::vendor::builtin_interfaces::msg::Time::into_rmw_message( + std::borrow::Cow::Owned(msg.clock), + ) + .into_owned(), + }), + std::borrow::Cow::Borrowed(msg) => std::borrow::Cow::Owned(Self::RmwMsg { + clock: crate::vendor::builtin_interfaces::msg::Time::into_rmw_message( + std::borrow::Cow::Borrowed(&msg.clock), + ) + .into_owned(), + }), + } + } + + fn from_rmw_message(msg: Self::RmwMsg) -> Self { + Self { + clock: crate::vendor::builtin_interfaces::msg::Time::from_rmw_message(msg.clock), + } + } +} diff --git a/rclrs/vendor_interfaces.py b/rclrs/vendor_interfaces.py index 37d01e2f5..6a0066869 100644 --- a/rclrs/vendor_interfaces.py +++ b/rclrs/vendor_interfaces.py @@ -1,6 +1,7 @@ # This script produces the `vendor` module inside `rclrs` by copying -# the generated code for the `rcl_interfaces` package and its dependency -# `builtin_interfaces` and adjusting the submodule paths in the code. +# the generated code for the `rosgraph_msgs` and `rcl_interfaces` packages and +# its dependency `builtin_interfaces` and adjusting the submodule paths in the +# code. # If these packages, or the `rosidl_generator_rs`, get changed, you can # update the `vendor` module by running this script. # The purpose is to avoid an external dependency on `rcl_interfaces`, which @@ -12,7 +13,7 @@ import subprocess def get_args(): - parser = argparse.ArgumentParser(description='Vendor the rcl_interfaces and builtin_interfaces packages into rclrs') + parser = argparse.ArgumentParser(description='Vendor the rcl_interfaces, builtin_interfaces and rosgraph_msgs packages into rclrs') parser.add_argument('install_base', metavar='install_base', type=Path, help='the install base (must have non-merged layout)') return parser.parse_args() @@ -20,6 +21,7 @@ def get_args(): def adjust(pkg, text): text = text.replace('builtin_interfaces::', 'crate::vendor::builtin_interfaces::') text = text.replace('rcl_interfaces::', 'crate::vendor::rcl_interfaces::') + text = text.replace('rosgraph_msgs::', 'crate::vendor::rosgraph_msgs::') text = text.replace('crate::msg', f'crate::vendor::{pkg}::msg') text = text.replace('crate::srv', f'crate::vendor::{pkg}::srv') return text @@ -34,6 +36,7 @@ def copy_adjusted(pkg, src, dst): pub mod builtin_interfaces; pub mod rcl_interfaces; +pub mod rosgraph_msgs; """.format(Path(__file__).name) def main(): @@ -41,11 +44,12 @@ def main(): assert args.install_base.is_dir(), "Install base does not exist" assert (args.install_base / 'builtin_interfaces').is_dir(), "Install base does not contain builtin_interfaces" assert (args.install_base / 'rcl_interfaces').is_dir(), "Install base does not contain rcl_interfaces" + assert (args.install_base / 'rosgraph_msgs').is_dir(), "Install base does not contain rosgraph_msgs" rclrs_root = Path(__file__).parent vendor_dir = rclrs_root / 'src' / 'vendor' if vendor_dir.exists(): shutil.rmtree(vendor_dir) - for pkg in ['builtin_interfaces', 'rcl_interfaces']: + for pkg in ['builtin_interfaces', 'rcl_interfaces', 'rosgraph_msgs']: src = args.install_base / pkg / 'share' / pkg / 'rust' / 'src' dst = vendor_dir / pkg dst.mkdir(parents=True) From 8fda8d7b8e3488faac2b9e821065383e88cd7eea Mon Sep 17 00:00:00 2001 From: Esteve Fernandez Date: Tue, 7 Nov 2023 17:15:08 +0100 Subject: [PATCH 3/4] Fix module path --- rclrs/src/time_source.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rclrs/src/time_source.rs b/rclrs/src/time_source.rs index d2aac431f..908f19559 100644 --- a/rclrs/src/time_source.rs +++ b/rclrs/src/time_source.rs @@ -1,6 +1,6 @@ use crate::clock::{Clock, ClockSource, ClockType}; use crate::{MandatoryParameter, Node, QoSProfile, Subscription, QOS_PROFILE_CLOCK}; -use rosgraph_msgs::msg::Clock as ClockMsg; +use crate::vendor::rosgraph_msgs::msg::Clock as ClockMsg; use std::sync::{Arc, Mutex, RwLock, Weak}; /// Time source for a node that drives the attached clock. From d74d82e907b680e1da013a8ec59f0e9a022eeca4 Mon Sep 17 00:00:00 2001 From: Esteve Fernandez Date: Tue, 7 Nov 2023 17:19:49 +0100 Subject: [PATCH 4/4] Fix format --- rclrs/src/time_source.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rclrs/src/time_source.rs b/rclrs/src/time_source.rs index 908f19559..102cdbd08 100644 --- a/rclrs/src/time_source.rs +++ b/rclrs/src/time_source.rs @@ -1,6 +1,6 @@ use crate::clock::{Clock, ClockSource, ClockType}; -use crate::{MandatoryParameter, Node, QoSProfile, Subscription, QOS_PROFILE_CLOCK}; use crate::vendor::rosgraph_msgs::msg::Clock as ClockMsg; +use crate::{MandatoryParameter, Node, QoSProfile, Subscription, QOS_PROFILE_CLOCK}; use std::sync::{Arc, Mutex, RwLock, Weak}; /// Time source for a node that drives the attached clock.