Skip to content

Commit 2edcff4

Browse files
committed
micro-ROS Jazzy patch
1 parent d1ad72d commit 2edcff4

27 files changed

+271
-55
lines changed

.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: [galactic, humble, 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

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"files.associations": {
3+
"*.uml": "plantuml",
4+
"service_event_publisher.h": "c"
5+
}
6+
}

rcl/CMakeLists.txt

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,33 @@ cmake_minimum_required(VERSION 3.5)
22

33
project(rcl)
44

5+
option(RCL_MICROROS "micro-ROS build mode" ON)
6+
57
find_package(ament_cmake_ros REQUIRED)
68
find_package(ament_cmake_gen_version_h REQUIRED)
79

8-
find_package(libyaml_vendor REQUIRED)
910
find_package(rcl_interfaces REQUIRED)
1011
find_package(rcl_logging_interface REQUIRED)
11-
find_package(rcl_yaml_param_parser REQUIRED)
1212
find_package(rcutils REQUIRED)
1313
find_package(rmw REQUIRED)
1414
find_package(rmw_implementation REQUIRED)
1515
find_package(rosidl_runtime_c REQUIRED)
1616
find_package(service_msgs REQUIRED)
1717
find_package(tracetools REQUIRED)
1818
find_package(type_description_interfaces REQUIRED)
19-
find_package(yaml REQUIRED)
19+
20+
if(NOT RCL_MICROROS)
21+
find_package(libyaml_vendor REQUIRED)
22+
find_package(yaml REQUIRED)
23+
find_package(rcl_yaml_param_parser REQUIRED)
24+
endif()
2025

2126
include(cmake/rcl_set_symbol_visibility_hidden.cmake)
22-
include(cmake/get_default_rcl_logging_implementation.cmake)
23-
get_default_rcl_logging_implementation(RCL_LOGGING_IMPL)
27+
28+
if(NOT RCL_MICROROS)
29+
include(cmake/get_default_rcl_logging_implementation.cmake)
30+
get_default_rcl_logging_implementation(RCL_LOGGING_IMPL)
31+
endif()
2432

2533
# Default to C11
2634
if(NOT CMAKE_C_STANDARD)
@@ -38,7 +46,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
3846
endif()
3947

4048
set(${PROJECT_NAME}_sources
41-
src/rcl/arguments.c
49+
$<$<NOT:$<BOOL:${RCL_MICROROS}>>:src/rcl/arguments.c>
4250
src/rcl/client.c
4351
src/rcl/common.c
4452
src/rcl/context.c
@@ -54,13 +62,13 @@ set(${PROJECT_NAME}_sources
5462
src/rcl/lexer.c
5563
src/rcl/lexer_lookahead.c
5664
src/rcl/localhost.c
57-
src/rcl/logging_rosout.c
58-
src/rcl/logging.c
59-
src/rcl/log_level.c
65+
$<$<NOT:$<BOOL:${RCL_MICROROS}>>:src/rcl/logging_rosout.c>
66+
$<$<NOT:$<BOOL:${RCL_MICROROS}>>:src/rcl/logging.c>
67+
$<$<NOT:$<BOOL:${RCL_MICROROS}>>:src/rcl/log_level.c>
6068
src/rcl/network_flow_endpoints.c
6169
src/rcl/node.c
6270
src/rcl/node_options.c
63-
src/rcl/node_type_cache.c
71+
$<$<NOT:$<BOOL:${RCL_MICROROS}>>:src/rcl/node_type_cache.c>
6472
src/rcl/publisher.c
6573
src/rcl/remap.c
6674
src/rcl/node_resolve_name.c
@@ -72,7 +80,7 @@ set(${PROJECT_NAME}_sources
7280
src/rcl/time.c
7381
src/rcl/timer.c
7482
src/rcl/type_hash.c
75-
src/rcl/type_description_conversions.c
83+
$<$<NOT:$<BOOL:${RCL_MICROROS}>>:src/rcl/type_description_conversions.c>
7684
src/rcl/validate_enclave_name.c
7785
src/rcl/validate_topic_name.c
7886
src/rcl/wait.c
@@ -88,20 +96,44 @@ target_link_libraries(${PROJECT_NAME} PUBLIC
8896
${rcl_interfaces_TARGETS}
8997
# TODO(clalancette): rcl_logging_interface should be PRIVATE, but downstream depends on it for now
9098
rcl_logging_interface::rcl_logging_interface
91-
rcl_yaml_param_parser::rcl_yaml_param_parser
9299
rcutils::rcutils
93100
rmw::rmw
94101
# TODO(clalancette): rmw_implementation should be PRIVATE, but downstream depends on it for now
95102
rmw_implementation::rmw_implementation
96103
rosidl_runtime_c::rosidl_runtime_c
97104
${type_description_interfaces_TARGETS}
98105
)
106+
107+
target_link_libraries(${PROJECT_NAME} PRIVATE
108+
tracetools::tracetools
109+
)
110+
111+
if(NOT RCL_MICROROS)
99112
target_link_libraries(${PROJECT_NAME} PRIVATE
100113
${RCL_LOGGING_IMPL}::${RCL_LOGGING_IMPL}
101114
${service_msgs_TARGETS}
102-
tracetools::tracetools
103115
yaml
104116
)
117+
endif()
118+
119+
if(NOT RCL_MICROROS)
120+
ament_target_dependencies(${PROJECT_NAME}
121+
"rcl_yaml_param_parser"
122+
)
123+
endif()
124+
125+
if(NOT RCL_MICROROS)
126+
ament_target_dependencies(${PROJECT_NAME}
127+
${RCL_LOGGING_IMPL}
128+
)
129+
endif()
130+
131+
if(NOT RCL_MICROROS)
132+
target_compile_definitions(${PROJECT_NAME}
133+
PUBLIC
134+
RCL_MICROROS_COMPLETE_IMPL
135+
)
136+
endif()
105137

106138
# Allow configuring the default discovery range
107139
if(DEFINED RCL_DEFAULT_DISCOVERY_RANGE)
@@ -141,14 +173,21 @@ ament_export_dependencies(ament_cmake)
141173
ament_export_dependencies(rcl_interfaces)
142174
# TODO(clalancette): rcl_logging_interface shouldn't be exported, but downstream depends on it for now
143175
ament_export_dependencies(rcl_logging_interface)
144-
ament_export_dependencies(rcl_yaml_param_parser)
145176
ament_export_dependencies(rcutils)
146177
ament_export_dependencies(rmw)
147178
# TODO(clalancette): rmw_implementation shouldn't be exported, but downstream depends on it for now
148179
ament_export_dependencies(rmw_implementation)
149180
ament_export_dependencies(rosidl_runtime_c)
150181
ament_export_dependencies(type_description_interfaces)
151-
ament_generate_version_header(${PROJECT_NAME})
182+
ament_export_dependencies(tracetools)
183+
184+
if(NOT RCL_MICROROS)
185+
ament_export_dependencies(rcl_yaml_param_parser)
186+
endif()
187+
188+
if(NOT RCL_MICROROS)
189+
ament_export_dependencies(${RCL_LOGGING_IMPL})
190+
endif()
152191

153192
if(BUILD_TESTING)
154193
find_package(ament_lint_auto REQUIRED)

rcl/include/rcl/arguments.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@
2222
#include "rcl/macros.h"
2323
#include "rcl/types.h"
2424
#include "rcl/visibility_control.h"
25+
#ifdef RCL_MICROROS_COMPLETE_IMPL
2526
#include "rcl_yaml_param_parser/types.h"
27+
#else
28+
typedef bool rcl_params_t;
29+
#endif // RCL_MICROROS_COMPLETE_IMPL
2630

2731
#ifdef __cplusplus
2832
extern "C"

rcl/include/rcl/context.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ extern "C"
2525
#include "rmw/init.h"
2626

2727
#include "rcl/allocator.h"
28+
#ifdef RCL_MICROROS_COMPLETE_IMPL
2829
#include "rcl/arguments.h"
30+
#endif // RCL_MICROROS_COMPLETE_IMPL
2931
#include "rcl/init_options.h"
3032
#include "rcl/macros.h"
3133
#include "rcl/types.h"
@@ -112,21 +114,18 @@ typedef struct rcl_context_impl_s rcl_context_impl_t;
112114
*/
113115
typedef struct rcl_context_s
114116
{
117+
#ifdef RCL_MICROROS_COMPLETE_IMPL
115118
/// Global arguments for all nodes which share this context.
116119
/** Typically generated by the parsing of argc/argv in rcl_init(). */
117120
rcl_arguments_t global_arguments;
121+
#endif // RCL_MICROROS_COMPLETE_IMPL
118122

119123
/// Implementation specific pointer.
120124
rcl_context_impl_t * impl;
121125

122126
// The assumption that this is big enough for an atomic_uint_least64_t is
123127
// ensured with a static_assert in the context.c file.
124128
// In most cases it should just be a plain uint64_t.
125-
/// @cond Doxygen_Suppress
126-
#if !defined(RCL_CONTEXT_ATOMIC_INSTANCE_ID_STORAGE_SIZE)
127-
#define RCL_CONTEXT_ATOMIC_INSTANCE_ID_STORAGE_SIZE sizeof(uint_least64_t)
128-
#endif
129-
/// @endcond
130129
/// Private storage for instance ID atomic.
131130
/**
132131
* Accessing the instance id should be done using the function
@@ -146,7 +145,7 @@ typedef struct rcl_context_s
146145
* See this paper for an effort to make this possible in the future:
147146
* http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0943r1.html
148147
*/
149-
RCL_ALIGNAS(8) uint8_t instance_id_storage[RCL_CONTEXT_ATOMIC_INSTANCE_ID_STORAGE_SIZE];
148+
uint32_t instance_id_storage;
150149
} rcl_context_t;
151150

152151
/// Return a zero initialization context object.

rcl/include/rcl/node.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ extern "C"
2525
#include <stdint.h>
2626

2727
#include "rcl/allocator.h"
28+
#ifdef RCL_MICROROS_COMPLETE_IMPL
2829
#include "rcl/arguments.h"
30+
#endif // RCL_MICROROS_COMPLETE_IMPL
2931
#include "rcl/context.h"
3032
#include "rcl/guard_condition.h"
3133
#include "rcl/macros.h"

rcl/include/rcl/node_options.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ extern "C"
2323
#endif
2424

2525
#include "rcl/allocator.h"
26+
#ifdef RCL_MICROROS_COMPLETE_IMPL
2627
#include "rcl/arguments.h"
28+
#endif // RCL_MICROROS_COMPLETE_IMPL
29+
#include "rcl/macros.h"
2730

2831
#include "rcl/domain_id.h"
2932

@@ -46,8 +49,10 @@ typedef struct rcl_node_options_s
4649
/// If false then only use arguments in this struct, otherwise use global arguments also.
4750
bool use_global_arguments;
4851

52+
#ifdef RCL_MICROROS_COMPLETE_IMPL
4953
/// Command line arguments that apply only to this node.
5054
rcl_arguments_t arguments;
55+
#endif // RCL_MICROROS_COMPLETE_IMPL
5156

5257
/// Flag to enable rosout for this node
5358
bool enable_rosout;

rcl/src/rcl/arguments_impl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717

1818
#include "rcl/arguments.h"
1919
#include "rcl/log_level.h"
20+
#ifdef RCL_MICROROS_COMPLETE_IMPL
2021
#include "rcl_yaml_param_parser/types.h"
22+
#else
23+
typedef bool rcl_params_t;
24+
#endif // RCL_MICROROS_COMPLETE_IMPL
2125
#include "./remap_impl.h"
2226

2327
#ifdef __cplusplus

rcl/src/rcl/client.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ extern "C"
2424

2525
#include "rcl/error_handling.h"
2626
#include "rcl/node.h"
27+
#ifdef RCL_MICROROS_COMPLETE_IMPL
2728
#include "rcl/node_type_cache.h"
29+
#endif // RCL_MICROROS_COMPLETE_IMPL
2830
#include "rcl/publisher.h"
2931
#include "rcl/time.h"
3032
#include "rcutils/logging_macros.h"
@@ -49,7 +51,9 @@ struct rcl_client_impl_s
4951
atomic_int_least64_t sequence_number;
5052
rcl_service_event_publisher_t * service_event_publisher;
5153
char * remapped_service_name;
54+
#ifdef RCL_MICROROS_COMPLETE_IMPL
5255
rosidl_type_hash_t type_hash;
56+
#endif // RCL_MICROROS_COMPLETE_IMPL
5357
};
5458

5559
rcl_client_t
@@ -178,6 +182,7 @@ rcl_client_init(
178182
client->impl->options = *options;
179183
atomic_init(&client->impl->sequence_number, 0);
180184

185+
#ifdef RCL_MICROROS_COMPLETE_IMPL
181186
const rosidl_type_hash_t * hash = type_support->get_type_hash_func(type_support);
182187
if (hash == NULL) {
183188
RCL_SET_ERROR_MSG("Failed to get the type hash");
@@ -195,6 +200,7 @@ rcl_client_init(
195200
goto destroy_client;
196201
}
197202
client->impl->type_hash = *hash;
203+
#endif // RCL_MICROROS_COMPLETE_IMPL
198204

199205
RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME, "Client initialized");
200206
TRACETOOLS_TRACEPOINT(
@@ -256,15 +262,15 @@ rcl_client_fini(rcl_client_t * client, rcl_node_t * node)
256262
RCL_SET_ERROR_MSG(rmw_get_error_string().str);
257263
result = RCL_RET_ERROR;
258264
}
259-
265+
#ifdef RCL_MICROROS_COMPLETE_IMPL
260266
if (
261267
ROSIDL_TYPE_HASH_VERSION_UNSET != client->impl->type_hash.version &&
262268
RCL_RET_OK != rcl_node_type_cache_unregister_type(node, &client->impl->type_hash))
263269
{
264270
RCUTILS_SAFE_FWRITE_TO_STDERR(rcl_get_error_string().str);
265271
result = RCL_RET_ERROR;
266272
}
267-
273+
#endif // RCL_MICROROS_COMPLETE_IMPL
268274
allocator.deallocate(client->impl->remapped_service_name, allocator.state);
269275
client->impl->remapped_service_name = NULL;
270276

rcl/src/rcl/context.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,12 @@ rcl_get_zero_initialized_context(void)
3030
{
3131
static rcl_context_t context = {
3232
.impl = NULL,
33-
.instance_id_storage = {0},
33+
.instance_id_storage = 0,
3434
};
3535
// this is not constexpr so it cannot be in the struct initialization
36+
#ifdef RCL_MICROROS_COMPLETE_IMPL
3637
context.global_arguments = rcl_get_zero_initialized_arguments();
37-
// ensure assumption about static storage
38-
static_assert(
39-
sizeof(context.instance_id_storage) >= sizeof(atomic_uint_least64_t),
40-
"expected rcl_context_t's instance id storage to be >= size of atomic_uint_least64_t");
41-
// initialize atomic
42-
atomic_init((atomic_uint_least64_t *)(&context.instance_id_storage), 0);
38+
#endif // RCL_MICROROS_COMPLETE_IMPL
4339
return context;
4440
}
4541

@@ -76,7 +72,7 @@ rcl_context_instance_id_t
7672
rcl_context_get_instance_id(const rcl_context_t * context)
7773
{
7874
RCL_CHECK_ARGUMENT_FOR_NULL(context, 0);
79-
return rcutils_atomic_load_uint64_t((atomic_uint_least64_t *)(&context->instance_id_storage));
75+
return context->instance_id_storage;
8076
}
8177

8278
rcl_ret_t
@@ -110,8 +106,9 @@ __cleanup_context(rcl_context_t * context)
110106
{
111107
rcl_ret_t ret = RCL_RET_OK;
112108
// reset the instance id to 0 to indicate "invalid" (should already be 0, but this is defensive)
113-
rcutils_atomic_store((atomic_uint_least64_t *)(&context->instance_id_storage), 0);
109+
context->instance_id_storage = 0;
114110

111+
#ifdef RCL_MICROROS_COMPLETE_IMPL
115112
// clean up global_arguments if initialized
116113
if (NULL != context->global_arguments.impl) {
117114
ret = rcl_arguments_fini(&(context->global_arguments));
@@ -124,6 +121,7 @@ __cleanup_context(rcl_context_t * context)
124121
rcl_reset_error();
125122
}
126123
}
124+
#endif // RCL_MICROROS_COMPLETE_IMPL
127125

128126
// if impl is null, nothing else can be cleaned up
129127
if (NULL != context->impl) {

0 commit comments

Comments
 (0)