Skip to content

Commit 7505a5f

Browse files
committed
micro-ROS Jazzy patch
1 parent b43c945 commit 7505a5f

7 files changed

Lines changed: 262 additions & 83 deletions

File tree

.github/workflows/fork_checker.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: micro-ROS fork Update Checker
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
name:
6+
description: "Manual trigger"
7+
schedule:
8+
- cron: '0 4 * * *'
9+
10+
jobs:
11+
micro_ros_fork_update_check:
12+
runs-on: ubuntu-latest
13+
container: ubuntu:20.04
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
branches: [humble, iron, jazzy, rolling]
18+
steps:
19+
- name: Check
20+
id: check
21+
shell: bash
22+
run: |
23+
apt update; apt install -y git
24+
REPO=$(echo ${{ github.repository }} | awk '{split($0,a,"/"); print a[2]}')
25+
git clone -b ${{ matrix.branches }} https://github.com/micro-ros/$REPO
26+
cd $REPO
27+
git remote add ros2 https://github.com/ros2/$REPO
28+
git fetch ros2
29+
git fetch origin
30+
echo "::set-output name=merge_required::true"
31+
CMP=$(git rev-list --left-right --count ros2/${{ matrix.branches }}...origin/${{ matrix.branches }} | awk '{print $1}')
32+
if [ $CMP = "0" ]; then echo "::set-output name=merge_required::false"; fi
33+
34+
- name: Alert
35+
if: ${{ steps.check.outputs.merge_required == 'true' }}
36+
run: exit 1

rosidl_typesupport_c/CMakeLists.txt

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@ cmake_minimum_required(VERSION 3.5)
22

33
project(rosidl_typesupport_c)
44

5+
if(BUILD_SHARED_LIBS)
6+
set(${PROJECT_NAME}_LIBRARY_TYPE "SHARED")
7+
else()
8+
set(${PROJECT_NAME}_LIBRARY_TYPE "STATIC")
9+
endif()
10+
11+
if(rosidl_typesupport_c_LIBRARY_TYPE STREQUAL "STATIC"
12+
AND NOT BUILD_TESTING
13+
)
14+
set(ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT ON)
15+
else()
16+
set(ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT OFF)
17+
endif()
18+
519
# Default to C11
620
if(NOT CMAKE_C_STANDARD)
721
set(CMAKE_C_STANDARD 11)
@@ -17,14 +31,18 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
1731
endif()
1832

1933
find_package(ament_cmake_ros REQUIRED)
20-
find_package(rcpputils REQUIRED)
2134
find_package(rcutils REQUIRED)
2235
find_package(rosidl_runtime_c REQUIRED)
36+
if(NOT ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT)
37+
find_package(rcpputils REQUIRED)
38+
endif()
2339

2440
ament_export_dependencies(rcutils)
25-
ament_export_dependencies(rcpputils)
2641
ament_export_dependencies(rosidl_runtime_c)
2742
ament_export_dependencies(rosidl_typesupport_interface)
43+
if(NOT ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT)
44+
ament_export_dependencies(rcpputils)
45+
endif()
2846

2947
ament_python_install_package(${PROJECT_NAME})
3048

@@ -36,16 +54,23 @@ if(WIN32)
3654
target_compile_definitions(${PROJECT_NAME}
3755
PRIVATE "ROSIDL_TYPESUPPORT_C_BUILDING_DLL")
3856
endif()
57+
target_compile_definitions(${PROJECT_NAME}
58+
PRIVATE
59+
$<$<BOOL:${ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT}>:ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT>
60+
)
3961
target_include_directories(${PROJECT_NAME} PUBLIC
4062
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
4163
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
4264

4365
target_link_libraries(${PROJECT_NAME} PUBLIC
4466
rosidl_runtime_c::rosidl_runtime_c)
4567
target_link_libraries(${PROJECT_NAME} PRIVATE
46-
rcpputils::rcpputils
4768
rcutils::rcutils)
4869

70+
if(NOT ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT)
71+
target_link_libraries(${PROJECT_NAME} PRIVATE
72+
rcpputils::rcpputils)
73+
endif()
4974
# Export old-style CMake variables
5075
ament_export_include_directories("include/${PROJECT_NAME}")
5176
ament_export_libraries(${PROJECT_NAME})
@@ -132,12 +157,6 @@ if(BUILD_TESTING)
132157
ament_add_pytest_test(test_cli_extension test/test_cli_extension.py)
133158
endif()
134159

135-
if(BUILD_SHARED_LIBS)
136-
set(${PROJECT_NAME}_LIBRARY_TYPE "SHARED")
137-
else()
138-
set(${PROJECT_NAME}_LIBRARY_TYPE "STATIC")
139-
endif()
140-
141160
ament_package(
142161
CONFIG_EXTRAS "rosidl_typesupport_c-extras.cmake.in"
143162
)

rosidl_typesupport_c/cmake/rosidl_typesupport_c_generate_interfaces.cmake

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,19 @@ endif()
123123
# if only a single typesupport is used this package will directly reference it
124124
# therefore it needs to link against the selected typesupport
125125
if(NOT typesupports MATCHES ";")
126+
set(SINGLE_TYPE_SUPPORT ON)
127+
target_include_directories(${rosidl_generate_interfaces_TARGET}${_target_suffix}
128+
PUBLIC
129+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/${typesupports}>")
126130
target_link_libraries(${rosidl_generate_interfaces_TARGET}${_target_suffix} PRIVATE
127131
${rosidl_generate_interfaces_TARGET}__${typesupports})
128132
else()
133+
set(SINGLE_TYPE_SUPPORT OFF)
129134
if("${rosidl_typesupport_c_LIBRARY_TYPE}" STREQUAL "STATIC")
130-
message(FATAL_ERROR "Multiple typesupports [${typesupports}] but static "
131-
"linking was requested")
135+
target_compile_definitions(${rosidl_generate_interfaces_TARGET}${_target_suffix}
136+
PRIVATE
137+
ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT
138+
)
132139
endif()
133140
endif()
134141

@@ -151,18 +158,32 @@ endforeach()
151158
add_dependencies(
152159
${rosidl_generate_interfaces_TARGET}
153160
${rosidl_generate_interfaces_TARGET}${_target_suffix}
161+
${rosidl_generate_interfaces_TARGET}__rosidl_generator_c
162+
${rosidl_generate_interfaces_TARGET}__rosidl_typesupport_c
154163
)
155164

156165
if(NOT rosidl_generate_interfaces_SKIP_INSTALL)
157-
install(
158-
TARGETS ${rosidl_generate_interfaces_TARGET}${_target_suffix}
159-
EXPORT ${rosidl_generate_interfaces_TARGET}${_target_suffix}
160-
ARCHIVE DESTINATION lib
161-
LIBRARY DESTINATION lib
162-
RUNTIME DESTINATION bin
163-
)
166+
if(SINGLE_TYPE_SUPPORT)
167+
install(
168+
TARGETS
169+
${rosidl_generate_interfaces_TARGET}${_target_suffix}
170+
${rosidl_generate_interfaces_TARGET}__${typesupports}
171+
EXPORT ${rosidl_generate_interfaces_TARGET}${_target_suffix}
172+
ARCHIVE DESTINATION lib
173+
LIBRARY DESTINATION lib
174+
RUNTIME DESTINATION bin
175+
)
176+
else()
177+
install(
178+
TARGETS
179+
${rosidl_generate_interfaces_TARGET}${_target_suffix}
180+
EXPORT ${rosidl_generate_interfaces_TARGET}${_target_suffix}
181+
ARCHIVE DESTINATION lib
182+
LIBRARY DESTINATION lib
183+
RUNTIME DESTINATION bin
184+
)
185+
endif()
164186

165-
# Export old-style CMake variables
166187
ament_export_libraries(${rosidl_generate_interfaces_TARGET}${_target_suffix})
167188

168189
# Export modern CMake targets

rosidl_typesupport_c/resource/msg__type_support.cpp.em

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,34 @@ typedef struct _@(message.structure.namespaced_type.name)_type_support_data_t
8181
void * data[@(len(type_supports))];
8282
} _@(message.structure.namespaced_type.name)_type_support_data_t;
8383

84+
#ifdef ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT
85+
#ifdef __cplusplus
86+
extern "C"
87+
{
88+
#endif
89+
@[for type_support in sorted(type_supports)]@
90+
rosidl_message_type_support_t * ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(@(type_support), @(', '.join([package_name] + list(interface_path.parents[0].parts))), @(message.structure.namespaced_type.name))();
91+
@[end for]@
92+
#ifdef __cplusplus
93+
}
94+
#endif
95+
96+
static _@(message.structure.namespaced_type.name)_type_support_data_t _@(message.structure.namespaced_type.name)_message_typesupport_data = {
97+
{
98+
@[for type_support in sorted(type_supports)]@
99+
(void*) ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(@(type_support), @(', '.join([package_name] + list(interface_path.parents[0].parts))), @(message.structure.namespaced_type.name)),
100+
@[end for]@
101+
}
102+
};
103+
#else
84104
static _@(message.structure.namespaced_type.name)_type_support_data_t _@(message.structure.namespaced_type.name)_message_typesupport_data = {
85105
{
86106
@[for type_support in sorted(type_supports)]@
87107
0, // will store the shared library later
88108
@[end for]@
89109
}
90110
};
111+
#endif // ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT
91112

92113
static const type_support_map_t _@(message.structure.namespaced_type.name)_message_typesupport_map = {
93114
@(len(type_supports)),
@@ -97,7 +118,7 @@ static const type_support_map_t _@(message.structure.namespaced_type.name)_messa
97118
&_@(message.structure.namespaced_type.name)_message_typesupport_data.data[0],
98119
};
99120

100-
static const rosidl_message_type_support_t @(message.structure.namespaced_type.name)_message_type_support_handle = {
121+
static rosidl_message_type_support_t @(message.structure.namespaced_type.name)_message_type_support_handle = {
101122
rosidl_typesupport_c__typesupport_identifier,
102123
reinterpret_cast<const type_support_map_t *>(&_@(message.structure.namespaced_type.name)_message_typesupport_map),
103124
rosidl_typesupport_c__get_message_typesupport_handle_function,
@@ -136,6 +157,11 @@ extern "C"
136157
const rosidl_message_type_support_t *
137158
ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(rosidl_typesupport_c, @(', '.join([package_name] + list(interface_path.parents[0].parts))), @(message.structure.namespaced_type.name))() {
138159
@[if len(type_supports) != 1]@
160+
if (!::@('::'.join([package_name] + list(interface_path.parents[0].parts)))::rosidl_typesupport_c::@(message.structure.namespaced_type.name)_message_type_support_handle.typesupport_identifier) {
161+
::@('::'.join([package_name] + list(interface_path.parents[0].parts)))::rosidl_typesupport_c::@(message.structure.namespaced_type.name)_message_type_support_handle.typesupport_identifier =
162+
rosidl_typesupport_c__typesupport_identifier;
163+
}
164+
139165
return &::@('::'.join([package_name] + list(interface_path.parents[0].parts)))::rosidl_typesupport_c::@(message.structure.namespaced_type.name)_message_type_support_handle;
140166
@[else]@
141167
return ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(@(list(type_supports)[0]), @(', '.join([package_name] + list(interface_path.parents[0].parts))), @(message.structure.namespaced_type.name))();

rosidl_typesupport_c/resource/srv__type_support.cpp.em

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,34 @@ typedef struct _@(service.namespaced_type.name)_type_support_data_t
105105
void * data[@(len(type_supports))];
106106
} _@(service.namespaced_type.name)_type_support_data_t;
107107

108+
#ifdef ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT
109+
#ifdef __cplusplus
110+
extern "C"
111+
{
112+
#endif
113+
@[for type_support in sorted(type_supports)]@
114+
rosidl_service_type_support_t * ROSIDL_TYPESUPPORT_INTERFACE__SERVICE_SYMBOL_NAME(@(type_support), @(', '.join([package_name] + list(interface_path.parents[0].parts))), @(service.namespaced_type.name))();
115+
@[end for]@
116+
#ifdef __cplusplus
117+
}
118+
#endif
119+
120+
static _@(service.namespaced_type.name)_type_support_data_t _@(service.namespaced_type.name)_service_typesupport_data = {
121+
{
122+
@[for type_support in sorted(type_supports)]@
123+
(void*) ROSIDL_TYPESUPPORT_INTERFACE__SERVICE_SYMBOL_NAME(@(type_support), @(', '.join([package_name] + list(interface_path.parents[0].parts))), @(service.namespaced_type.name)),
124+
@[end for]@
125+
}
126+
};
127+
#else
108128
static _@(service.namespaced_type.name)_type_support_data_t _@(service.namespaced_type.name)_service_typesupport_data = {
109129
{
110130
@[for type_support in sorted(type_supports)]@
111131
0, // will store the shared library later
112132
@[end for]@
113133
}
114134
};
135+
#endif // ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT
115136

116137
static const type_support_map_t _@(service.namespaced_type.name)_service_typesupport_map = {
117138
@(len(type_supports)),
@@ -121,7 +142,7 @@ static const type_support_map_t _@(service.namespaced_type.name)_service_typesup
121142
&_@(service.namespaced_type.name)_service_typesupport_data.data[0],
122143
};
123144

124-
static const rosidl_service_type_support_t @(service.namespaced_type.name)_service_type_support_handle = {
145+
static rosidl_service_type_support_t @(service.namespaced_type.name)_service_type_support_handle = {
125146
rosidl_typesupport_c__typesupport_identifier,
126147
reinterpret_cast<const type_support_map_t *>(&_@(service.namespaced_type.name)_service_typesupport_map),
127148
rosidl_typesupport_c__get_service_typesupport_handle_function,
@@ -168,6 +189,11 @@ extern "C"
168189
const rosidl_service_type_support_t *
169190
ROSIDL_TYPESUPPORT_INTERFACE__SERVICE_SYMBOL_NAME(rosidl_typesupport_c, @(', '.join([package_name] + list(interface_path.parents[0].parts))), @(service.namespaced_type.name))() {
170191
@[if len(type_supports) != 1]@
192+
if (!::@('::'.join([package_name] + list(interface_path.parents[0].parts)))::rosidl_typesupport_c::@(service.namespaced_type.name)_service_type_support_handle.typesupport_identifier) {
193+
::@('::'.join([package_name] + list(interface_path.parents[0].parts)))::rosidl_typesupport_c::@(service.namespaced_type.name)_service_type_support_handle.typesupport_identifier =
194+
rosidl_typesupport_c__typesupport_identifier;
195+
}
196+
171197
return &::@('::'.join([package_name] + list(interface_path.parents[0].parts)))::rosidl_typesupport_c::@(service.namespaced_type.name)_service_type_support_handle;
172198
@[else]@
173199
return ROSIDL_TYPESUPPORT_INTERFACE__SERVICE_SYMBOL_NAME(@(list(type_supports)[0]), @(', '.join([package_name] + list(interface_path.parents[0].parts))), @(service.namespaced_type.name))();
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Copyright 2021 Open Source Robotics Foundation, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef DYNAMIC_SUPPORT_DISPATCH_HPP_
16+
#define DYNAMIC_SUPPORT_DISPATCH_HPP_
17+
18+
#include <cstddef>
19+
#include <cstdio>
20+
#include <cstring>
21+
22+
#include <memory>
23+
#include <stdexcept>
24+
#include <list>
25+
#include <string>
26+
27+
#include "rcpputils/shared_library.hpp"
28+
#include "rcutils/error_handling.h"
29+
#include "rcutils/snprintf.h"
30+
#include "rosidl_typesupport_c/type_support_map.h"
31+
32+
namespace rosidl_typesupport_c
33+
{
34+
35+
static void *
36+
handle_shared_library_from_name(
37+
const type_support_map_t * map,
38+
size_t map_item,
39+
const char * identifier
40+
)
41+
{
42+
rcpputils::SharedLibrary * lib = nullptr;
43+
44+
if (!map->data[map_item]) {
45+
char library_basename[1024];
46+
int ret = rcutils_snprintf(
47+
library_basename, 1023, "%s__%s",
48+
map->package_name, identifier);
49+
if (ret < 0) {
50+
RCUTILS_SET_ERROR_MSG("Failed to format library name");
51+
return nullptr;
52+
}
53+
54+
std::string library_name;
55+
try {
56+
library_name = rcpputils::get_platform_library_name(library_basename);
57+
} catch (const std::exception & e) {
58+
RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING(
59+
"Failed to compute library name for '%s' due to %s",
60+
library_basename, e.what());
61+
return nullptr;
62+
}
63+
64+
try {
65+
lib = new rcpputils::SharedLibrary(library_name);
66+
} catch (const std::runtime_error & e) {
67+
RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING(
68+
"Could not load library %s: %s", library_name.c_str(), e.what());
69+
return nullptr;
70+
} catch (const std::bad_alloc & e) {
71+
RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING(
72+
"Could not load library %s: %s", library_name.c_str(), e.what());
73+
return nullptr;
74+
}
75+
map->data[map_item] = lib;
76+
}
77+
78+
auto clib = static_cast<const rcpputils::SharedLibrary *>(map->data[map_item]);
79+
lib = const_cast<rcpputils::SharedLibrary *>(clib);
80+
81+
void * sym = nullptr;
82+
83+
try {
84+
if (!lib->has_symbol(map->symbol_name[map_item])) {
85+
RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING(
86+
"Failed to find symbol '%s' in library", map->symbol_name[map_item]);
87+
return nullptr;
88+
}
89+
sym = lib->get_symbol(map->symbol_name[map_item]);
90+
} catch (const std::exception & e) {
91+
RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING(
92+
"Failed to get symbol '%s' in library: %s",
93+
map->symbol_name[map_item], e.what());
94+
return nullptr;
95+
}
96+
97+
return sym;
98+
}
99+
100+
} // namespace rosidl_typesupport_c
101+
102+
#endif // DYNAMIC_SUPPORT_DISPATCH_HPP_

0 commit comments

Comments
 (0)