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

Rosidl generator advancement #393

Closed
Closed
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
Empty file modified .dockerignore
100644 → 100755
Empty file.
Empty file modified .github/workflows/rust.yml
100644 → 100755
Empty file.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified .rustfmt.toml
100644 → 100755
Empty file.
Empty file modified Dockerfile
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified NOTICE
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified docs/CONTRIBUTING.md
100644 → 100755
Empty file.
Empty file modified docs/building.md
100644 → 100755
Empty file.
Empty file modified docs/writing-your-first-rclrs-node.md
100644 → 100755
Empty file.
Empty file modified examples/message_demo/Cargo.toml
100644 → 100755
Empty file.
Empty file modified examples/message_demo/package.xml
100644 → 100755
Empty file.
Empty file modified examples/message_demo/src/message_demo.rs
100644 → 100755
Empty file.
Empty file modified examples/minimal_client_service/Cargo.toml
100644 → 100755
Empty file.
Empty file modified examples/minimal_client_service/package.xml
100644 → 100755
Empty file.
Empty file modified examples/minimal_client_service/src/minimal_client.rs
100644 → 100755
Empty file.
Empty file modified examples/minimal_client_service/src/minimal_client_async.rs
100644 → 100755
Empty file.
Empty file modified examples/minimal_client_service/src/minimal_service.rs
100644 → 100755
Empty file.
Empty file modified examples/minimal_pub_sub/Cargo.toml
100644 → 100755
Empty file.
Empty file modified examples/minimal_pub_sub/launch/minimal_pub_sub.launch.xml
100644 → 100755
Empty file.
Empty file modified examples/minimal_pub_sub/package.xml
100644 → 100755
Empty file.
Empty file modified examples/minimal_pub_sub/src/minimal_publisher.rs
100644 → 100755
Empty file.
Empty file modified examples/minimal_pub_sub/src/minimal_subscriber.rs
100644 → 100755
Empty file.
Empty file modified examples/minimal_pub_sub/src/minimal_two_nodes.rs
100644 → 100755
Empty file.
Empty file modified examples/minimal_pub_sub/src/zero_copy_publisher.rs
100644 → 100755
Empty file.
Empty file modified examples/minimal_pub_sub/src/zero_copy_subscriber.rs
100644 → 100755
Empty file.
Empty file modified examples/rclrs_example_msgs/CMakeLists.txt
100644 → 100755
Empty file.
Empty file modified examples/rclrs_example_msgs/msg/MyMessage.idl
100644 → 100755
Empty file.
Empty file modified examples/rclrs_example_msgs/msg/NestedType.msg
100644 → 100755
Empty file.
Empty file modified examples/rclrs_example_msgs/msg/VariousTypes.msg
100644 → 100755
Empty file.
Empty file modified examples/rclrs_example_msgs/package.xml
100644 → 100755
Empty file.
Empty file modified rclrs/CHANGELOG.rst
100644 → 100755
Empty file.
Empty file modified rclrs/Cargo.toml
100644 → 100755
Empty file.
Empty file modified rclrs/README.md
100644 → 100755
Empty file.
Empty file modified rclrs/build.rs
100644 → 100755
Empty file.
Empty file modified rclrs/package.xml
100644 → 100755
Empty file.
Empty file modified rclrs/src/arguments.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/client.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/clock.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/context.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/dynamic_message.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/dynamic_message/error.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/error.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/executor.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/lib.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/node.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/node/builder.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/node/graph.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/parameter.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/parameter/override_map.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/parameter/service.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/parameter/value.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/publisher.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/publisher/loaned_message.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/qos.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/rcl_bindings.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/rcl_wrapper.h
100644 → 100755
Empty file.
Empty file modified rclrs/src/service.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/subscription.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/subscription/callback.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/subscription/message_info.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/subscription/readonly_loaned_message.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/test_helpers/graph_helpers.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/test_helpers/mod.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/time.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/time_source.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/vendor/builtin_interfaces/mod.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/vendor/builtin_interfaces/msg.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/vendor/mod.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/vendor/rcl_interfaces/mod.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/vendor/rcl_interfaces/msg.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/vendor/rcl_interfaces/srv.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/vendor/rosgraph_msgs/mod.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/vendor/rosgraph_msgs/msg.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/wait.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/wait/exclusivity_guard.rs
100644 → 100755
Empty file.
Empty file modified rclrs/src/wait/guard_condition.rs
100644 → 100755
Empty file.
Empty file modified rclrs/vendor_interfaces.py
100644 → 100755
Empty file.
Empty file modified ros2_rust_humble.repos
100644 → 100755
Empty file.
Empty file modified ros2_rust_iron.repos
100644 → 100755
Empty file.
Empty file modified ros2_rust_rolling.repos
100644 → 100755
Empty file.
Empty file modified rosidl_generator_rs/CMakeLists.txt
100644 → 100755
Empty file.
Empty file modified rosidl_generator_rs/cmake/custom_command.cmake
100644 → 100755
Empty file.
Empty file modified rosidl_generator_rs/cmake/register_rs.cmake
100644 → 100755
Empty file.
Empty file.
Empty file modified rosidl_generator_rs/package.xml
100644 → 100755
Empty file.
4 changes: 3 additions & 1 deletion rosidl_generator_rs/resource/Cargo.toml.em
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
name = "@(package_name)"
version = "@(package_version)"
edition = "2021"

description = "@(package_name) ros2 rust generated dependencies"
license = "@(license)"
authors= @(authors)
[dependencies]
rosidl_runtime_rs = "0.4"
serde = { version = "1", optional = true, features = ["derive"] }
Expand Down
Empty file modified rosidl_generator_rs/resource/build.rs.em
100644 → 100755
Empty file.
Empty file modified rosidl_generator_rs/resource/lib.rs.em
100644 → 100755
Empty file.
Empty file modified rosidl_generator_rs/resource/msg.rs.em
100644 → 100755
Empty file.
Empty file modified rosidl_generator_rs/resource/msg_idiomatic.rs.em
100644 → 100755
Empty file.
Empty file modified rosidl_generator_rs/resource/msg_rmw.rs.em
100644 → 100755
Empty file.
Empty file modified rosidl_generator_rs/resource/srv.rs.em
100644 → 100755
Empty file.
Empty file modified rosidl_generator_rs/rosidl_generator_rs-extras.cmake.in
100644 → 100755
Empty file.
104 changes: 46 additions & 58 deletions rosidl_generator_rs/rosidl_generator_rs/__init__.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,29 @@

import os
import pathlib

from pathlib import Path

if os.environ['ROS_DISTRO'] <= 'humble':
import rosidl_cmake as rosidl_pycommon
else:
import rosidl_cmake as rosidl_pycommon
else:
import rosidl_pycommon

from rosidl_parser.definition import AbstractGenericString
from rosidl_parser.definition import Array
from rosidl_parser.definition import BasicType
from rosidl_parser.definition import BoundedSequence
from rosidl_parser.definition import BoundedString
from rosidl_parser.definition import BoundedWString
from rosidl_parser.definition import IdlContent
from rosidl_parser.definition import IdlLocator
from rosidl_parser.definition import Message
from rosidl_parser.definition import NamespacedType
from rosidl_parser.definition import Service
from rosidl_parser.definition import UnboundedSequence
from rosidl_parser.definition import UnboundedString
from rosidl_parser.definition import UnboundedWString
from rosidl_parser.definition import (
AbstractGenericString,
Array,
BasicType,
BoundedSequence,
BoundedString,
BoundedWString,
IdlContent,
IdlLocator,
Message,
NamespacedType,
Service,
UnboundedSequence,
UnboundedString,
UnboundedWString,
)

from rosidl_parser.parser import parse_idl_file

Expand Down Expand Up @@ -88,11 +89,9 @@ def generate_rs(generator_arguments_file, typesupport_impls):

# Ensure the required templates exist
for template_file in mapping_msgs.keys():
assert os.path.exists(template_file), \
'Messages template file %s not found' % template_file
assert os.path.exists(template_file), f'Messages template file {template_file} not found'
for template_file in mapping_srvs.keys():
assert os.path.exists(template_file), \
'Services template file %s not found' % template_file
assert os.path.exists(template_file), f'Services template file {template_file} not found'

data = {
'pre_field_serde': pre_field_serde,
Expand All @@ -105,8 +104,8 @@ def generate_rs(generator_arguments_file, typesupport_impls):
rosidl_pycommon.convert_camel_case_to_lower_case_underscore,
'convert_lower_case_underscore_to_camel_case':
convert_lower_case_underscore_to_camel_case,
'msg_specs': [],
'srv_specs': [],
'msg_specs': [('msg', message) for message in idl_content.get_elements_of_type(Message)],
'srv_specs': [('srv', service) for service in idl_content.get_elements_of_type(Service)],
'package_name': args['package_name'],
'typesupport_impls': typesupport_impls,
'interface_path': idl_rel_path,
Expand All @@ -115,12 +114,6 @@ def generate_rs(generator_arguments_file, typesupport_impls):
latest_target_timestamp = rosidl_pycommon.get_newest_modification_time(
args['target_dependencies'])

for message in idl_content.get_elements_of_type(Message):
data['msg_specs'].append(('msg', message))

for service in idl_content.get_elements_of_type(Service):
data['srv_specs'].append(('srv', service))

if data['msg_specs']:
for template_file, generated_filenames in mapping_msgs.items():
for generated_filename in generated_filenames:
Expand Down Expand Up @@ -153,6 +146,9 @@ def generate_rs(generator_arguments_file, typesupport_impls):
'dependency_packages': dependency_packages,
'package_name': args['package_name'],
'package_version': args['package_version'],
'license':"Apache-2.0",
'authors':'["DefaultUser <[email protected]>"]'

}
rosidl_pycommon.expand_template(
os.path.join(template_dir, 'Cargo.toml.em'),
Expand Down Expand Up @@ -184,23 +180,19 @@ def get_rs_name(name):
return name if not name in keywords else name + '_'

def escape_string(s):
s = s.replace('\\', '\\\\')
s = s.replace("'", "\\'")
return s
return s.replace('\\', '\\\\').replace("'", "\\'")


def value_to_rs(type_, value):
assert type_.is_primitive_type()
assert value is not None

if not type_.is_array:
return primitive_value_to_rs(type_, value)
return primitive_value_to_rs(type_, value) if(
not type_.is_array
)else '{%s}' % ', '.join(
[primitive_value_to_rs(type_, single_value) for single_value in value]
)

rs_values = []
for single_value in value:
rs_value = primitive_value_to_rs(type_, single_value)
rs_values.append(rs_value)
return '{%s}' % ', '.join(rs_values)


def primitive_value_to_rs(type_, value):
Expand All @@ -227,13 +219,12 @@ def primitive_value_to_rs(type_, value):
return str(value)

if type_.type == 'float32':
return '%sf' % value
return f'{value}f'

if type_.type == 'string':
return '"%s"' % escape_string(value)

assert False, "unknown primitive type '%s'" % type_
return f'"{escape_string(value)}"'

assert False, f"unknown primitive type '{type_}'"

def constant_value_to_rs(type_, value):
assert value is not None
Expand All @@ -242,13 +233,13 @@ def constant_value_to_rs(type_, value):
if type_.typename == 'boolean':
return 'true' if value else 'false'
elif type_.typename == 'float32':
return '%sf' % value
return f'{value}f'
return str(value)

if isinstance(type_, AbstractGenericString):
return '"%s"' % escape_string(value)
return f'"{escape_string(value)}"'

assert False, "unknown constant type '%s'" % type_
assert False, f"unknown constant type '{type_}'"

# Type hierarchy:
#
Expand All @@ -272,10 +263,7 @@ def constant_value_to_rs(type_, value):


def pre_field_serde(type_):
if isinstance(type_, Array) and type_.size > 32:
return '#[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]\n '
else:
return ''
return '#[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]\n 'if isinstance(type_, Array) and type_.size > 32 else ''


def make_get_idiomatic_rs_type(package_name):
Expand All @@ -284,11 +272,11 @@ def get_idiomatic_rs_type(type_):
if isinstance(type_, UnboundedString) or isinstance(type_, UnboundedWString):
return 'std::string::String'
elif isinstance(type_, UnboundedSequence):
return 'Vec<{}>'.format(get_idiomatic_rs_type(type_.value_type))
return f'Vec<{get_idiomatic_rs_type(type_.value_type)}>'
elif isinstance(type_, NamespacedType):
return '::'.join(type_.namespaced_name()).replace(package_name, 'crate')
elif isinstance(type_, Array):
return '[{}; {}]'.format(get_idiomatic_rs_type(type_.value_type), type_.size)
return f'[{get_idiomatic_rs_type(type_.value_type)}; {type_.size}]'
else:
return get_rmw_rs_type(type_)
return get_idiomatic_rs_type
Expand Down Expand Up @@ -333,15 +321,15 @@ def get_rmw_rs_type(type_):
elif isinstance(type_, UnboundedWString):
return 'rosidl_runtime_rs::WString'
elif isinstance(type_, BoundedString):
return 'rosidl_runtime_rs::BoundedString<{}>'.format(type_.maximum_size)
return f'rosidl_runtime_rs::BoundedString<{type_.maximum_size}>'
elif isinstance(type_, BoundedWString):
return 'rosidl_runtime_rs::BoundedWString<{}>'.format(type_.maximum_size)
return f'rosidl_runtime_rs::BoundedWString<{type_.maximum_size}>'
elif isinstance(type_, Array):
return '[{}; {}]'.format(get_rmw_rs_type(type_.value_type), type_.size)
return f"[{get_rmw_rs_type(type_.value_type)}; {type_.size}]"
elif isinstance(type_, UnboundedSequence):
return 'rosidl_runtime_rs::Sequence<{}>'.format(get_rmw_rs_type(type_.value_type))
return f'rosidl_runtime_rs::Sequence<{get_rmw_rs_type(type_.value_type)}>'
elif isinstance(type_, BoundedSequence):
return 'rosidl_runtime_rs::BoundedSequence<{}, {}>'.format(get_rmw_rs_type(type_.value_type), type_.maximum_size)
return f'rosidl_runtime_rs::BoundedSequence<{get_rmw_rs_type(type_.value_type)}, {type_.maximum_size}>'

assert False, "unknown type '%s'" % type_.typename
assert False, f"unknown type '{type_.typename}'"
return get_rmw_rs_type
Empty file modified rosidl_runtime_rs/Cargo.toml
100644 → 100755
Empty file.
Empty file modified rosidl_runtime_rs/README.md
100644 → 100755
Empty file.
Empty file modified rosidl_runtime_rs/build.rs
100644 → 100755
Empty file.
Empty file modified rosidl_runtime_rs/package.xml
100644 → 100755
Empty file.
Empty file modified rosidl_runtime_rs/src/lib.rs
100644 → 100755
Empty file.
12 changes: 7 additions & 5 deletions rosidl_runtime_rs/src/sequence.rs
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::cmp::Ordering;
use std::fmt::{self, Debug, Display};
use std::hash::{Hash, Hasher};
use std::iter::{Extend, FromIterator, FusedIterator};
use std::ops::{Deref, DerefMut};
use std::{
cmp::Ordering,
fmt::{self, Debug, Display},
hash::{Hash, Hasher},
iter::{Extend, FromIterator, FusedIterator},
ops::{Deref, DerefMut},
};

#[cfg(feature = "serde")]
mod serde;
Expand Down
Empty file modified rosidl_runtime_rs/src/sequence/serde.rs
100644 → 100755
Empty file.
15 changes: 8 additions & 7 deletions rosidl_runtime_rs/src/string.rs
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use std::cmp::Ordering;
use std::ffi::CStr;
use std::fmt::{self, Debug, Display};
use std::hash::{Hash, Hasher};
use std::ops::{Deref, DerefMut};
use std::{
cmp::Ordering,
ffi::CStr,
fmt::{self, Debug, Display},
hash::{Hash, Hasher},
ops::{Deref, DerefMut},
};

#[cfg(feature = "serde")]
mod serde;

use crate::sequence::Sequence;
use crate::traits::SequenceAlloc;
use crate::{sequence::Sequence, traits::SequenceAlloc};

/// A zero-terminated string of 8-bit characters.
///
Expand Down
Empty file modified rosidl_runtime_rs/src/string/serde.rs
100644 → 100755
Empty file.
3 changes: 1 addition & 2 deletions rosidl_runtime_rs/src/traits.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
// DISTRIBUTION A. Approved for public release; distribution unlimited.
// OPSEC #4584.
//
use std::borrow::Cow;
use std::fmt::Debug;
use std::{borrow::Cow, fmt::Debug};

/// Internal trait that connects a particular `Sequence<T>` instance to generated C functions
/// that allocate and deallocate memory.
Expand Down
Loading