From c658ddeaf4630c7aae51d6f6e442a8c273815200 Mon Sep 17 00:00:00 2001 From: Erik Boasson Date: Thu, 26 Oct 2023 11:45:40 +0200 Subject: [PATCH] Disable CDDS-based plugin Can't work as a shared library in an otherwise static build, but linking it in statically causes nasty circular dependencies. So disable it altogether and rely on the Iceoryx plugin working fine. --- src/core/ddsc/tests/CMakeLists.txt | 41 +++++++++++++------ src/core/ddsc/tests/psmx.c | 33 ++++++++++++++- src/ddsrt/CMakeLists.txt | 5 +++ src/ddsrt/include/dds/features.h.in | 3 ++ .../core/tests/common/config_env.h.in | 10 +++-- 5 files changed, 74 insertions(+), 18 deletions(-) diff --git a/src/core/ddsc/tests/CMakeLists.txt b/src/core/ddsc/tests/CMakeLists.txt index be9db4499b..30194a804f 100644 --- a/src/core/ddsc/tests/CMakeLists.txt +++ b/src/core/ddsc/tests/CMakeLists.txt @@ -216,23 +216,38 @@ target_link_libraries(oneliner PRIVATE RoundTrip Space ddsc) # PSMX implementation with Cyclone as transport, for testing +# +# This is one disabled in a static build. In a fully static build, the plugin should also +# be linked statically, but that introduces a circular dependency: this plugin requires +# the library in order to be built ... Of course it can be fixed with a multi-phase +# build, but this CMake, not good old make and so that's too hard. +# +# On most platforms (Linux, Windows, macOS) we can still dynamically load shared +# libraries, and so we can still build the plugin as a shared library. That however fails +# to work because the shared library then includes its own copy of Cyclone DDS, but this +# one needs to access the applications readers', which live in the other copy of the +# library. +# +# Fortunately, The Iceoryx doesn't suffer from this, so all it needs is some trickery to +# still get the Iceoryx tests to run. +if (BUILD_SHARED_LIBS OR NOT DEFINED BUILD_SHARED_LIBS) + idlc_generate(TARGET psmx_cdds_data FILES psmx_cdds_data.idl) + set(psmx_cdds_sources + "psmx_cdds_impl.c" + "psmx_cdds_impl.h") + add_library(psmx_cdds SHARED ${psmx_cdds_sources}) + target_include_directories( + psmx_cdds PRIVATE + "$" + "$") + target_link_libraries(psmx_cdds PRIVATE ddsc psmx_cdds_data) -idlc_generate(TARGET psmx_cdds_data FILES psmx_cdds_data.idl) -set(psmx_cdds_sources - "psmx_cdds_impl.c" - "psmx_cdds_impl.h") -add_library(psmx_cdds SHARED ${psmx_cdds_sources}) -target_include_directories( - psmx_cdds PRIVATE - "$" - "$") -target_link_libraries(psmx_cdds PRIVATE ddsc psmx_cdds_data) - -generate_export_header(psmx_cdds BASE_NAME PSMX_CDDS EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/include/dds/psmx_cdds/export.h") + generate_export_header(psmx_cdds BASE_NAME PSMX_CDDS EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/include/dds/psmx_cdds/export.h") -install(TARGETS psmx_cdds + install(TARGETS psmx_cdds LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +endif() # If Iceoryx is available, then also run all PSMX tests using Iceoryx. Colcon complicates # things too much and it doesn't affect Cyclone's CI run anyway. diff --git a/src/core/ddsc/tests/psmx.c b/src/core/ddsc/tests/psmx.c index 532236430e..0d899c2f3b 100644 --- a/src/core/ddsc/tests/psmx.c +++ b/src/core/ddsc/tests/psmx.c @@ -63,6 +63,16 @@ static void fail_too_much_data (void) { fail (); } static dds_entity_t create_participant (dds_domainid_t int_dom) { + const char *psmx_plugin = "cdds"; + (void) ddsrt_getenv ("CDDS_PSMX_NAME", &psmx_plugin); +#ifdef DDS_IS_STATIC_LIBRARY + // Circular dependencies (solvable, but with risk of brain-damage because of CMake) + // with fully static builds and multiple copies of Cyclone if the plugin is built as + // a shared library while the core is a static library make this too hard a case. + if (strcmp (psmx_plugin, "cdds") == 0) + return 0; +#endif + assert (int_dom < MAX_DOMAINS); const unsigned char *l = psmx_locators[int_dom].a; char *configstr; @@ -71,7 +81,7 @@ static dds_entity_t create_participant (dds_domainid_t int_dom) \ spdp\ \ - \ + \ \ \ \ @@ -83,6 +93,7 @@ static dds_entity_t create_participant (dds_domainid_t int_dom) cdds.log.%d\ \ ", + psmx_plugin, psmx_plugin, l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], l[10], l[11], l[12], l[13], l[14], l[15], (int) l[0], // This prevents Iceoryx and Cyclone-based plugins from forwarding across the "network" (int) int_dom // log file name @@ -606,6 +617,10 @@ static void dotest (const dds_topic_descriptor_t *tpdesc, const void *sample, bo for (int i = 0; i < MAX_DOMAINS; i++) { pp[i] = create_participant ((dds_domainid_t) i); // FIXME: vary shm_enable for i > 0 + if (pp[i] == 0) { + CU_PASS ("skipped because of static build and cdds-based plugin"); + return; + } tp[i] = dds_create_topic (pp[i], tpdesc, topicname, NULL, NULL); CU_ASSERT_FATAL (tp[i] > 0); gvs[i] = get_domaingv (pp[i]); @@ -1054,6 +1069,10 @@ CU_Test(ddsc_psmx, return_loan) { dds_return_t rc; const dds_entity_t pp = create_participant (0); + if (pp == 0) { + CU_PASS ("skipped because of static build and cdds-based plugin"); + return; + } char topicname[100]; create_unique_topic_name ("test_psmx", topicname, sizeof (topicname)); const dds_entity_t tp = dds_create_topic (pp, &Array100_desc, topicname, NULL, NULL); @@ -1079,6 +1098,10 @@ CU_Test(ddsc_psmx, partition_xtalk) { dds_return_t rc; const dds_entity_t pp = create_participant (0); + if (pp == 0) { + CU_PASS ("skipped because of static build and cdds-based plugin"); + return; + } char topicname[100]; create_unique_topic_name ("test_psmx", topicname, sizeof (topicname)); const dds_entity_t tp = dds_create_topic (pp, &PsmxType1_desc, topicname, NULL, NULL); @@ -1184,6 +1207,10 @@ CU_Test (ddsc_psmx, basic) bool psmx_enabled; participant = create_participant (0); + if (participant == 0) { + CU_PASS ("skipped because of static build and cdds-based plugin"); + return; + } CU_ASSERT_FATAL (participant > 0); char topicname[100]; @@ -1243,6 +1270,10 @@ CU_Test (ddsc_psmx, zero_copy) dds_return_t rc; const dds_entity_t pp = create_participant (0); + if (pp == 0) { + CU_PASS ("skipped because of static build and cdds-based plugin"); + return; + } CU_ASSERT_FATAL (pp > 0); for (size_t k = 0; k < sizeof (cases) / sizeof (cases[0]); k++) { diff --git a/src/ddsrt/CMakeLists.txt b/src/ddsrt/CMakeLists.txt index febc6b3062..a76c7f51cf 100644 --- a/src/ddsrt/CMakeLists.txt +++ b/src/ddsrt/CMakeLists.txt @@ -319,6 +319,11 @@ if(BUILD_TESTING) set(DDS_ALLOW_NESTED_DOMAIN 1) endif() +if (BUILD_SHARED_LIBS OR NOT DEFINED BUILD_SHARED_LIBS) +else() + set(DDS_IS_STATIC_LIBRARY 1) +endif() + configure_file(include/dds/config.h.in include/dds/config.h) configure_file(include/dds/features.h.in include/dds/features.h) configure_file(include/dds/version.h.in include/dds/version.h) diff --git a/src/ddsrt/include/dds/features.h.in b/src/ddsrt/include/dds/features.h.in index 0bcf6f0bb1..28ac452333 100644 --- a/src/ddsrt/include/dds/features.h.in +++ b/src/ddsrt/include/dds/features.h.in @@ -41,4 +41,7 @@ /* Not for general use, specificly for testing psmx Cyclone DDS plugin */ #cmakedefine DDS_ALLOW_NESTED_DOMAIN 1 +/* Not intended for general use, whether building a static library, specifically testing psmx and security */ +#cmakedefine DDS_IS_STATIC_LIBRARY 1 + #endif diff --git a/src/security/core/tests/common/config_env.h.in b/src/security/core/tests/common/config_env.h.in index d2a68527dc..fba35a91ae 100644 --- a/src/security/core/tests/common/config_env.h.in +++ b/src/security/core/tests/common/config_env.h.in @@ -12,18 +12,20 @@ #ifndef CONFIG_ENV_H #define CONFIG_ENV_H +#include "dds/features.h" + #define FILE_PATH_SEP "/" #define COMMON_ETC_DIR "@common_etc_dir@" #define PLUGIN_WRAPPER_LIB_DIR "@plugin_wrapper_lib_dir@" #define PLUGIN_WRAPPER_LIB_PREFIX "@CMAKE_SHARED_LIBRARY_PREFIX@" #define PLUGIN_WRAPPER_LIB_SUFFIX "@CMAKE_SHARED_LIBRARY_SUFFIX@" -#if 0 // shared library: +// Statically linked plugins don't do path names +#ifdef DDS_IS_STATIC_LIBRARY +#define WRAPPERLIB_PATH(name) name +#else #define WRAPPERLIB_PATH(name) \ PLUGIN_WRAPPER_LIB_DIR FILE_PATH_SEP PLUGIN_WRAPPER_LIB_PREFIX name PLUGIN_WRAPPER_LIB_SUFFIX -#else // static library mode: -#define WRAPPERLIB_PATH(name) \ - name #endif #define COMMON_ETC_PATH(name) \