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

Add fastrtps (Fast-DDS) as supported dds middleware #148

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ build:clang --repo_env=CC=clang
build:clang --repo_env=CXX=clang++
build:clang --linkopt="-fuse-ld=lld"

# CycloneDDS is used as DDS vendor in the ROS Middleware by default in this repo.
# To use FastDDS, invoke Bazel with `--config=fastdds`.
build:fastdds --@com_github_mvukov_rules_ros2//ros2:dds_vendor=fastdds

# Load any settings specific to the current user.
# user.bazelrc should appear in .gitignore so that settings are not shared with
# team members. This needs to be last statement in this config,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Available features:
- Defining ROS 2 deployments with `ros2_launch` Bazel macro.
- Defining ROS 2 tests with `ros2_test` Bazel macro.
- Defining ROS 2 plugins with `ros2_plugin` Bazel macro.
- Only CycloneDDS middleware can be used at the moment.
- CycloneDDS (default) and FastDDS middleware are supported.
- Zero copy transport via shared memory backend ([iceoryx](https://github.com/eclipse-iceoryx/iceoryx)) for CycloneDDS.
- Utilities:
- [`foxglove_bridge`](https://github.com/foxglove/ros-foxglove-bridge) for visualization and debugging
Expand Down
33 changes: 33 additions & 0 deletions repositories/fastcdr.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
""" Builds FastCDR.
"""

load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")

filegroup(
name = "all_srcs",
srcs = glob(["**"]),
)

cache_entries = {
"CMAKE_POSITION_INDEPENDENT_CODE": "ON", # Must be set!
"BUILD_SHARED_LIBS": "OFF",
# FastCDR specific options.
"APPEND_PROJECT_NAME_TO_INCLUDEDIR": "OFF",
"BUILD_DOCUMENTATION": "OFF",
"CHECK_DOCUMENTATION": "OFF",
"EPROSIMA_BUILD": "OFF",
"EPROSIMA_BUILD_TESTS": "OFF",
"EPROSIMA_INSTALLER": "OFF",
}

cmake(
name = "fastcdr",
build_args = [
"--",
"-j4",
],
cache_entries = cache_entries,
lib_source = ":all_srcs",
out_static_libs = ["libfastcdr.a"],
visibility = ["//visibility:public"],
)
134 changes: 134 additions & 0 deletions repositories/fastrtps.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
""" Builds FastDDS.
"""

load("@bazel_skylib//lib:dicts.bzl", "dicts")
load("@bazel_skylib//lib:selects.bzl", "selects")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")

bool_flag(
name = "enable_shm",
build_setting_default = False,
)

config_setting(
name = "enable_shm_on",
flag_values = {":enable_shm": "True"},
visibility = ["//visibility:public"],
)

config_setting(
name = "enable_shm_off",
flag_values = {":enable_shm": "False"},
visibility = ["//visibility:public"],
)

selects.config_setting_group(
name = "linux_or_macos",
match_any = [
"@platforms//os:linux",
"@platforms//os:macos",
],
)

selects.config_setting_group(
name = "linux_or_macos_with_shm",
match_all = [
":linux_or_macos",
":enable_shm_on",
],
)

selects.config_setting_group(
name = "qnx_with_shm",
match_all = [
"@platforms//os:qnx",
":enable_shm_on",
],
)

selects.config_setting_group(
name = "linux_or_macos_without_shm",
match_all = [
":linux_or_macos",
":enable_shm_off",
],
)

selects.config_setting_group(
name = "qnx_without_shm",
match_all = [
"@platforms//os:qnx",
":enable_shm_off",
],
)

filegroup(
name = "all_srcs",
srcs = glob(["**"]),
)

cache_entries = {
"CMAKE_POSITION_INDEPENDENT_CODE": "ON", # Must be set!
"BUILD_SHARED_LIBS": "OFF",
# FastDDS specific options.
"BUILD_DOCUMENTATION": "OFF",
"CHECK_DOCUMENTATION": "OFF",
"COMPILE_EXAMPLES": "OFF",
"COMPILE_TOOLS": "OFF",
"FASTDDS_STATISTICS": "OFF",
"INSTALL_EXAMPLES": "OFF",
"INSTALL_TOOLS": "OFF",
"NO_TLS": "ON",
"SECURITY": "OFF",
}

cache_entries_with_shm = {
"SHM_TRANSPORT_DEFAULT": "ON",
}

cache_entries_without_shm = {
"SHM_TRANSPORT_DEFAULT": "OFF",
}

cmake(
name = "fastrtps",
build_args = [
"--",
"-j4",
],
cache_entries = select(
{
":enable_shm_on": dicts.add(
cache_entries,
cache_entries_with_shm,
),
":enable_shm_off": dicts.add(
cache_entries,
cache_entries_without_shm,
),
},
no_match_error = "Unsupported build configuration",
),
lib_source = ":all_srcs",
linkopts = select(
{
":linux_or_macos_with_shm": [
"-lpthread",
"-lrt",
],
":qnx_with_shm": ["-lrt"],
":linux_or_macos_without_shm": ["-lpthread"],
":qnx_without_shm": [],
},
no_match_error = "Only Linux, macOS and QNX are supported!",
),
out_static_libs = ["libfastrtps.a"],
visibility = ["//visibility:public"],
deps = [
"@asio",
"@fastcdr",
"@foonathan_memory",
"@tinyxml2",
],
)
29 changes: 29 additions & 0 deletions repositories/foonathan_memory.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
""" Builds foonathan_memory.
"""

load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")

filegroup(
name = "all_srcs",
srcs = glob(["**"]),
)

cache_entries = {
"CMAKE_POSITION_INDEPENDENT_CODE": "ON", # Must be set!
"BUILD_SHARED_LIBS": "OFF",
# foonathan_memory specific options.
"FOONATHAN_MEMORY_BUILD_EXAMPLES": "OFF",
"FOONATHAN_MEMORY_BUILD_TESTS": "OFF",
}

cmake(
name = "foonathan_memory",
build_args = [
"--",
"-j4",
],
cache_entries = cache_entries,
lib_source = ":all_srcs",
out_static_libs = ["libfoonathan_memory-0.7.3.a"],
visibility = ["//visibility:public"],
)
14 changes: 14 additions & 0 deletions repositories/patches/foonathan_memory_remove_dbg_suffix.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0b82f0b..50c1bb9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,9 +13,6 @@ set(FOONATHAN_MEMORY_VERSION "${FOONATHAN_MEMORY_VERSION_MAJOR}.${FOONATHAN_MEMO
CACHE STRING "version of memory" FORCE)


-# set a debug postfix
-set(CMAKE_DEBUG_POSTFIX "-dbg")
-
# installation destinations
if(UNIX OR VXWORKS)
include(GNUInstallDirs)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
diff --git a/rmw_fastrtps_dynamic_cpp/src/type_support_common.cpp b/rmw_fastrtps_dynamic_cpp/src/type_support_common.cpp
index d602069..62e4362 100644
--- a/rmw_fastrtps_dynamic_cpp/src/type_support_common.cpp
+++ b/rmw_fastrtps_dynamic_cpp/src/type_support_common.cpp
@@ -25,12 +25,13 @@
bool
using_introspection_c_typesupport(const char * typesupport_identifier)
{
- return typesupport_identifier == rosidl_typesupport_introspection_c__identifier;
+ return !std::string(typesupport_identifier)
+ .compare(rosidl_typesupport_introspection_c__identifier);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would std::strcmp work if you would cast rosidl_typesupport_introspection_c__identifier to char*?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strcmp works, I just wanted to use the same method as the patch for cyclonedds to be consistent

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As pointed out in ros2/rmw_cyclonedds#320, std::strcmp is a bit of an optimization and will avoid an extra mem. alloc. (Eventually we should also refactor the rwm_cyclonedds patch, but that's for a follow-up.)

}

bool
using_introspection_cpp_typesupport(const char * typesupport_identifier)
{
- return typesupport_identifier ==
- rosidl_typesupport_introspection_cpp::typesupport_identifier;
+ return !std::string(typesupport_identifier)
+ .compare(rosidl_typesupport_introspection_cpp::typesupport_identifier);
}
54 changes: 54 additions & 0 deletions repositories/rmw_fastrtps.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
""" Builds rmw_fastrtps.
"""

load(
"@com_github_mvukov_rules_ros2//ros2:cc_defs.bzl",
"ros2_cpp_binary",
"ros2_cpp_library",
)

ros2_cpp_library(
name = "rmw_fastrtps_shared_cpp",
srcs = glob([
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please split into hdrs and srcs.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think header files in src belong in srcs. They don't look like they're intended for downstream rules to #include directly.

"rmw_fastrtps_shared_cpp/src/*.cpp",
"rmw_fastrtps_shared_cpp/src/**/*.hpp",
]),
hdrs = glob([
"rmw_fastrtps_shared_cpp/include/**/*.h",
"rmw_fastrtps_shared_cpp/include/**/*.hpp",
]),
includes = ["rmw_fastrtps_shared_cpp/include"],
visibility = ["//visibility:public"],
deps = [
"@fastrtps",
"@ros2_rcpputils//:rcpputils",
"@ros2_rcutils//:rcutils",
"@ros2_rmw//:rmw",
"@ros2_rmw//:rmw_cpp",
"@ros2_rmw_dds_common//:rmw_dds_common_lib",
"@ros2_rosidl//:rosidl_runtime_c",
"@ros2_rosidl//:rosidl_typesupport_introspection_c",
"@ros2_rosidl//:rosidl_typesupport_introspection_cpp",
"@ros2_tracing//:tracetools",
],
)

ros2_cpp_binary(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, fastdds supports two modes per https://fast-dds.docs.eprosima.com/en/latest/fastdds/ros2/ros2.html#ros-2-using-fast-dds-middleware:

  • rmw_fastrtps_dynamic_cpp that can use introspection-based type-support that we already have. This one should be easy to integrate. cyclonedds rmw uses introspection-based type-support.
  • rmw_fastrtps_cpp that uses their custom type-support. This is involved as fastdds-specific IDL code generation needs to be implemented.

This is for rclc/rclcpp part, I think. I'm not 100% sure, should be checked, which type-support rclpy expects/can work with.

My take: as a first step, if it suits your needs, just integrate rmw_fastrtps_dynamic_cpp.

If we want to go with rmw_fastrtps_cpp then we will also need to use dds_vendor switch in IDL code-generation, to only generate what's necessary. This might get involved -- haven't studied what generated code fastdds needs.

Please let me know what you think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will switch it to dynamic instead. I tried this before, but didn't have improving results. Let's see if I can make it work!

name = "rmw_fastrtps_dynamic_cpp",
srcs = glob([
"rmw_fastrtps_dynamic_cpp/include/**/*.h",
"rmw_fastrtps_dynamic_cpp/include/**/*.hpp",
"rmw_fastrtps_dynamic_cpp/src/*.cpp",
"rmw_fastrtps_dynamic_cpp/src/*.hpp",
]),
copts = ["-fvisibility=hidden"],
includes = ["rmw_fastrtps_dynamic_cpp/include"],
linkopts = ["-fvisibility=hidden"],
linkshared = True,
visibility = ["//visibility:public"],
deps = [
":rmw_fastrtps_shared_cpp",
"@ros2_rosidl_typesupport_fastrtps//:rosidl_typesupport_fastrtps_c",
"@ros2_rosidl_typesupport_fastrtps//:rosidl_typesupport_fastrtps_cpp",
mvukov marked this conversation as resolved.
Show resolved Hide resolved
],
)
20 changes: 14 additions & 6 deletions repositories/rmw_implementation.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@ ros2_cpp_library(
"rmw_implementation/src/visibility_control.h",
],
copts = ["-w"],
data = [
"@ros2_rmw_cyclonedds//:rmw_cyclonedds",
],
data = select(
{
"@com_github_mvukov_rules_ros2//ros2:use_cyclonedds": ["@ros2_rmw_cyclonedds//:rmw_cyclonedds"],
"@com_github_mvukov_rules_ros2//ros2:use_fastdds_dynamic": ["@ros2_rmw_fastrtps//:rmw_fastrtps_dynamic_cpp"],
},
no_match_error = "Unsupported dds vendor",
),
includes = ["include"],
local_defines = [
"RMW_LIBRARY_PATH=\\\"$(rootpath @ros2_rmw_cyclonedds//:rmw_cyclonedds)\\\"",
],
local_defines = select(
{
"@com_github_mvukov_rules_ros2//ros2:use_cyclonedds": ["RMW_LIBRARY_PATH=\\\"$(rootpath @ros2_rmw_cyclonedds//:rmw_cyclonedds)\\\""],
"@com_github_mvukov_rules_ros2//ros2:use_fastdds_dynamic": ["RMW_LIBRARY_PATH=\\\"$(rootpath @ros2_rmw_fastrtps//:rmw_fastrtps_dynamic_cpp)\\\""],
},
no_match_error = "Unsupported dds vendor",
),
visibility = ["//visibility:public"],
deps = [
"@ros2_rcpputils//:rcpputils",
Expand Down
18 changes: 18 additions & 0 deletions repositories/ros2_repo_mappings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ repositories:
cyclonedds:
name: cyclonedds
build_file: "@com_github_mvukov_rules_ros2//repositories:cyclonedds.BUILD.bazel"
fastcdr:
name: fastcdr
build_file: "@com_github_mvukov_rules_ros2//repositories:fastcdr.BUILD.bazel"
fastrtps:
name: fastrtps # 2.6.2
build_file: "@com_github_mvukov_rules_ros2//repositories:fastrtps.BUILD.bazel"
foonathan_memory:
name: foonathan_memory
build_file: "@com_github_mvukov_rules_ros2//repositories:foonathan_memory.BUILD.bazel"
patch_args: ["-p1"]
patches:
- "@com_github_mvukov_rules_ros2//repositories/patches:foonathan_memory_remove_dbg_suffix.patch"
geometry2:
name: ros2_geometry2
build_file: "@com_github_mvukov_rules_ros2//repositories:geometry2.BUILD.bazel"
Expand Down Expand Up @@ -96,6 +108,12 @@ repositories:
rmw_dds_common:
name: ros2_rmw_dds_common
build_file: "@com_github_mvukov_rules_ros2//repositories:rmw_dds_common.BUILD.bazel"
rmw_fastrtps:
name: ros2_rmw_fastrtps
build_file: "@com_github_mvukov_rules_ros2//repositories:rmw_fastrtps.BUILD.bazel"
patch_args: ["-p1"]
patches:
- "@com_github_mvukov_rules_ros2//repositories/patches:rmw_fastrtps-fix-typesupport-conditions-bug.patch"
rmw_implementation:
name: ros2_rmw_implementation
build_file: "@com_github_mvukov_rules_ros2//repositories:rmw_implementation.BUILD.bazel"
Expand Down
Loading
Loading