Skip to content

Commit e8738a4

Browse files
committed
micro-ROS Kilted patch
Signed-off-by: Antón Casas <antoncasas@eprosima.com>
1 parent ea3937b commit e8738a4

27 files changed

Lines changed: 271 additions & 54 deletions

.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:24.04
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
branches: [humble, jazzy, kilted, 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.20)
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
@@ -53,13 +61,13 @@ set(${PROJECT_NAME}_sources
5361
src/rcl/init_options.c
5462
src/rcl/lexer.c
5563
src/rcl/lexer_lookahead.c
56-
src/rcl/logging_rosout.c
57-
src/rcl/logging.c
58-
src/rcl/log_level.c
64+
$<$<NOT:$<BOOL:${RCL_MICROROS}>>:src/rcl/logging_rosout.c>
65+
$<$<NOT:$<BOOL:${RCL_MICROROS}>>:src/rcl/logging.c>
66+
$<$<NOT:$<BOOL:${RCL_MICROROS}>>:src/rcl/log_level.c>
5967
src/rcl/network_flow_endpoints.c
6068
src/rcl/node.c
6169
src/rcl/node_options.c
62-
src/rcl/node_type_cache.c
70+
$<$<NOT:$<BOOL:${RCL_MICROROS}>>:src/rcl/node_type_cache.c>
6371
src/rcl/publisher.c
6472
src/rcl/remap.c
6573
src/rcl/node_resolve_name.c
@@ -71,7 +79,7 @@ set(${PROJECT_NAME}_sources
7179
src/rcl/time.c
7280
src/rcl/timer.c
7381
src/rcl/type_hash.c
74-
src/rcl/type_description_conversions.c
82+
$<$<NOT:$<BOOL:${RCL_MICROROS}>>:src/rcl/type_description_conversions.c>
7583
src/rcl/validate_enclave_name.c
7684
src/rcl/validate_topic_name.c
7785
src/rcl/wait.c
@@ -87,20 +95,44 @@ target_link_libraries(${PROJECT_NAME} PUBLIC
8795
${rcl_interfaces_TARGETS}
8896
# TODO(clalancette): rcl_logging_interface should be PRIVATE, but downstream depends on it for now
8997
rcl_logging_interface::rcl_logging_interface
90-
rcl_yaml_param_parser::rcl_yaml_param_parser
9198
rcutils::rcutils
9299
rmw::rmw
93100
# TODO(clalancette): rmw_implementation should be PRIVATE, but downstream depends on it for now
94101
rmw_implementation::rmw_implementation
95102
rosidl_runtime_c::rosidl_runtime_c
96103
${type_description_interfaces_TARGETS}
97104
)
105+
106+
target_link_libraries(${PROJECT_NAME} PRIVATE
107+
tracetools::tracetools
108+
)
109+
110+
if(NOT RCL_MICROROS)
98111
target_link_libraries(${PROJECT_NAME} PRIVATE
99112
${RCL_LOGGING_IMPL}::${RCL_LOGGING_IMPL}
100113
${service_msgs_TARGETS}
101-
tracetools::tracetools
102114
yaml
103115
)
116+
endif()
117+
118+
if(NOT RCL_MICROROS)
119+
ament_target_dependencies(${PROJECT_NAME}
120+
"rcl_yaml_param_parser"
121+
)
122+
endif()
123+
124+
if(NOT RCL_MICROROS)
125+
ament_target_dependencies(${PROJECT_NAME}
126+
${RCL_LOGGING_IMPL}
127+
)
128+
endif()
129+
130+
if(NOT RCL_MICROROS)
131+
target_compile_definitions(${PROJECT_NAME}
132+
PUBLIC
133+
RCL_MICROROS_COMPLETE_IMPL
134+
)
135+
endif()
104136

105137
# Allow configuring the default discovery range
106138
if(DEFINED RCL_DEFAULT_DISCOVERY_RANGE)
@@ -140,14 +172,21 @@ ament_export_dependencies(ament_cmake)
140172
ament_export_dependencies(rcl_interfaces)
141173
# TODO(clalancette): rcl_logging_interface shouldn't be exported, but downstream depends on it for now
142174
ament_export_dependencies(rcl_logging_interface)
143-
ament_export_dependencies(rcl_yaml_param_parser)
144175
ament_export_dependencies(rcutils)
145176
ament_export_dependencies(rmw)
146177
# TODO(clalancette): rmw_implementation shouldn't be exported, but downstream depends on it for now
147178
ament_export_dependencies(rmw_implementation)
148179
ament_export_dependencies(rosidl_runtime_c)
149180
ament_export_dependencies(type_description_interfaces)
150-
ament_generate_version_header(${PROJECT_NAME})
181+
ament_export_dependencies(tracetools)
182+
183+
if(NOT RCL_MICROROS)
184+
ament_export_dependencies(rcl_yaml_param_parser)
185+
endif()
186+
187+
if(NOT RCL_MICROROS)
188+
ament_export_dependencies(${RCL_LOGGING_IMPL})
189+
endif()
151190

152191
if(BUILD_TESTING)
153192
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
@@ -179,6 +183,7 @@ rcl_client_init(
179183
client->impl->options = *options;
180184
atomic_init(&client->impl->sequence_number, 0);
181185

186+
#ifdef RCL_MICROROS_COMPLETE_IMPL
182187
const rosidl_type_hash_t * hash = type_support->get_type_hash_func(type_support);
183188
if (hash == NULL) {
184189
RCL_SET_ERROR_MSG("Failed to get the type hash");
@@ -196,6 +201,7 @@ rcl_client_init(
196201
goto destroy_client;
197202
}
198203
client->impl->type_hash = *hash;
204+
#endif // RCL_MICROROS_COMPLETE_IMPL
199205

200206
RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME, "Client initialized");
201207
TRACETOOLS_TRACEPOINT(
@@ -257,15 +263,15 @@ rcl_client_fini(rcl_client_t * client, rcl_node_t * node)
257263
RCL_SET_ERROR_MSG(rmw_get_error_string().str);
258264
result = RCL_RET_ERROR;
259265
}
260-
266+
#ifdef RCL_MICROROS_COMPLETE_IMPL
261267
if (
262268
ROSIDL_TYPE_HASH_VERSION_UNSET != client->impl->type_hash.version &&
263269
RCL_RET_OK != rcl_node_type_cache_unregister_type(node, &client->impl->type_hash))
264270
{
265271
RCUTILS_SAFE_FWRITE_TO_STDERR(rcl_get_error_string().str);
266272
result = RCL_RET_ERROR;
267273
}
268-
274+
#endif // RCL_MICROROS_COMPLETE_IMPL
269275
allocator.deallocate(client->impl->remapped_service_name, allocator.state);
270276
client->impl->remapped_service_name = NULL;
271277

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
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)