Skip to content

Commit

Permalink
Fix ros2_rust build
Browse files Browse the repository at this point in the history
  • Loading branch information
mvukov committed Dec 15, 2024
1 parent dbe021e commit 3d56ea3
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 459 deletions.
4 changes: 3 additions & 1 deletion examples/chatter/talker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::error::Error>> {
let shut_down = Arc::new(AtomicBool::new(false));
signal_hook::flag::register(signal_hook::consts::SIGINT, Arc::clone(&shut_down))?;
Expand All @@ -19,7 +21,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

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));
Expand Down
4 changes: 3 additions & 1 deletion examples/zero_copy/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::error::Error>> {
let shut_down = Arc::new(AtomicBool::new(false));
for signal in [signal_hook::consts::SIGINT, signal_hook::consts::SIGTERM] {
Expand All @@ -24,7 +26,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.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()
Expand Down
4 changes: 3 additions & 1 deletion examples/zero_copy/talker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::error::Error>> {
let shut_down = Arc::new(AtomicBool::new(false));
for signal in [signal_hook::consts::SIGINT, signal_hook::consts::SIGTERM] {
Expand Down Expand Up @@ -37,7 +39,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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));
Expand Down
147 changes: 0 additions & 147 deletions repositories/patches/ros2_rust_fix_rcl_bindings.patch

This file was deleted.

63 changes: 38 additions & 25 deletions repositories/patches/ros2_rust_fix_rosidl_generator.patch
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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'],
Expand Down
42 changes: 0 additions & 42 deletions repositories/patches/ros2_rust_logging.patch

This file was deleted.

Loading

0 comments on commit 3d56ea3

Please sign in to comment.