Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vendorize rosgraph msgs #345

Merged
merged 4 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/message_demo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "examples_rclrs_message_demo"
version = "0.4.0"
version = "0.3.1"
authors = ["Nikolai Morin <[email protected]>"]
edition = "2021"

Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion examples/message_demo/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>examples_rclrs_message_demo</name>
<version>0.4.0</version>
<version>0.3.1</version>
<description>Package containing an example of message-related functionality in rclrs.</description>
<maintainer email="[email protected]">Nikolai Morin</maintainer>
<license>Apache License 2.0</license>
Expand Down
6 changes: 3 additions & 3 deletions examples/minimal_client_service/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "examples_rclrs_minimal_client_service"
version = "0.4.0"
version = "0.3.1"
authors = ["Esteve Fernandez <[email protected]>"]
edition = "2021"

Expand All @@ -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 = "*"
2 changes: 1 addition & 1 deletion examples/minimal_client_service/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>examples_rclrs_minimal_client_service</name>
<version>0.4.0</version>
<version>0.3.1</version>
<description>Package containing an example of the client-service mechanism in rclrs.</description>
<maintainer email="[email protected]">Esteve Fernandez</maintainer>
<license>Apache License 2.0</license>
Expand Down
6 changes: 3 additions & 3 deletions examples/minimal_pub_sub/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>", "Nikolai Morin <[email protected]>", "Jacob Hassold <[email protected]>"]
edition = "2021"
Expand Down Expand Up @@ -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 = "*"
Expand Down
2 changes: 1 addition & 1 deletion examples/minimal_pub_sub/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>examples_rclrs_minimal_pub_sub</name>
<version>0.4.0</version>
<version>0.3.1</version>
<description>Package containing an example of the publish-subscribe mechanism in rclrs.</description>
<maintainer email="[email protected]">Esteve Fernandez</maintainer>
<maintainer email="[email protected]">Nikolai Morin</maintainer>
Expand Down
6 changes: 2 additions & 4 deletions rclrs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>", "Nikolai Morin <[email protected]>", "Jacob Hassold <[email protected]>"]
edition = "2021"
Expand All @@ -20,10 +20,8 @@ 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.4"
rosidl_runtime_rs = "0.3"

[dev-dependencies]
# Needed for e.g. writing yaml files in tests
Expand Down
2 changes: 1 addition & 1 deletion rclrs/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>rclrs</name>
<version>0.4.0</version>
<version>0.3.1</version>
<description>Package containing the Rust client library.</description>
<maintainer email="[email protected]">Esteve Fernandez</maintainer>
<maintainer email="[email protected]">Nikolai Morin</maintainer>
Expand Down
2 changes: 1 addition & 1 deletion rclrs/src/time_source.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::clock::{Clock, ClockSource, ClockType};
use crate::vendor::rosgraph_msgs::msg::Clock as ClockMsg;
use crate::{MandatoryParameter, Node, QoSProfile, Subscription, QOS_PROFILE_CLOCK};
use rosgraph_msgs::msg::Clock as ClockMsg;
use std::sync::{Arc, Mutex, RwLock, Weak};

/// Time source for a node that drives the attached clock.
Expand Down
1 change: 1 addition & 0 deletions rclrs/src/vendor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@

pub mod builtin_interfaces;
pub mod rcl_interfaces;
pub mod rosgraph_msgs;
3 changes: 3 additions & 0 deletions rclrs/src/vendor/rosgraph_msgs/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#![allow(non_camel_case_types)]

pub mod msg;
131 changes: 131 additions & 0 deletions rclrs/src/vendor/rosgraph_msgs/msg.rs
Original file line number Diff line number Diff line change
@@ -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<Clock>,
size: usize,
) -> bool;
fn rosgraph_msgs__msg__Clock__Sequence__fini(seq: *mut rosidl_runtime_rs::Sequence<Clock>);
fn rosgraph_msgs__msg__Clock__Sequence__copy(
in_seq: &rosidl_runtime_rs::Sequence<Clock>,
out_seq: *mut rosidl_runtime_rs::Sequence<Clock>,
) -> 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<Self>, 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<Self>) {
// 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<Self>,
out_seq: &mut rosidl_runtime_rs::Sequence<Self>,
) -> 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 {
<Self as rosidl_runtime_rs::Message>::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),
}
}
}
12 changes: 8 additions & 4 deletions rclrs/vendor_interfaces.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,14 +13,15 @@
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()

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
Expand All @@ -34,18 +36,20 @@ def copy_adjusted(pkg, src, dst):

pub mod builtin_interfaces;
pub mod rcl_interfaces;
pub mod rosgraph_msgs;
""".format(Path(__file__).name)

def main():
args = get_args()
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)
Expand Down
2 changes: 1 addition & 1 deletion rclrs_example_msgs/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>rclrs_example_msgs</name>
<version>0.4.0</version>
<version>0.3.1</version>
<description>A package containing some example message definitions.</description>
<maintainer email="[email protected]">Nikolai Morin</maintainer>
<license>Apache License 2.0</license>
Expand Down
2 changes: 1 addition & 1 deletion rclrs_tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rclrs_tests"
version = "0.4.0"
version = "0.3.1"
authors = ["Chris Reid <[email protected]>"]
edition = "2021"

Expand Down
2 changes: 1 addition & 1 deletion rclrs_tests/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>rclrs_tests</name>
<version>0.4.0</version>
<version>0.3.1</version>
<description>Package containing tests for rclrs that make use of msgs and other dependencies</description>
<maintainer email="[email protected]">Chris Reid</maintainer>
<license>Apache License 2.0</license>
Expand Down
2 changes: 1 addition & 1 deletion rosidl_generator_rs/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>rosidl_generator_rs</name>
<version>0.4.0</version>
<version>0.3.1</version>
<description>Generate the ROS interfaces in Rust.</description>
<maintainer email="[email protected]">Esteve Fernandez</maintainer>
<license>Apache License 2.0</license>
Expand Down
2 changes: 1 addition & 1 deletion rosidl_generator_rs/resource/Cargo.toml.em
Original file line number Diff line number Diff line change
Expand Up @@ -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]@
Expand Down
2 changes: 1 addition & 1 deletion rosidl_runtime_rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>", "Nikolai Morin <[email protected]>", "Jacob Hassold <[email protected]>"]
edition = "2021"
Expand Down
2 changes: 1 addition & 1 deletion rosidl_runtime_rs/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>rosidl_runtime_rs</name>
<version>0.4.0</version>
<version>0.3.1</version>
<description>Message generation code shared by Rust projects in ROS 2</description>
<!-- This project is not military-sponsored, Jacob's employment contract just requires him to use this email address -->
<maintainer email="[email protected]">Jacob Hassold</maintainer>
Expand Down
Loading