Skip to content

Commit 02e97d4

Browse files
4ntnDavid-LP99
authored andcommitted
micro-ROS Lyrical patch
Signed-off-by: Antón Casas <antoncasas@eprosima.com> Signed-off-by: David Laseca <davidlaseca@eprosima.com>
1 parent 71406a1 commit 02e97d4

20 files changed

Lines changed: 535 additions & 36 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, master]
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+
"*.in": "c"
5+
}
6+
}

‎CMakeLists.txt‎

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ cmake_minimum_required(VERSION 3.20)
22

33
project(rcutils)
44

5+
option(RCUTILS_NO_THREAD_SUPPORT "Disable thread support." OFF)
6+
option(RCUTILS_NO_FILESYSTEM "Disable filesystem usage." OFF)
7+
option(RCUTILS_AVOID_DYNAMIC_ALLOCATION "Disable dynamic allocations." OFF)
8+
option(RCUTILS_NO_64_ATOMIC "Enable alternative support for 64 bits atomic operations in platforms with no native support." OFF)
9+
option(RCUTILS_MICROROS "Flag for building micro-ROS." ON)
10+
511
include(CheckLibraryExists)
612

713
find_package(ament_cmake REQUIRED)
@@ -17,7 +23,7 @@ if(UNIX AND NOT APPLE)
1723
endif()
1824
endif()
1925

20-
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
26+
if(NOT RCUTILS_MICROROS AND (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
2127
# enables building a static library but later link it into a dynamic library
2228
add_compile_options(-fPIC)
2329
endif()
@@ -66,6 +72,7 @@ set(rcutils_sources
6672
src/time.c
6773
${time_impl_c}
6874
src/uint8_array.c
75+
$<$<BOOL:${RCUTILS_NO_64_ATOMIC}>:src/atomic_64bits.c>
6976
)
7077
set_source_files_properties(
7178
${rcutils_sources}
@@ -76,6 +83,7 @@ add_library(
7683
${rcutils_sources})
7784
target_include_directories(${PROJECT_NAME} PUBLIC
7885
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
86+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>"
7987
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
8088

8189
# Causes the visibility macros to use dllexport rather than dllimport,
@@ -87,10 +95,18 @@ if(BUILD_TESTING AND NOT RCUTILS_DISABLE_FAULT_INJECTION)
8795
endif()
8896

8997
target_link_libraries(${PROJECT_NAME}
90-
${CMAKE_DL_LIBS}
9198
ament_cmake_ros_core::ament_ros_defaults
9299
)
93100

101+
configure_file(
102+
"${PROJECT_SOURCE_DIR}/include/rcutils/configuration_flags.h.in"
103+
"${PROJECT_BINARY_DIR}/include/rcutils/configuration_flags.h"
104+
)
105+
106+
if(NOT RCUTILS_NO_FILESYSTEM)
107+
target_link_libraries(${PROJECT_NAME} ${CMAKE_DL_LIBS})
108+
endif()
109+
94110
check_library_exists(atomic __atomic_load_8 "" HAVE_LIBATOMICS)
95111

96112
if(HAVE_LIBATOMICS AND NOT WIN32 AND NOT APPLE)
@@ -162,20 +178,22 @@ if(BUILD_TESTING)
162178
TIMEOUT 10
163179
)
164180

165-
ament_add_gmock(test_logging_macros test/test_logging_macros.cpp)
166-
target_link_libraries(test_logging_macros
167-
${PROJECT_NAME}
168-
ament_cmake_ros_core::ament_ros_defaults
169-
)
181+
if(NOT RCUTILS_MICROROS)
182+
ament_add_gmock(test_logging_macros test/test_logging_macros.cpp)
183+
target_link_libraries(test_logging_macros
184+
${PROJECT_NAME}
185+
ament_cmake_ros_core::ament_ros_defaults
186+
)
170187

171-
add_executable(test_logging_macros_c test/test_logging_macros.c)
172-
target_link_libraries(test_logging_macros_c
173-
${PROJECT_NAME}
174-
ament_cmake_ros_core::ament_ros_defaults
175-
)
176-
ament_add_test(test_logging_macros_c
177-
COMMAND "$<TARGET_FILE:test_logging_macros_c>"
178-
GENERATE_RESULT_FOR_RETURN_CODE_ZERO)
188+
add_executable(test_logging_macros_c test/test_logging_macros.c)
189+
target_link_libraries(test_logging_macros_c
190+
${PROJECT_NAME}
191+
ament_cmake_ros_core::ament_ros_defaults
192+
)
193+
ament_add_test(test_logging_macros_c
194+
COMMAND "$<TARGET_FILE:test_logging_macros_c>"
195+
GENERATE_RESULT_FOR_RETURN_CODE_ZERO)
196+
endif()
179197

180198
set(SKIP_MEMORY_TOOLS_TEST "")
181199
if(NOT memory_tools_is_available)
@@ -637,15 +655,17 @@ if(BUILD_TESTING)
637655
)
638656
endif()
639657

640-
ament_add_gtest(test_logging_enable_for
641-
test/test_logging_enable_for.cpp
642-
)
643-
if(TARGET test_logging_enable_for)
644-
target_link_libraries(test_logging_enable_for
645-
${PROJECT_NAME}
646-
osrf_testing_tools_cpp::memory_tools
647-
ament_cmake_ros_core::ament_ros_defaults
658+
if(NOT RCUTILS_MICROROS)
659+
ament_add_gtest(test_logging_enable_for
660+
test/test_logging_enable_for.cpp
648661
)
662+
if(TARGET test_logging_enable_for)
663+
target_link_libraries(test_logging_enable_for
664+
${PROJECT_NAME}
665+
osrf_testing_tools_cpp::memory_tools
666+
ament_cmake_ros_core::ament_ros_defaults
667+
)
668+
endif()
649669
endif()
650670

651671
ament_add_gtest(test_logging_console_output_handler
@@ -696,5 +716,5 @@ ament_export_dependencies(ament_cmake ament_cmake_ros_core)
696716
ament_package()
697717

698718
install(
699-
DIRECTORY include/
719+
DIRECTORY include/ ${CMAKE_CURRENT_BINARY_DIR}/include/
700720
DESTINATION include/${PROJECT_NAME})

‎include/rcutils/allocator.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,21 @@ RCUTILS_WARN_UNUSED
8585
rcutils_allocator_t
8686
rcutils_get_zero_initialized_allocator(void);
8787

88+
/// Set rcutils default allocators.
89+
/**
90+
* <hr>
91+
* Attribute | Adherence
92+
* ------------------ | -------------
93+
* Allocates Memory | No
94+
* Thread-Safe | Yes
95+
* Uses Atomics | No
96+
* Lock-Free | Yes
97+
*/
98+
RCUTILS_PUBLIC
99+
RCUTILS_WARN_UNUSED
100+
bool
101+
rcutils_set_default_allocator(rcutils_allocator_t * allocator);
102+
88103
/// Return a properly initialized rcutils_allocator_t with default values.
89104
/**
90105
* This defaults to:
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
#ifndef RCUTILS__CONFIGURATION_FLAGS_H_
3+
#define RCUTILS__CONFIGURATION_FLAGS_H_
4+
5+
#ifdef __cplusplus
6+
extern "C"
7+
{
8+
#endif
9+
10+
#cmakedefine RCUTILS_NO_FILESYSTEM
11+
#cmakedefine RCUTILS_AVOID_DYNAMIC_ALLOCATION
12+
#cmakedefine RCUTILS_NO_THREAD_SUPPORT
13+
#cmakedefine RCUTILS_MICROROS
14+
15+
#ifdef __cplusplus
16+
}
17+
#endif
18+
19+
#endif // RCUTILS__CONFIGURATION_FLAGS_H_

‎include/rcutils/error_handling.h‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,19 @@ extern "C"
3737
#include "rcutils/testing/fault_injection.h"
3838
#include "rcutils/types/rcutils_ret.h"
3939
#include "rcutils/visibility_control.h"
40+
#include "rcutils/configuration_flags.h"
4041

42+
#if !defined(RCUTILS_NO_FILESYSTEM)
4143
/// Write the given msg out to stderr, limiting the buffer size in the `fwrite`.
4244
/**
4345
* This ensures that there is an upper bound to a buffer overrun if `msg` is
4446
* non-null terminated.
4547
*/
4648
#define RCUTILS_SAFE_FWRITE_TO_STDERR(msg) \
4749
do {fwrite(msg, sizeof(char), rcutils_strnlen(msg, 4096), stderr);} while (0)
50+
#else
51+
#define RCUTILS_SAFE_FWRITE_TO_STDERR(msg)
52+
#endif
4853

4954
/// Set the error message to stderr using a format string and format arguments.
5055
/**
@@ -55,6 +60,8 @@ extern "C"
5560
* \param[in] format_string The string to be used as the format of the error message.
5661
* \param[in] ... Arguments for the format string.
5762
*/
63+
64+
#if !defined(RCUTILS_AVOID_DYNAMIC_ALLOCATION)
5865
#define RCUTILS_SAFE_FWRITE_TO_STDERR_WITH_FORMAT_STRING(format_string, ...) \
5966
do { \
6067
char output_msg[RCUTILS_ERROR_MESSAGE_MAX_LENGTH]; \
@@ -66,7 +73,11 @@ extern "C"
6673
RCUTILS_SAFE_FWRITE_TO_STDERR(output_msg); \
6774
} \
6875
} while (0)
76+
#else
77+
#define RCUTILS_SAFE_FWRITE_TO_STDERR_WITH_FORMAT_STRING(format_string, ...)
78+
#endif
6979

80+
#if !defined(RCUTILS_AVOID_DYNAMIC_ALLOCATION)
7081
/// The maximum length a formatted number is allowed to have.
7182
#define RCUTILS_ERROR_STATE_LINE_NUMBER_STR_MAX_LENGTH 20 // "18446744073709551615"
7283

@@ -93,6 +104,13 @@ extern "C"
93104
RCUTILS_ERROR_STATE_LINE_NUMBER_STR_MAX_LENGTH - \
94105
RCUTILS_ERROR_FORMATTING_CHARACTERS - \
95106
1)
107+
#else
108+
#define RCUTILS_ERROR_STATE_LINE_NUMBER_STR_MAX_LENGTH 1
109+
#define RCUTILS_ERROR_FORMATTING_CHARACTERS 1
110+
#define RCUTILS_ERROR_MESSAGE_MAX_LENGTH 1
111+
#define RCUTILS_ERROR_STATE_MESSAGE_MAX_LENGTH 1
112+
#define RCUTILS_ERROR_STATE_FILE_MAX_LENGTH 1
113+
#endif // RCUTILS_AVOID_DYNAMIC_ALLOCATION
96114

97115
/// Struct wrapping a fixed-size c string used for returning the formatted error string.
98116
typedef struct rcutils_error_string_s
@@ -114,7 +132,7 @@ typedef struct rcutils_error_state_s
114132
} rcutils_error_state_t;
115133

116134
// make sure our math is right...
117-
#if __STDC_VERSION__ >= 201112L
135+
#if __STDC_VERSION__ >= 201112L && !defined(RCUTILS_AVOID_DYNAMIC_ALLOCATION)
118136
static_assert(
119137
sizeof(rcutils_error_string_t) == (
120138
RCUTILS_ERROR_STATE_MESSAGE_MAX_LENGTH +
@@ -226,8 +244,12 @@ rcutils_set_error_state(const char * error_string, const char * file, size_t lin
226244
*
227245
* \param[in] msg The error message to be set.
228246
*/
247+
#ifdef RCUTILS_AVOID_DYNAMIC_ALLOCATION
248+
#define RCUTILS_SET_ERROR_MSG(msg)
249+
#else
229250
#define RCUTILS_SET_ERROR_MSG(msg) \
230251
do {rcutils_set_error_state(msg, __FILE__, __LINE__);} while (0)
252+
#endif // RCUTILS_AVOID_DYNAMIC_ALLOCATION
231253

232254
/// Set the error message using a format string and format arguments.
233255
/**
@@ -238,6 +260,9 @@ rcutils_set_error_state(const char * error_string, const char * file, size_t lin
238260
* \param[in] format_string The string to be used as the format of the error message.
239261
* \param[in] ... Arguments for the format string.
240262
*/
263+
#ifdef RCUTILS_AVOID_DYNAMIC_ALLOCATION
264+
#define RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING(format_string, ...)
265+
#else
241266
#define RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING(format_string, ...) \
242267
do { \
243268
char output_msg[RCUTILS_ERROR_MESSAGE_MAX_LENGTH]; \
@@ -249,6 +274,8 @@ rcutils_set_error_state(const char * error_string, const char * file, size_t lin
249274
RCUTILS_SET_ERROR_MSG(output_msg); \
250275
} \
251276
} while (0)
277+
#endif // RCUTILS_AVOID_DYNAMIC_ALLOCATION
278+
252279

253280
/// Indicate that the function intends to set an error message and return an error value.
254281
/**

‎include/rcutils/logging.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extern "C"
4141
* \def RCUTILS_DEFAULT_LOGGER_DEFAULT_LEVEL
4242
* \brief The default severity level of the default logger.
4343
*/
44-
#define RCUTILS_DEFAULT_LOGGER_DEFAULT_LEVEL RCUTILS_LOG_SEVERITY_INFO
44+
#define RCUTILS_DEFAULT_LOGGER_DEFAULT_LEVEL RCUTILS_LOG_SEVERITY_UNSET
4545

4646
/// The flag if the logging system has been initialized.
4747
RCUTILS_PUBLIC

‎include/rcutils/logging_macros.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ extern "C"
3939
* Use RCUTILS_LOG_MIN_SEVERITY_NONE to compile out all macros.
4040
*/
4141
#ifndef RCUTILS_LOG_MIN_SEVERITY
42-
#define RCUTILS_LOG_MIN_SEVERITY RCUTILS_LOG_MIN_SEVERITY_DEBUG
42+
#define RCUTILS_LOG_MIN_SEVERITY RCUTILS_LOG_MIN_SEVERITY_NONE
4343
#endif
4444

4545
/**

‎include/rcutils/macros.h‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ extern "C"
2222
{
2323
#endif
2424

25+
#include "rcutils/configuration_flags.h"
26+
2527
#ifndef _MSC_VER
2628
/// A macro to make the compiler warn when the return value of a function is not used.
2729
#define RCUTILS_WARN_UNUSED __attribute__((warn_unused_result))
@@ -32,7 +34,9 @@ extern "C"
3234

3335
/// \cond Doxygen_Suppress
3436
// This block either sets RCUTILS_THREAD_LOCAL or RCUTILS_THREAD_LOCAL_PTHREAD.
35-
#if defined _WIN32 || defined __CYGWIN__
37+
#if defined(RCUTILS_NO_THREAD_SUPPORT)
38+
#define RCUTILS_THREAD_LOCAL
39+
#elif defined _WIN32 || defined __CYGWIN__
3640
// Windows or Cygwin
3741
#define RCUTILS_THREAD_LOCAL __declspec(thread)
3842
#elif defined __APPLE__

0 commit comments

Comments
 (0)