Skip to content

Commit

Permalink
Fix shared memory for fastrtps
Browse files Browse the repository at this point in the history
  • Loading branch information
henriksod committed Jul 30, 2023
1 parent 444f46c commit 103ce2a
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 21 deletions.
6 changes: 3 additions & 3 deletions repositories/fastcdr.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ cache_entries = {
"CMAKE_POSITION_INDEPENDENT_CODE": "ON", # Must be set!
"BUILD_SHARED_LIBS": "OFF",
# FastCDR specific options.
"EPROSIMA_INSTALLER": "OFF",
"EPROSIMA_BUILD": "OFF",
"EPROSIMA_BUILD_TESTS": "OFF",
"APPEND_PROJECT_NAME_TO_INCLUDEDIR": "OFF",
"BUILD_DOCUMENTATION": "OFF",
"CHECK_DOCUMENTATION": "OFF",
"EPROSIMA_BUILD": "OFF",
"EPROSIMA_BUILD_TESTS": "OFF",
"EPROSIMA_INSTALLER": "OFF",
}

cmake(
Expand Down
106 changes: 95 additions & 11 deletions repositories/fastrtps.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,8 +1,68 @@
""" 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(["**"]),
Expand All @@ -13,16 +73,24 @@ cache_entries = {
"CMAKE_POSITION_INDEPENDENT_CODE": "ON", # Must be set!
"BUILD_SHARED_LIBS": "OFF",
# FastDDS specific options.
"SECURITY": "OFF",
"NO_TLS": "ON",
"SHM_TRANSPORT_DEFAULT": "ON",
"BUILD_DOCUMENTATION": "OFF",
"CHECK_DOCUMENTATION": "OFF",
"COMPILE_EXAMPLES": "OFF",
"COMPILE_TOOLS": "OFF",
"INSTALL_TOOLS": "OFF",
"FASTDDS_STATISTICS": "OFF",
"COMPILE_EXAMPLES": "OFF",
"INSTALL_EXAMPLES": "OFF",
"BUILD_DOCUMENTATION": "OFF",
"CHECK_DOCUMENTATION": "OFF",
"INSTALL_TOOLS": "OFF",
"NO_TLS": "ON",
"SECURITY": "OFF",
"SHM_TRANSPORT_DEFAULT": "ON",
}

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

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

cmake(
Expand All @@ -31,13 +99,29 @@ cmake(
"--",
"-j4",
],
cache_entries = cache_entries,
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(
{
"@platforms//os:linux": ["-lpthread"],
"@platforms//os:macos": ["-lpthread"],
"@platforms//os:qnx": [],
":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!",
),
Expand Down
6 changes: 4 additions & 2 deletions repositories/rmw_fastrtps.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ load(
ros2_cpp_library(
name = "rmw_fastrtps_shared_cpp",
srcs = glob([
"rmw_fastrtps_shared_cpp/include/**/*.h",
"rmw_fastrtps_shared_cpp/include/**/*.hpp",
"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 = [
Expand Down
4 changes: 2 additions & 2 deletions repositories/rmw_implementation.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ ros2_cpp_library(
data = select(
{
"@com_github_mvukov_rules_ros2//ros2:use_cyclonedds": ["@ros2_rmw_cyclonedds//:rmw_cyclonedds"],
"@com_github_mvukov_rules_ros2//ros2:use_fastdds": ["@ros2_rmw_fastrtps//:rmw_fastrtps_dynamic_cpp"],
"@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 = 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": ["RMW_LIBRARY_PATH=\\\"$(rootpath @ros2_rmw_fastrtps//:rmw_fastrtps_dynamic_cpp)\\\""],
"@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",
),
Expand Down
5 changes: 4 additions & 1 deletion repositories/ros2_repo_mappings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repositories:
name: fastcdr
build_file: "@com_github_mvukov_rules_ros2//repositories:fastcdr.BUILD.bazel"
fastrtps:
name: fastrtps
name: fastrtps # 2.6.2
build_file: "@com_github_mvukov_rules_ros2//repositories:fastrtps.BUILD.bazel"
foonathan_memory:
name: foonathan_memory
Expand Down Expand Up @@ -108,6 +108,9 @@ repositories:
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
3 changes: 1 addition & 2 deletions ros2/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ py_binary(
],
)

# DDS vendor settings
string_flag(
name = "dds_vendor",
build_setting_default = "cyclonedds",
Expand All @@ -84,7 +83,7 @@ config_setting(
)

config_setting(
name = "use_fastdds",
name = "use_fastdds_dynamic",
flag_values = {":dds_vendor": "fastdds"},
visibility = ["//visibility:public"],
)

0 comments on commit 103ce2a

Please sign in to comment.