diff --git a/.bazelrc b/.bazelrc index b0c59c76..c53f8050 100644 --- a/.bazelrc +++ b/.bazelrc @@ -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, diff --git a/README.md b/README.md index f6f0c5ab..175ed1d7 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/repositories/fastcdr.BUILD.bazel b/repositories/fastcdr.BUILD.bazel new file mode 100644 index 00000000..7885706b --- /dev/null +++ b/repositories/fastcdr.BUILD.bazel @@ -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"], +) diff --git a/repositories/fastrtps.BUILD.bazel b/repositories/fastrtps.BUILD.bazel new file mode 100644 index 00000000..cc512324 --- /dev/null +++ b/repositories/fastrtps.BUILD.bazel @@ -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", + ], +) diff --git a/repositories/foonathan_memory.BUILD.bazel b/repositories/foonathan_memory.BUILD.bazel new file mode 100644 index 00000000..5a56a3ef --- /dev/null +++ b/repositories/foonathan_memory.BUILD.bazel @@ -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"], +) diff --git a/repositories/patches/foonathan_memory_remove_dbg_suffix.patch b/repositories/patches/foonathan_memory_remove_dbg_suffix.patch new file mode 100644 index 00000000..9610e608 --- /dev/null +++ b/repositories/patches/foonathan_memory_remove_dbg_suffix.patch @@ -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) diff --git a/repositories/patches/rmw_fastrtps-fix-typesupport-conditions-bug.patch b/repositories/patches/rmw_fastrtps-fix-typesupport-conditions-bug.patch new file mode 100644 index 00000000..093d1d40 --- /dev/null +++ b/repositories/patches/rmw_fastrtps-fix-typesupport-conditions-bug.patch @@ -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); + } + + 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); + } diff --git a/repositories/rmw_fastrtps.BUILD.bazel b/repositories/rmw_fastrtps.BUILD.bazel new file mode 100644 index 00000000..19134a01 --- /dev/null +++ b/repositories/rmw_fastrtps.BUILD.bazel @@ -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([ + "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( + 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", + ], +) diff --git a/repositories/rmw_implementation.BUILD.bazel b/repositories/rmw_implementation.BUILD.bazel index 7549c9cb..867cf597 100644 --- a/repositories/rmw_implementation.BUILD.bazel +++ b/repositories/rmw_implementation.BUILD.bazel @@ -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", diff --git a/repositories/ros2_repo_mappings.yaml b/repositories/ros2_repo_mappings.yaml index 615f0588..19fb3b7a 100644 --- a/repositories/ros2_repo_mappings.yaml +++ b/repositories/ros2_repo_mappings.yaml @@ -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" @@ -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" diff --git a/repositories/ros2_repositories_impl.bzl b/repositories/ros2_repositories_impl.bzl index 005489ce..7f7e300c 100644 --- a/repositories/ros2_repositories_impl.bzl +++ b/repositories/ros2_repositories_impl.bzl @@ -48,6 +48,35 @@ def ros2_repositories_impl(): url = "https://github.com/eclipse-cyclonedds/cyclonedds/archive/refs/tags/0.9.1.tar.gz", ) + maybe( + http_archive, + name = "fastcdr", + build_file = "@com_github_mvukov_rules_ros2//repositories:fastcdr.BUILD.bazel", + sha256 = "5c4b2ad5493abd30b9475b14856641a8944c98077a36bd0760c1d83c65216e67", + strip_prefix = "Fast-CDR-1.1.0", + url = "https://github.com/eProsima/Fast-CDR/archive/refs/tags/v1.1.0.tar.gz", + ) + + maybe( + http_archive, + name = "fastrtps", + build_file = "@com_github_mvukov_rules_ros2//repositories:fastrtps.BUILD.bazel", + sha256 = "463af750b4d956710611d58179e02817de65f3f9beb94c600c74d826b0746a84", + strip_prefix = "Fast-DDS-2.6.2", + url = "https://github.com/eProsima/Fast-DDS/archive/refs/tags/v2.6.2.tar.gz", + ) + + maybe( + http_archive, + 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"], + sha256 = "4203d15db22a94a3978eeb1afb59a37d35c57c0f148733f0f1a53a6281cb74dd", + strip_prefix = "memory-0.7-3", + url = "https://github.com/foonathan/memory/archive/refs/tags/v0.7-3.tar.gz", + ) + maybe( http_archive, name = "ros2_geometry2", @@ -253,6 +282,17 @@ def ros2_repositories_impl(): url = "https://github.com/ros2/rmw_dds_common/archive/refs/tags/1.6.0.tar.gz", ) + maybe( + http_archive, + 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"], + sha256 = "a0145b414207a2528fd56e98a56bd6d4c3f0353dcd58f4b3a65224af8bd52284", + strip_prefix = "rmw_fastrtps-6.2.3", + url = "https://github.com/ros2/rmw_fastrtps/archive/refs/tags/6.2.3.tar.gz", + ) + maybe( http_archive, name = "ros2_rmw_implementation", @@ -353,6 +393,15 @@ def ros2_repositories_impl(): url = "https://github.com/ros2/rosidl_typesupport/archive/refs/tags/2.0.0.tar.gz", ) + maybe( + http_archive, + name = "ros2_rosidl_typesupport_fastrtps", + build_file = "@com_github_mvukov_rules_ros2//repositories:rosidl_typesupport_fastrtps.BUILD.bazel", + sha256 = "41deed571ab95f7d2a191af6e4536536f13266df059b0b11f6469be8e44cf304", + strip_prefix = "rosidl_typesupport_fastrtps-2.2.1", + url = "https://github.com/ros2/rosidl_typesupport_fastrtps/archive/refs/tags/2.2.1.tar.gz", + ) + maybe( http_archive, name = "ros2_rpyutils", diff --git a/repositories/rosidl.BUILD.bazel b/repositories/rosidl.BUILD.bazel index 63bf837e..2cee51d7 100644 --- a/repositories/rosidl.BUILD.bazel +++ b/repositories/rosidl.BUILD.bazel @@ -168,6 +168,7 @@ ros2_c_library( srcs = glob(["rosidl_typesupport_introspection_c/src/*.c"]), hdrs = glob(["rosidl_typesupport_introspection_c/include/**/*.h"]), includes = ["rosidl_typesupport_introspection_c/include"], + linkstatic = False, visibility = ["//visibility:public"], ) @@ -179,6 +180,7 @@ ros2_cpp_library( "rosidl_typesupport_introspection_cpp/include/**/*.h", ]), includes = ["rosidl_typesupport_introspection_cpp/include"], + linkstatic = False, visibility = ["//visibility:public"], deps = [ ":rosidl_runtime_c", diff --git a/repositories/rosidl_typesupport_fastrtps.BUILD.bazel b/repositories/rosidl_typesupport_fastrtps.BUILD.bazel new file mode 100644 index 00000000..f70bd233 --- /dev/null +++ b/repositories/rosidl_typesupport_fastrtps.BUILD.bazel @@ -0,0 +1,42 @@ +""" Builds rosidl_typesupport_fastrtps. +""" + +load("@bazel_skylib//rules:copy_file.bzl", "copy_file") +load( + "@com_github_mvukov_rules_ros2//ros2:cc_defs.bzl", + "ros2_c_library", + "ros2_cpp_library", +) +load("@rules_python//python:defs.bzl", "py_binary", "py_library") + +ros2_cpp_library( + name = "rosidl_typesupport_fastrtps_c", + srcs = glob(["rosidl_typesupport_fastrtps_c/src/*.cpp"]), + hdrs = glob([ + "rosidl_typesupport_fastrtps_c/include/**/*.h", + "rosidl_typesupport_fastrtps_c/include/**/*.hpp", + ]), + includes = ["rosidl_typesupport_fastrtps_c/include"], + visibility = ["//visibility:public"], + deps = [ + "@ros2_rcpputils//:rcpputils", + "@ros2_rcutils//:rcutils", + "@ros2_rosidl//:rosidl_runtime_c", + ], +) + +ros2_cpp_library( + name = "rosidl_typesupport_fastrtps_cpp", + srcs = glob(["rosidl_typesupport_fastrtps_cpp/src/*.cpp"]), + hdrs = glob([ + "rosidl_typesupport_fastrtps_cpp/include/**/*.h", + "rosidl_typesupport_fastrtps_cpp/include/**/*.hpp", + ]), + includes = ["rosidl_typesupport_fastrtps_cpp/include"], + visibility = ["//visibility:public"], + deps = [ + ":rosidl_typesupport_fastrtps_c", + "@ros2_rcpputils//:rcpputils", + "@ros2_rosidl//:rosidl_runtime_c", + ], +) diff --git a/ros2/BUILD.bazel b/ros2/BUILD.bazel index 59a136f2..28327ad8 100644 --- a/ros2/BUILD.bazel +++ b/ros2/BUILD.bazel @@ -1,6 +1,8 @@ """ ROS 2 common definitions. """ +load("@bazel_skylib//lib:selects.bzl", "selects") +load("@bazel_skylib//rules:common_settings.bzl", "string_flag") load("@rules_python//python:defs.bzl", "py_binary", "py_library") exports_files([ @@ -64,3 +66,24 @@ py_binary( "@ros2cli//:ros2lifecycle", ], ) + +string_flag( + name = "dds_vendor", + build_setting_default = "cyclonedds", + values = [ + "cyclonedds", + "fastdds", + ], +) + +config_setting( + name = "use_cyclonedds", + flag_values = {":dds_vendor": "cyclonedds"}, + visibility = ["//visibility:public"], +) + +config_setting( + name = "use_fastdds_dynamic", + flag_values = {":dds_vendor": "fastdds"}, + visibility = ["//visibility:public"], +) diff --git a/ros2/test/BUILD.bazel b/ros2/test/BUILD.bazel index 42ed53ca..25260f2e 100644 --- a/ros2/test/BUILD.bazel +++ b/ros2/test/BUILD.bazel @@ -60,6 +60,7 @@ ros2_cpp_test( idl_deps = [ "@ros2_common_interfaces//:std_msgs", ], + linkstatic = False, deps = [ "@com_google_googletest//:gtest", "@ros2_rclcpp//:rclcpp",