diff --git a/examples/chatter/talker.rs b/examples/chatter/talker.rs index 7cdd80fd..3e26b676 100644 --- a/examples/chatter/talker.rs +++ b/examples/chatter/talker.rs @@ -2,6 +2,8 @@ use std::env; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; +use rclrs::{log_info, ToLogParams}; + fn main() -> Result<(), Box> { let shut_down = Arc::new(AtomicBool::new(false)); signal_hook::flag::register(signal_hook::consts::SIGINT, Arc::clone(&shut_down))?; @@ -19,7 +21,7 @@ fn main() -> Result<(), Box> { while !shut_down.load(Ordering::Relaxed) && context.ok() { message.data = format!("Hello, world! {}", publish_count); - rclrs::log_info!(node.logger_name(), "Publishing: {}", message.data); + log_info!(node.logger(), "Publishing: {}", message.data); publisher.publish(&message)?; publish_count += 1; std::thread::sleep(std::time::Duration::from_millis(500)); diff --git a/examples/zero_copy/listener.rs b/examples/zero_copy/listener.rs index ea4b283d..9f6470e7 100644 --- a/examples/zero_copy/listener.rs +++ b/examples/zero_copy/listener.rs @@ -3,6 +3,8 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use std::time::SystemTime; +use rclrs::{log_info, ToLogParams}; + fn main() -> Result<(), Box> { let shut_down = Arc::new(AtomicBool::new(false)); for signal in [signal_hook::consts::SIGINT, signal_hook::consts::SIGTERM] { @@ -24,7 +26,7 @@ fn main() -> Result<(), Box> { .as_micros() as u64; let delay_us = now - msg.timestamp; let data_length = msg.data_length as usize; - rclrs::log_info!(subscription_node.logger_name(), + log_info!(subscription_node.logger(), "Delay {} us, I heard: '{:?}'", delay_us, String::from_utf8(msg.data[..data_length].to_vec()).unwrap() diff --git a/examples/zero_copy/talker.rs b/examples/zero_copy/talker.rs index bb92d7fc..350984a4 100644 --- a/examples/zero_copy/talker.rs +++ b/examples/zero_copy/talker.rs @@ -3,6 +3,8 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use std::time::SystemTime; +use rclrs::{log_info, ToLogParams}; + fn main() -> Result<(), Box> { let shut_down = Arc::new(AtomicBool::new(false)); for signal in [signal_hook::consts::SIGINT, signal_hook::consts::SIGTERM] { @@ -37,7 +39,7 @@ fn main() -> Result<(), Box> { let msg_len = msg.len(); message.data_length = msg_len as u64; message.data[..msg_len].copy_from_slice(msg.as_bytes()); - rclrs::log_info!(node.logger_name(), "Publishing: {}", msg); + log_info!(node.logger(), "Publishing: {}", msg); message.publish()?; publish_count += 1; std::thread::sleep(std::time::Duration::from_millis(callback_period_ms as u64)); diff --git a/repositories/patches/ros2_rust_fix_rcl_bindings.patch b/repositories/patches/ros2_rust_fix_rcl_bindings.patch deleted file mode 100644 index 87378f7f..00000000 --- a/repositories/patches/ros2_rust_fix_rcl_bindings.patch +++ /dev/null @@ -1,147 +0,0 @@ -diff --git a/rclrs/src/rcl_bindings.rs b/rclrs/src/rcl_bindings.rs -index 94491bc..47cf9c4 100644 ---- a/rclrs/src/rcl_bindings.rs -+++ b/rclrs/src/rcl_bindings.rs -@@ -11,140 +11,7 @@ - #![allow(clippy::all)] - #![allow(missing_docs)] - --cfg_if::cfg_if! { -- if #[cfg(feature="generate_docs")] { -- #[repr(C)] -- #[derive(Debug)] -- pub struct rcl_allocator_t; - -- #[repr(C)] -- #[derive(Debug)] -- pub struct rcl_arguments_t; -+include!("rcl_bindings_generated.rs"); - -- #[repr(C)] -- #[derive(Debug)] -- pub struct rcl_client_t; -- -- #[repr(C)] -- #[derive(Debug)] -- pub struct rcl_clock_t; -- -- #[repr(C)] -- #[derive(Debug)] -- pub struct rcl_clock_type_t; -- -- #[repr(C)] -- #[derive(Debug)] -- pub struct rcl_context_t; -- -- #[repr(C)] -- #[derive(Debug)] -- pub struct rcl_guard_condition_t; -- -- #[repr(C)] -- #[derive(Debug)] -- pub struct rcl_names_and_types_t; -- -- #[repr(C)] -- #[derive(Debug)] -- pub struct rcl_node_options_t; -- -- #[repr(C)] -- #[derive(Debug)] -- pub struct rcl_node_params_t; -- -- #[repr(C)] -- #[derive(Debug)] -- pub struct rcl_node_t; -- -- #[repr(C)] -- #[derive(Debug)] -- pub struct rcl_params_t; -- -- #[repr(C)] -- #[derive(Debug)] -- pub struct rcl_publisher_t; -- -- #[repr(C)] -- #[derive(Debug)] -- pub struct rcl_ret_t; -- -- #[repr(C)] -- #[derive(Debug)] -- pub struct rcl_service_t; -- -- #[repr(C)] -- #[derive(Debug)] -- pub struct rcl_subscription_t; -- -- #[repr(C)] -- #[derive(Debug)] -- pub struct rcl_topic_endpoint_info_array_t; -- -- #[repr(C)] -- #[derive(Debug)] -- pub struct rcl_variant_t; -- -- #[repr(C)] -- #[derive(Debug)] -- pub struct rcl_wait_set_t; -- -- #[repr(C)] -- #[derive(Debug)] -- pub struct rcutils_string_array_t; -- -- #[repr(C)] -- #[derive(Debug)] -- pub struct rmw_message_info_t; -- -- #[repr(C)] -- #[derive(Debug)] -- pub struct rmw_names_and_types_t; -- -- #[repr(C)] -- #[derive(Debug)] -- pub struct rmw_qos_durability_policy_t; -- -- #[repr(C)] -- #[derive(Debug)] -- pub struct rmw_qos_history_policy_t; -- -- #[repr(C)] -- #[derive(Debug)] -- pub struct rmw_qos_liveliness_policy_t; -- -- #[repr(C)] -- #[derive(Debug)] -- pub struct rmw_qos_profile_t; -- -- #[repr(C)] -- #[derive(Debug)] -- pub struct rmw_qos_reliability_policy_t; -- -- #[repr(C)] -- #[derive(Debug)] -- pub struct rmw_request_id_t; -- -- #[repr(C)] -- #[derive(Debug)] -- pub struct rmw_time_t; -- -- #[repr(C)] -- #[derive(Debug)] -- pub struct rmw_topic_endpoint_info_array_t; -- -- #[repr(C)] -- #[derive(Debug)] -- pub struct rosidl_message_type_support_t; -- -- pub const RMW_GID_STORAGE_SIZE: usize = 24; -- -- extern "C" { -- pub fn rcl_context_is_valid(context: *const rcl_context_t) -> bool; -- } -- } else { -- include!(concat!(env!("OUT_DIR"), "/rcl_bindings_generated.rs")); -- -- pub const RMW_GID_STORAGE_SIZE: usize = rmw_gid_storage_size_constant; -- } --} -+pub const RMW_GID_STORAGE_SIZE: usize = rmw_gid_storage_size_constant; diff --git a/repositories/patches/ros2_rust_fix_rclrs.patch b/repositories/patches/ros2_rust_fix_rclrs.patch new file mode 100644 index 00000000..5571d9c7 --- /dev/null +++ b/repositories/patches/ros2_rust_fix_rclrs.patch @@ -0,0 +1,257 @@ +diff --git a/rclrs/src/lib.rs b/rclrs/src/lib.rs +index 3a22c6d..8c92865 100644 +--- a/rclrs/src/lib.rs ++++ b/rclrs/src/lib.rs +@@ -20,7 +20,6 @@ mod service; + mod subscription; + mod time; + mod time_source; +-mod vendor; + mod wait; + + #[cfg(test)] +diff --git a/rclrs/src/parameter.rs b/rclrs/src/parameter.rs +index 2a0829e..7f56772 100644 +--- a/rclrs/src/parameter.rs ++++ b/rclrs/src/parameter.rs +@@ -8,7 +8,7 @@ pub use range::*; + use service::*; + pub use value::*; + +-use crate::vendor::rcl_interfaces::msg::rmw::{ParameterType, ParameterValue as RmwParameterValue}; ++use rcl_interfaces::msg::rmw::{ParameterType, ParameterValue as RmwParameterValue}; + + use crate::{ + call_string_getter_with_rcl_node, rcl_bindings::*, Node, RclrsError, ENTITY_LIFECYCLE_MUTEX, +diff --git a/rclrs/src/parameter/range.rs b/rclrs/src/parameter/range.rs +index 6a46d2f..9c94231 100644 +--- a/rclrs/src/parameter/range.rs ++++ b/rclrs/src/parameter/range.rs +@@ -1,9 +1,10 @@ + use crate::{ +- vendor::rcl_interfaces::msg::rmw::{FloatingPointRange, IntegerRange}, + DeclarationError, ParameterValue, ParameterVariant, + }; + use rosidl_runtime_rs::{seq, BoundedSequence}; + ++use rcl_interfaces::msg::rmw::{FloatingPointRange, IntegerRange}; ++ + impl From> for ParameterRanges { + fn from(params: ParameterRange) -> Self { + Self { +diff --git a/rclrs/src/parameter/service.rs b/rclrs/src/parameter/service.rs +index 7c8ffe6..5143797 100644 +--- a/rclrs/src/parameter/service.rs ++++ b/rclrs/src/parameter/service.rs +@@ -3,7 +3,7 @@ use std::{ + sync::{Arc, Mutex}, + }; + +-use crate::vendor::rcl_interfaces::{msg::rmw::*, srv::rmw::*}; ++use rcl_interfaces::{msg::rmw::*, srv::rmw::*}; + use rosidl_runtime_rs::Sequence; + + use super::ParameterMap; +diff --git a/rclrs/src/parameter/value.rs b/rclrs/src/parameter/value.rs +index 82fe31e..24453fd 100644 +--- a/rclrs/src/parameter/value.rs ++++ b/rclrs/src/parameter/value.rs +@@ -3,10 +3,11 @@ use std::{ffi::CStr, sync::Arc}; + use crate::{ + parameter::{ParameterRange, ParameterRanges}, + rcl_bindings::*, +- vendor::rcl_interfaces::msg::rmw::{ParameterType, ParameterValue as RmwParameterValue}, + ParameterValueError, + }; + ++use rcl_interfaces::msg::rmw::{ParameterType, ParameterValue as RmwParameterValue}; ++ + /// A parameter value. + /// + /// Such a value can be specified in YAML format on the command line, or in a parameter file. +diff --git a/rclrs/src/rcl_bindings.rs b/rclrs/src/rcl_bindings.rs +index 90f4340..38c5d18 100644 +--- a/rclrs/src/rcl_bindings.rs ++++ b/rclrs/src/rcl_bindings.rs +@@ -11,143 +11,9 @@ + #![allow(clippy::all)] + #![allow(missing_docs)] + +-cfg_if::cfg_if! { +- if #[cfg(feature="generate_docs")] { +- #[repr(C)] +- #[derive(Debug)] +- pub struct rcl_allocator_t; ++include!("rcl_bindings_generated.rs"); + +- #[repr(C)] +- #[derive(Debug)] +- pub struct rcl_arguments_t; +- +- #[repr(C)] +- #[derive(Debug)] +- pub struct rcl_client_t; +- +- #[repr(C)] +- #[derive(Debug)] +- pub struct rcl_clock_t; +- +- #[repr(C)] +- #[derive(Debug)] +- pub struct rcl_clock_type_t; +- +- #[repr(C)] +- #[derive(Debug)] +- pub struct rcl_context_t; +- +- #[repr(C)] +- #[derive(Debug)] +- pub struct rcl_guard_condition_t; +- +- #[repr(C)] +- #[derive(Debug)] +- pub struct rcl_names_and_types_t; +- +- #[repr(C)] +- #[derive(Debug)] +- pub struct rcl_node_options_t; +- +- #[repr(C)] +- #[derive(Debug)] +- pub struct rcl_node_params_t; +- +- #[repr(C)] +- #[derive(Debug)] +- pub struct rcl_node_t; +- +- #[repr(C)] +- #[derive(Debug)] +- pub struct rcl_params_t; +- +- #[repr(C)] +- #[derive(Debug)] +- pub struct rcl_publisher_t; +- +- #[repr(C)] +- #[derive(Debug)] +- pub struct rcl_ret_t; +- +- #[repr(C)] +- #[derive(Debug)] +- pub struct rcl_service_t; +- +- #[repr(C)] +- #[derive(Debug)] +- pub struct rcl_subscription_t; +- +- #[repr(C)] +- #[derive(Debug)] +- pub struct rcl_topic_endpoint_info_array_t; +- +- #[repr(C)] +- #[derive(Debug)] +- pub struct rcl_variant_t; +- +- #[repr(C)] +- #[derive(Debug)] +- pub struct rcl_wait_set_t; +- +- #[repr(C)] +- #[derive(Debug)] +- pub struct rcutils_string_array_t; +- +- #[repr(C)] +- #[derive(Debug)] +- pub struct rmw_message_info_t; +- +- #[repr(C)] +- #[derive(Debug)] +- pub struct rmw_names_and_types_t; +- +- #[repr(C)] +- #[derive(Debug)] +- pub struct rmw_qos_durability_policy_t; +- +- #[repr(C)] +- #[derive(Debug)] +- pub struct rmw_qos_history_policy_t; +- +- #[repr(C)] +- #[derive(Debug)] +- pub struct rmw_qos_liveliness_policy_t; +- +- #[repr(C)] +- #[derive(Debug)] +- pub struct rmw_qos_profile_t; +- +- #[repr(C)] +- #[derive(Debug)] +- pub struct rmw_qos_reliability_policy_t; +- +- #[repr(C)] +- #[derive(Debug)] +- pub struct rmw_request_id_t; +- +- #[repr(C)] +- #[derive(Debug)] +- pub struct rmw_time_t; +- +- #[repr(C)] +- #[derive(Debug)] +- pub struct rmw_topic_endpoint_info_array_t; +- +- #[repr(C)] +- #[derive(Debug)] +- pub struct rosidl_message_type_support_t; +- +- pub const RMW_GID_STORAGE_SIZE: usize = 24; +- +- extern "C" { +- pub fn rcl_context_is_valid(context: *const rcl_context_t) -> bool; +- } +- } else { +- include!(concat!(env!("OUT_DIR"), "/rcl_bindings_generated.rs")); +- +- pub const RMW_GID_STORAGE_SIZE: usize = rmw_gid_storage_size_constant; +- } +-} ++pub const RMW_GID_STORAGE_SIZE: usize = rmw_gid_storage_size_constant; + + /// Wrapper around [`std::slice::from_raw_parts`] that accommodates the rcl + /// convention of providing a null pointer to represent empty arrays. This +diff --git a/rclrs/src/time.rs b/rclrs/src/time.rs +index 540c624..3d0c631 100644 +--- a/rclrs/src/time.rs ++++ b/rclrs/src/time.rs +@@ -1,4 +1,4 @@ +-use crate::{rcl_bindings::*, vendor::builtin_interfaces}; ++use crate::rcl_bindings::*; + use std::{ + num::TryFromIntError, + ops::{Add, Sub}, +@@ -6,6 +6,8 @@ use std::{ + time::Duration, + }; + ++use builtin_interfaces; ++ + /// Struct that represents time. + #[derive(Clone, Debug)] + pub struct Time { +diff --git a/rclrs/src/time_source.rs b/rclrs/src/time_source.rs +index 0be0c07..1fe6fee 100644 +--- a/rclrs/src/time_source.rs ++++ b/rclrs/src/time_source.rs +@@ -1,10 +1,11 @@ + use crate::{ + clock::{Clock, ClockSource, ClockType}, +- vendor::rosgraph_msgs::msg::Clock as ClockMsg, + Node, QoSProfile, ReadOnlyParameter, Subscription, QOS_PROFILE_CLOCK, + }; + use std::sync::{Arc, Mutex, RwLock, Weak}; + ++use rosgraph_msgs::msg::Clock as ClockMsg; ++ + /// Time source for a node that drives the attached clock. + /// If the node's `use_sim_time` parameter is set to `true`, the `TimeSource` will subscribe + /// to the `/clock` topic and drive the attached clock diff --git a/repositories/patches/ros2_rust_fix_rosidl_generator.patch b/repositories/patches/ros2_rust_fix_rosidl_generator.patch index a050b1ce..dd0319f8 100644 --- a/repositories/patches/ros2_rust_fix_rosidl_generator.patch +++ b/repositories/patches/ros2_rust_fix_rosidl_generator.patch @@ -1,5 +1,17 @@ +diff --git a/rosidl_generator_rs/resource/action.rs.em b/rosidl_generator_rs/resource/action.rs.em +index 5f463f3..56c3a03 100644 +--- a/rosidl_generator_rs/resource/action.rs.em ++++ b/rosidl_generator_rs/resource/action.rs.em +@@ -75,7 +75,6 @@ TEMPLATE( + type_name = action_spec.namespaced_type.name + }@ + +-#[link(name = "@(package_name)__rosidl_typesupport_c")] + extern "C" { + fn rosidl_typesupport_c__get_action_type_support_handle__@(package_name)__@(subfolder)__@(type_name)() -> *const std::ffi::c_void; + } diff --git a/rosidl_generator_rs/resource/msg_rmw.rs.em b/rosidl_generator_rs/resource/msg_rmw.rs.em -index c4420a6..d5d575c 100644 +index fbedd6d..3fb50c2 100644 --- a/rosidl_generator_rs/resource/msg_rmw.rs.em +++ b/rosidl_generator_rs/resource/msg_rmw.rs.em @@ -17,12 +17,10 @@ use serde::{Deserialize, Serialize}; @@ -8,50 +20,42 @@ index c4420a6..d5d575c 100644 -#[link(name = "@(package_name)__rosidl_typesupport_c")] extern "C" { - fn rosidl_typesupport_c__get_message_type_support_handle__@(package_name)__@(subfolder)__@(type_name)() -> *const std::os::raw::c_void; + fn rosidl_typesupport_c__get_message_type_support_handle__@(package_name)__@(subfolder)__@(type_name)() -> *const std::ffi::c_void; } -#[link(name = "@(package_name)__rosidl_generator_c")] extern "C" { fn @(package_name)__@(subfolder)__@(type_name)__init(msg: *mut @(type_name)) -> bool; fn @(package_name)__@(subfolder)__@(type_name)__Sequence__init(seq: *mut rosidl_runtime_rs::Sequence<@(type_name)>, size: usize) -> bool; -diff --git a/rosidl_generator_rs/resource/srv.rs.em b/rosidl_generator_rs/resource/srv.rs.em -index 369696f..503be91 100644 ---- a/rosidl_generator_rs/resource/srv.rs.em -+++ b/rosidl_generator_rs/resource/srv.rs.em +diff --git a/rosidl_generator_rs/resource/srv_idiomatic.rs.em b/rosidl_generator_rs/resource/srv_idiomatic.rs.em +index 660f1a6..0a7cce5 100644 +--- a/rosidl_generator_rs/resource/srv_idiomatic.rs.em ++++ b/rosidl_generator_rs/resource/srv_idiomatic.rs.em @@ -23,7 +23,6 @@ TEMPLATE( type_name = srv_spec.namespaced_type.name }@ -#[link(name = "@(package_name)__rosidl_typesupport_c")] extern "C" { - fn rosidl_typesupport_c__get_service_type_support_handle__@(package_name)__@(subfolder)__@(type_name)() -> *const std::os::raw::c_void; + fn rosidl_typesupport_c__get_service_type_support_handle__@(package_name)__@(subfolder)__@(type_name)() -> *const std::ffi::c_void; } -@@ -61,7 +60,6 @@ TEMPLATE( +diff --git a/rosidl_generator_rs/resource/srv_rmw.rs.em b/rosidl_generator_rs/resource/srv_rmw.rs.em +index 6ba55f1..b44e633 100644 +--- a/rosidl_generator_rs/resource/srv_rmw.rs.em ++++ b/rosidl_generator_rs/resource/srv_rmw.rs.em +@@ -23,7 +23,6 @@ TEMPLATE( type_name = srv_spec.namespaced_type.name }@ - #[link(name = "@(package_name)__rosidl_typesupport_c")] extern "C" { - fn rosidl_typesupport_c__get_service_type_support_handle__@(package_name)__@(subfolder)__@(type_name)() -> *const std::os::raw::c_void; + fn rosidl_typesupport_c__get_service_type_support_handle__@(package_name)__@(subfolder)__@(type_name)() -> *const std::ffi::c_void; } diff --git a/rosidl_generator_rs/rosidl_generator_rs/__init__.py b/rosidl_generator_rs/rosidl_generator_rs/__init__.py -index 502d1d3..33a9645 100644 +index b7850a6..a5661f0 100644 --- a/rosidl_generator_rs/rosidl_generator_rs/__init__.py +++ b/rosidl_generator_rs/rosidl_generator_rs/__init__.py -@@ -17,10 +17,7 @@ import pathlib - - from pathlib import Path - --if os.environ['ROS_DISTRO'] <= 'humble': -- import rosidl_cmake as rosidl_pycommon --else: -- import rosidl_pycommon -+import rosidl_cmake as rosidl_pycommon - - from rosidl_parser.definition import AbstractGenericString - from rosidl_parser.definition import Array -@@ -127,7 +124,7 @@ def generate_rs(generator_arguments_file, typesupport_impls): +@@ -143,7 +143,7 @@ def generate_rs(generator_arguments_file, typesupport_impls): generated_file = os.path.join(args['output_dir'], generated_filename % 'msg') rosidl_pycommon.expand_template( @@ -60,7 +64,7 @@ index 502d1d3..33a9645 100644 data.copy(), generated_file, minimum_timestamp=latest_target_timestamp) -@@ -138,7 +135,7 @@ def generate_rs(generator_arguments_file, typesupport_impls): +@@ -154,7 +154,7 @@ def generate_rs(generator_arguments_file, typesupport_impls): generated_file = os.path.join(args['output_dir'], generated_filename % 'srv') rosidl_pycommon.expand_template( @@ -69,7 +73,16 @@ index 502d1d3..33a9645 100644 data.copy(), generated_file, minimum_timestamp=latest_target_timestamp) -@@ -152,7 +149,7 @@ def generate_rs(generator_arguments_file, typesupport_impls): +@@ -165,7 +165,7 @@ def generate_rs(generator_arguments_file, typesupport_impls): + generated_file = os.path.join(args['output_dir'], + generated_filename % 'action') + rosidl_pycommon.expand_template( +- os.path.join(template_dir, template_file), ++ template_file, + data.copy(), + generated_file, + minimum_timestamp=latest_target_timestamp) +@@ -179,7 +179,7 @@ def generate_rs(generator_arguments_file, typesupport_impls): cargo_toml_data = { 'dependency_packages': dependency_packages, 'package_name': args['package_name'], diff --git a/repositories/patches/ros2_rust_fix_rosidl_runtime.patch b/repositories/patches/ros2_rust_fix_rosidl_runtime.patch new file mode 100644 index 00000000..fb62991b --- /dev/null +++ b/repositories/patches/ros2_rust_fix_rosidl_runtime.patch @@ -0,0 +1,24 @@ +diff --git a/rosidl_runtime_rs/src/sequence.rs b/rosidl_runtime_rs/src/sequence.rs +index 3d7cd58..1371bbc 100644 +--- a/rosidl_runtime_rs/src/sequence.rs ++++ b/rosidl_runtime_rs/src/sequence.rs +@@ -502,7 +502,6 @@ impl std::error::Error for SequenceExceedsBoundsError {} + + macro_rules! impl_sequence_alloc_for_primitive_type { + ($rust_type:ty, $init_func:ident, $fini_func:ident, $copy_func:ident) => { +- #[link(name = "rosidl_runtime_c")] + extern "C" { + fn $init_func(seq: *mut Sequence<$rust_type>, size: usize) -> bool; + fn $fini_func(seq: *mut Sequence<$rust_type>); +diff --git a/rosidl_runtime_rs/src/string.rs b/rosidl_runtime_rs/src/string.rs +index 9f0251c..599e794 100644 +--- a/rosidl_runtime_rs/src/string.rs ++++ b/rosidl_runtime_rs/src/string.rs +@@ -115,7 +115,6 @@ pub struct StringExceedsBoundsError { + // There is a lot of redundancy between String and WString, which this macro aims to reduce. + macro_rules! string_impl { + ($string:ty, $char_type:ty, $unsigned_char_type:ty, $string_conversion_func:ident, $init:ident, $fini:ident, $assignn:ident, $sequence_init:ident, $sequence_fini:ident, $sequence_copy:ident) => { +- #[link(name = "rosidl_runtime_c")] + extern "C" { + fn $init(s: *mut $string) -> bool; + fn $fini(s: *mut $string); diff --git a/repositories/patches/ros2_rust_logging.patch b/repositories/patches/ros2_rust_logging.patch deleted file mode 100644 index e57b2d02..00000000 --- a/repositories/patches/ros2_rust_logging.patch +++ /dev/null @@ -1,42 +0,0 @@ -diff --git a/rclrs/src/lib.rs b/rclrs/src/lib.rs -index 4924b36..3a22c6d 100644 ---- a/rclrs/src/lib.rs -+++ b/rclrs/src/lib.rs -@@ -11,6 +11,7 @@ mod clock; - mod context; - mod error; - mod executor; -+mod logging; - mod node; - mod parameter; - mod publisher; -@@ -38,6 +39,7 @@ pub use clock::*; - pub use context::*; - pub use error::*; - pub use executor::*; -+pub use logging::*; - pub use node::*; - pub use parameter::*; - pub use publisher::*; -diff --git a/rclrs/src/node.rs b/rclrs/src/node.rs -index 97684d6..defd1f3 100644 ---- a/rclrs/src/node.rs -+++ b/rclrs/src/node.rs -@@ -440,6 +440,17 @@ impl Node { - pub fn builder(context: &Context, node_name: &str) -> NodeBuilder { - NodeBuilder::new(context, node_name) - } -+ -+ /// Returns the logger name of the node. -+ pub fn logger_name(&self) -> &str { -+ let rcl_node = self.handle.rcl_node.lock().unwrap(); -+ let name_raw_ptr = unsafe { rcl_node_get_logger_name(&*rcl_node) }; -+ if name_raw_ptr.is_null() { -+ return ""; -+ } -+ let name_cstr = unsafe { CStr::from_ptr(name_raw_ptr) }; -+ name_cstr.to_str().unwrap_or("") -+ } - } - - // Helper used to implement call_string_getter(), but also used to get the FQN in the Node::new() diff --git a/repositories/patches/ros2_rust_no_msg_vendoring.patch b/repositories/patches/ros2_rust_no_msg_vendoring.patch deleted file mode 100644 index 4c7b68c6..00000000 --- a/repositories/patches/ros2_rust_no_msg_vendoring.patch +++ /dev/null @@ -1,100 +0,0 @@ -diff --git a/rclrs/src/lib.rs b/rclrs/src/lib.rs -index 4924b36..6e618c0 100644 ---- a/rclrs/src/lib.rs -+++ b/rclrs/src/lib.rs -@@ -19,7 +19,6 @@ mod service; - mod subscription; - mod time; - mod time_source; --mod vendor; - mod wait; - - #[cfg(test)] -diff --git a/rclrs/src/parameter.rs b/rclrs/src/parameter.rs -index c8a710e..43e9447 100644 ---- a/rclrs/src/parameter.rs -+++ b/rclrs/src/parameter.rs -@@ -8,7 +8,7 @@ pub use range::*; - use service::*; - pub use value::*; - --use crate::vendor::rcl_interfaces::msg::rmw::{ParameterType, ParameterValue as RmwParameterValue}; -+use rcl_interfaces::msg::rmw::{ParameterType, ParameterValue as RmwParameterValue}; - - use crate::{call_string_getter_with_rcl_node, rcl_bindings::*, Node, RclrsError}; - use std::{ -diff --git a/rclrs/src/parameter/range.rs b/rclrs/src/parameter/range.rs -index 96f66d6..fb7dede 100644 ---- a/rclrs/src/parameter/range.rs -+++ b/rclrs/src/parameter/range.rs -@@ -1,7 +1,7 @@ - use crate::{ -- vendor::rcl_interfaces::msg::rmw::{FloatingPointRange, IntegerRange}, - DeclarationError, ParameterValue, ParameterVariant, - }; -+use rcl_interfaces::msg::rmw::{FloatingPointRange, IntegerRange}; - use rosidl_runtime_rs::{seq, BoundedSequence}; - - impl From> for ParameterRanges { -diff --git a/rclrs/src/parameter/service.rs b/rclrs/src/parameter/service.rs -index 7c8ffe6..d1d95b0 100644 ---- a/rclrs/src/parameter/service.rs -+++ b/rclrs/src/parameter/service.rs -@@ -3,7 +3,7 @@ use std::{ - sync::{Arc, Mutex}, - }; - --use crate::vendor::rcl_interfaces::{msg::rmw::*, srv::rmw::*}; -+use rcl_interfaces::{msg::rmw::*, srv::rmw::*}; - use rosidl_runtime_rs::Sequence; - - use super::ParameterMap; -@@ -306,7 +306,7 @@ impl ParameterService { - #[cfg(test)] - mod tests { - use crate::{ -- vendor::rcl_interfaces::{ -+ rcl_interfaces::{ - msg::rmw::{ - Parameter as RmwParameter, ParameterType, ParameterValue as RmwParameterValue, - }, -diff --git a/rclrs/src/parameter/value.rs b/rclrs/src/parameter/value.rs -index 9d431c0..627c406 100644 ---- a/rclrs/src/parameter/value.rs -+++ b/rclrs/src/parameter/value.rs -@@ -3,9 +3,9 @@ use std::{ffi::CStr, sync::Arc}; - use crate::{ - parameter::{ParameterRange, ParameterRanges}, - rcl_bindings::*, -- vendor::rcl_interfaces::msg::rmw::{ParameterType, ParameterValue as RmwParameterValue}, - ParameterValueError, - }; -+use rcl_interfaces::msg::rmw::{ParameterType, ParameterValue as RmwParameterValue}; - - /// A parameter value. - /// -diff --git a/rclrs/src/time.rs b/rclrs/src/time.rs -index 540c624..4d64234 100644 ---- a/rclrs/src/time.rs -+++ b/rclrs/src/time.rs -@@ -1,4 +1,5 @@ --use crate::{rcl_bindings::*, vendor::builtin_interfaces}; -+use crate::rcl_bindings::*; -+use builtin_interfaces; - use std::{ - num::TryFromIntError, - ops::{Add, Sub}, -diff --git a/rclrs/src/time_source.rs b/rclrs/src/time_source.rs -index a6b6008..577643f 100644 ---- a/rclrs/src/time_source.rs -+++ b/rclrs/src/time_source.rs -@@ -1,8 +1,8 @@ - use crate::{ - clock::{Clock, ClockSource, ClockType}, -- vendor::rosgraph_msgs::msg::Clock as ClockMsg, - Node, QoSProfile, ReadOnlyParameter, 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. diff --git a/repositories/ros2_rust.BUILD.bazel b/repositories/ros2_rust.BUILD.bazel index e3be9fb6..8922be8b 100644 --- a/repositories/ros2_rust.BUILD.bazel +++ b/repositories/ros2_rust.BUILD.bazel @@ -71,7 +71,6 @@ rust_library( exclude = ["rclrs/src/vendor/*.rs"], ) + [ "rclrs/src/rcl_bindings_generated.rs", - ":logging_generator", ], edition = "2021", visibility = ["//visibility:public"], @@ -83,12 +82,6 @@ rust_library( ], ) -copy_file( - name = "logging_generator", - src = "@com_github_mvukov_rules_ros2//third_party/ros2_rust_logging:logging.rs", - out = "rclrs/src/logging.rs", -) - GENERATOR_APP_PY = "rosidl_generator_rs_app.py" copy_file( diff --git a/repositories/rust_setup_stage_1.bzl b/repositories/rust_setup_stage_1.bzl index 168468cd..4afa2613 100644 --- a/repositories/rust_setup_stage_1.bzl +++ b/repositories/rust_setup_stage_1.bzl @@ -20,14 +20,13 @@ def rust_setup_stage_1(): http_archive, name = "ros2_rust", build_file = "@com_github_mvukov_rules_ros2//repositories:ros2_rust.BUILD.bazel", - sha256 = "8311e72f517b4ad21a87a1aec0558467aa45b6d7173e03a332952a5105a4060f", - strip_prefix = "ros2_rust-ad9667f18151a5f35d02de8ad9889c5e26cefd04", - urls = ["https://github.com/ros2-rust/ros2_rust/archive/ad9667f18151a5f35d02de8ad9889c5e26cefd04.zip"], + sha256 = "9a57b561b1a68a7c70aed87584668249ccfa7caa23cc177378607daf8323d1a5", + strip_prefix = "ros2_rust-31e4563e2b5a19f62f4841138927a215978bf01c", + urls = ["https://github.com/ros2-rust/ros2_rust/archive/31e4563e2b5a19f62f4841138927a215978bf01c.zip"], patch_args = ["-p1"], patches = [ - "@com_github_mvukov_rules_ros2//repositories/patches:ros2_rust_fix_rcl_bindings.patch", + "@com_github_mvukov_rules_ros2//repositories/patches:ros2_rust_fix_rclrs.patch", "@com_github_mvukov_rules_ros2//repositories/patches:ros2_rust_fix_rosidl_generator.patch", - "@com_github_mvukov_rules_ros2//repositories/patches:ros2_rust_no_msg_vendoring.patch", - "@com_github_mvukov_rules_ros2//repositories/patches:ros2_rust_logging.patch", + "@com_github_mvukov_rules_ros2//repositories/patches:ros2_rust_fix_rosidl_runtime.patch", ], ) diff --git a/ros2/interfaces.bzl b/ros2/interfaces.bzl index ff0bd5f0..fada4f56 100644 --- a/ros2/interfaces.bzl +++ b/ros2/interfaces.bzl @@ -178,7 +178,8 @@ def run_generator( extra_generator_args = None, extra_generated_outputs = None, mnemonic = None, - progress_message = None): + progress_message = None, + generator_env = None): generator_templates = generator_templates[DefaultInfo].files.to_list() generator_arguments_file = ctx.actions.declare_file( @@ -224,6 +225,7 @@ def run_generator( ctx.actions.run( inputs = adapter.idl_files + generator_templates + [generator_arguments_file], outputs = generator_outputs, + env = generator_env, executable = generator, arguments = [generator_cmd_args], mnemonic = mnemonic, diff --git a/ros2/rust_interfaces.bzl b/ros2/rust_interfaces.bzl index 8e12b201..3c971b49 100644 --- a/ros2/rust_interfaces.bzl +++ b/ros2/rust_interfaces.bzl @@ -137,7 +137,7 @@ def _rust_generator_aspect_impl(target, ctx): lib_rs = "rust/src/lib.rs" extra_generated_outputs = [lib_rs] - for ext in ["msg", "srv"]: + for ext in ["action", "msg", "srv"]: if any([f.extension == ext for f in srcs]): extra_generated_outputs.append("rust/src/{}.rs".format(ext)) @@ -155,6 +155,7 @@ def _rust_generator_aspect_impl(target, ctx): extra_generated_outputs = extra_generated_outputs, mnemonic = "Ros2IdlGeneratorRust", progress_message = "Generating Rust IDL interfaces for %{label}", + generator_env = {"ROS_DISTRO": "humble"}, ) # Ideally dep_variant_info could be a depset, and all dep propagation should diff --git a/ros2/test/rust/publisher.rs b/ros2/test/rust/publisher.rs index f62fccdd..f05dfb18 100644 --- a/ros2/test/rust/publisher.rs +++ b/ros2/test/rust/publisher.rs @@ -2,6 +2,8 @@ use std::env; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; +use rclrs::{log_info, ToLogParams}; + fn main() -> Result<(), Box> { let shut_down = Arc::new(AtomicBool::new(false)); signal_hook::flag::register(signal_hook::consts::SIGINT, Arc::clone(&shut_down))?; @@ -17,7 +19,7 @@ fn main() -> Result<(), Box> { while !shut_down.load(Ordering::Relaxed) && context.ok() { let msg = format!("Hello, world! {}", publish_count); message.data = msg.clone(); - rclrs::log_info!(node.logger_name(), "{}", msg); + log_info!(node.logger(), "{}", msg); publisher.publish(&message)?; publish_count += 1; std::thread::sleep(std::time::Duration::from_millis(10)); diff --git a/third_party/ros2_rust_logging/BUILD.bazel b/third_party/ros2_rust_logging/BUILD.bazel deleted file mode 100644 index 63216db7..00000000 --- a/third_party/ros2_rust_logging/BUILD.bazel +++ /dev/null @@ -1,3 +0,0 @@ -exports_files([ - "logging.rs", -]) diff --git a/third_party/ros2_rust_logging/logging.rs b/third_party/ros2_rust_logging/logging.rs deleted file mode 100644 index 02dfcde3..00000000 --- a/third_party/ros2_rust_logging/logging.rs +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright (c) 2019 Sequence Planner -// SPDX-License-Identifier: Apache-2.0 AND MIT -// Adapted from https://github.com/sequenceplanner/r2r/blob/89cec03d07a1496a225751159cbc7bfb529d9dd1/r2r/src/utils.rs - -use std::{ - ffi::CString, - sync::{Mutex, Once}, -}; - -use crate::error; -use crate::rcl_bindings::*; - -static INIT: Once = Once::new(); -static LOG_GUARD: Mutex<()> = Mutex::new(()); - -/// Don't call this directly, use the logging macros instead. -#[doc(hidden)] -pub fn log(msg: &str, logger_name: &str, file: &str, line: u32, severity: LogSeverity) { - // currently not possible to get function name in rust. - // see https://github.com/rust-lang/rfcs/pull/2818 - let function = CString::new("").unwrap(); - let file = CString::new(file).unwrap(); - let location = rcutils_log_location_t { - function_name: function.as_ptr(), - file_name: file.as_ptr(), - line_number: line as usize, - }; - let format = CString::new("%s").unwrap(); - let logger_name = CString::new(logger_name).unwrap(); - let message = CString::new(msg).unwrap(); - let severity = severity.to_native(); - - INIT.call_once(|| { - let ret = unsafe { rcutils_logging_initialize() }; - if let Err(code) = error::to_rclrs_result(ret) { - panic!("Failed to initialize logging: {:?}", code); - } - }); - let _guard = LOG_GUARD.lock().unwrap(); - unsafe { - rcutils_log( - &location, - severity as i32, - logger_name.as_ptr(), - format.as_ptr(), - message.as_ptr(), - ); - } -} - -/// Logging severity -#[doc(hidden)] -pub enum LogSeverity { - Unset, - Debug, - Info, - Warn, - Error, - Fatal, -} - -impl LogSeverity { - fn to_native(&self) -> RCUTILS_LOG_SEVERITY { - use crate::rcl_bindings::rcl_log_severity_t::*; - match self { - LogSeverity::Unset => RCUTILS_LOG_SEVERITY_UNSET, - LogSeverity::Debug => RCUTILS_LOG_SEVERITY_DEBUG, - LogSeverity::Info => RCUTILS_LOG_SEVERITY_INFO, - LogSeverity::Warn => RCUTILS_LOG_SEVERITY_WARN, - LogSeverity::Error => RCUTILS_LOG_SEVERITY_ERROR, - LogSeverity::Fatal => RCUTILS_LOG_SEVERITY_FATAL, - } - } -} - -/// A helper macro to log the message. -#[macro_export] -macro_rules! __impl_log { - ($logger_name:expr, $msg:expr, $file:expr, $line:expr, $severity:expr) => {{ - $crate::log(&std::fmt::format($msg), $logger_name, $file, $line, $severity); - }}; -} - -/// Debug log message. -#[macro_export] -macro_rules! log_debug { - ($logger_name:expr, $($args:tt)*) => {{ - $crate::__impl_log!($logger_name, format_args!($($args)*), - file!(), line!(), $crate::LogSeverity::Debug) - }} -} - -/// Info log message. -#[macro_export] -macro_rules! log_info { - ($logger_name:expr, $($args:tt)*) => {{ - $crate::__impl_log!($logger_name, format_args!($($args)*), - file!(), line!(), $crate::LogSeverity::Info) - }} -} - -/// Warning log message. -#[macro_export] -macro_rules! log_warn { - ($logger_name:expr, $($args:tt)*) => {{ - $crate::__impl_log!($logger_name, format_args!($($args)*), - file!(), line!(), $crate::LogSeverity::Warn) - }} -} - -/// Error log message. -#[macro_export] -macro_rules! log_error { - ($logger_name:expr, $($args:tt)*) => {{ - $crate::__impl_log!($logger_name, format_args!($($args)*), - file!(), line!(), $crate::LogSeverity::Error) - }} -} - -/// Fatal log message. -#[macro_export] -macro_rules! log_fatal { - ($logger_name:expr, $($args:tt)*) => {{ - $crate::__impl_log!($logger_name, format_args!($($args)*), - file!(), line!(), $crate::LogSeverity::Fatal) - }} -}