This is an automated email from the ASF dual-hosted git repository. jdanek pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git
The following commit(s) were added to refs/heads/main by this push: new 2bff679 DISPATCH-2178: Do not build separate libqpid-dispatch.so (#1267) 2bff679 is described below commit 2bff67975707ed2bab36bb31c38aa542290a035b Author: Jiri Daněk <jda...@redhat.com> AuthorDate: Mon Jun 28 17:03:42 2021 +0200 DISPATCH-2178: Do not build separate libqpid-dispatch.so (#1267) --- CMakeLists.txt | 5 ++--- dockerfiles/Dockerfile-centos7 | 2 +- router/CMakeLists.txt | 6 ++---- run.py.in | 1 - src/CMakeLists.txt | 22 ++++++---------------- src/config.h.in | 1 - src/dispatch.c | 5 +++-- src/{config.h.in => empty.c} | 7 ++----- src/server.c | 2 +- src/timer.c | 3 +-- tests/CMakeLists.txt | 16 ++++++++-------- tests/c_unittests/CMakeLists.txt | 4 ++-- 12 files changed, 28 insertions(+), 46 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f8b24a..49d9a43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -275,15 +275,14 @@ install(FILES README DESTINATION ${QD_DOC_INSTALL_DIR}) -add_subdirectory(src) # Build src first so other subdirs can use QPID_DISPATCH_LIB - -# run.py environment runner script - needs QPID_DISPATCH_LIB configure_file(${CMAKE_CURRENT_SOURCE_DIR}/run.py.in ${CMAKE_CURRENT_BINARY_DIR}/run.py) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/run.py.in ${CMAKE_CURRENT_BINARY_DIR}/tests/run.py) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/system_tests_http.py.in ${CMAKE_CURRENT_SOURCE_DIR}/tests/system_tests_http.py) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/python/qpid_dispatch_internal/management/agent.py.in ${CMAKE_CURRENT_SOURCE_DIR}/python/qpid_dispatch_internal/management/agent.py) execute_process(COMMAND ${RUN} --sh OUTPUT_FILE config.sh) +add_subdirectory(src) # Build src first so other subdirs can use qpid-dispatch library + if (NOT UNITTEST_MISSING) file(GLOB SCRAPER_SRC ${CMAKE_CURRENT_SOURCE_DIR}/tools/scraper/*.py) file(COPY ${SCRAPER_SRC} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/tests/scraper/) diff --git a/dockerfiles/Dockerfile-centos7 b/dockerfiles/Dockerfile-centos7 index 9610d05..3ddc800 100644 --- a/dockerfiles/Dockerfile-centos7 +++ b/dockerfiles/Dockerfile-centos7 @@ -44,7 +44,7 @@ MAINTAINER "d...@qpid.apache.org" RUN yum -y install epel-release # now install the rest of the packages -RUN yum -y install gcc gcc-c++ cmake libuuid-devel openssl-devel cyrus-sasl-devel cyrus-sasl-plain cyrus-sasl-gssapi cyrus-sasl-md5 swig python-devel git make doxygen valgrind emacs libwebsockets-devel && yum clean all -y +RUN yum -y install gcc gcc-c++ cmake libuuid-devel openssl-devel cyrus-sasl-devel cyrus-sasl-plain cyrus-sasl-gssapi cyrus-sasl-md5 swig python3-devel git make doxygen valgrind emacs libwebsockets-devel && yum clean all -y # Create a main directory and clone the qpid-proton repo from github RUN mkdir /main && cd /main && git clone https://github.com/apache/qpid-proton.git && cd /main/qpid-proton && mkdir /main/qpid-proton/build diff --git a/router/CMakeLists.txt b/router/CMakeLists.txt index 659627a..45a6de6 100644 --- a/router/CMakeLists.txt +++ b/router/CMakeLists.txt @@ -32,9 +32,7 @@ set(router_SOURCES src/main.c ) -SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${QPID_DISPATCH_HOME}") - -add_executable(qdrouterd ${router_SOURCES}) -target_link_libraries(qdrouterd qpid-dispatch) +add_executable(qdrouterd ${router_SOURCES} $<TARGET_OBJECTS:qpid-dispatch>) +target_link_libraries(qdrouterd qpid-dispatch-libraries) install(TARGETS qdrouterd RUNTIME DESTINATION sbin) diff --git a/run.py.in b/run.py.in index 9b2f744..fe54355 100755 --- a/run.py.in +++ b/run.py.in @@ -86,7 +86,6 @@ env_vars = { 'SOURCE_DIR': "${CMAKE_SOURCE_DIR}", 'BUILD_DIR': "${CMAKE_BINARY_DIR}", 'QPID_DISPATCH_HOME': "${CMAKE_SOURCE_DIR}", - 'QPID_DISPATCH_LIB': "${CMAKE_BINARY_DIR}/src/${QPID_DISPATCH_LIB}", 'QPID_DISPATCH_RUNNER': qdrouterd_runner, 'MALLOC_CHECK_': "3", # 3 = print error and abort 'MALLOC_PERTURB_': "153", # 153 = 0x99 freed memory pattern diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 724a877..2ebb4f8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -164,24 +164,14 @@ endif (CMAKE_C_COMPILER_ID STREQUAL "GNU") if ((DEFINED ASAN_LIBRARY) OR (DEFINED UBSAN_LIBRARY) OR (DEFINED TSAN_LIBRARY)) set(USING_SANITIZERS TRUE) endif() -if (APPLE) - # DISPATCH-1384 - for macOS use flat_namespace instead of 2 level - # namespace (acts more like linux) - set(QPID_DISPATCH_LIB_LINK_FLAGS "-Wl,-flat_namespace ${QPID_DISPATCH_LIB_LINK_FLAGS}") -elseif(CMAKE_C_COMPILER_ID MATCHES "Clang" AND USING_SANITIZERS) - # https://github.com/google/sanitizers/issues/380 - can't enable error on - # undefined symbols when linking sanitizers with Clang -else() - set(QPID_DISPATCH_LIB_LINK_FLAGS "-Wl,-z,defs ${QPID_DISPATCH_LIB_LINK_FLAGS}") -endif() -add_library(qpid-dispatch SHARED ${qpid_dispatch_SOURCES}) +add_library(qpid-dispatch OBJECT ${qpid_dispatch_SOURCES}) target_include_directories(qpid-dispatch PRIVATE ${qpid_dispatch_INCLUDES}) -target_link_libraries(qpid-dispatch ${qpid_dispatch_LIBRARIES}) -set_target_properties(qpid-dispatch PROPERTIES - LINK_FLAGS "${QPID_DISPATCH_LIB_LINK_FLAGS}") -install(TARGETS qpid-dispatch - LIBRARY DESTINATION ${QPID_DISPATCH_HOME}) + +# Workaround. CMake < 3.12 does not allow using object libraries in target_link_libraries; +# `ar` on macOS refuses to produce a static library consisting of /dev/null as the only source file. +add_library(qpid-dispatch-libraries STATIC empty.c) +target_link_libraries(qpid-dispatch-libraries ${qpid_dispatch_LIBRARIES}) # check for various function availability check_symbol_exists(getrlimit sys/resource.h QD_HAVE_GETRLIMIT) diff --git a/src/config.h.in b/src/config.h.in index 21ea9e1..f558215 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -18,7 +18,6 @@ */ #define QPID_DISPATCH_VERSION "${QPID_DISPATCH_VERSION}" -#define QPID_DISPATCH_LIB "$<$<BOOL:${APPLE}>:@rpath/>$<TARGET_FILE_NAME:qpid-dispatch>" #define QPID_CONSOLE_STAND_ALONE_INSTALL_DIR "${CONSOLE_STAND_ALONE_INSTALL_DIR}" #cmakedefine01 QD_MEMORY_STATS #cmakedefine01 QD_HAVE_GETRLIMIT diff --git a/src/dispatch.c b/src/dispatch.c index ddb3eb5..00b1718 100644 --- a/src/dispatch.c +++ b/src/dispatch.c @@ -122,9 +122,10 @@ STATIC_ASSERT(sizeof(long) >= sizeof(void*), pointer_is_bigger_than_long); qd_error_t qd_dispatch_load_config(qd_dispatch_t *qd, const char *config_path) { - qd->dl_handle = dlopen(QPID_DISPATCH_LIB, RTLD_LAZY | RTLD_NOLOAD); + // `dlopen(NULL, ...)` opens the current executable; qdrouterd used to dlopen libqpid-dispatch.so here before + qd->dl_handle = dlopen(NULL, RTLD_LAZY | RTLD_NOLOAD); if (!qd->dl_handle) - return qd_error(QD_ERROR_RUNTIME, "Cannot locate library %s", QPID_DISPATCH_LIB); + return qd_error(QD_ERROR_RUNTIME, "Failed to dlopen the current executable"); qd_python_lock_state_t lock_state = qd_python_lock(); PyObject *module = PyImport_ImportModule("qpid_dispatch_internal.management.config"); diff --git a/src/config.h.in b/src/empty.c similarity index 73% copy from src/config.h.in copy to src/empty.c index 21ea9e1..67ab2bf 100644 --- a/src/config.h.in +++ b/src/empty.c @@ -17,8 +17,5 @@ * under the License. */ -#define QPID_DISPATCH_VERSION "${QPID_DISPATCH_VERSION}" -#define QPID_DISPATCH_LIB "$<$<BOOL:${APPLE}>:@rpath/>$<TARGET_FILE_NAME:qpid-dispatch>" -#define QPID_CONSOLE_STAND_ALONE_INSTALL_DIR "${CONSOLE_STAND_ALONE_INSTALL_DIR}" -#cmakedefine01 QD_MEMORY_STATS -#cmakedefine01 QD_HAVE_GETRLIMIT +/// Workaround. Some C compilers raise warning when asked to compile an empty file. +typedef int qd_make_this_translation_unit_not_be_empty; diff --git a/src/server.c b/src/server.c index b758d72..4910f37 100644 --- a/src/server.c +++ b/src/server.c @@ -1738,7 +1738,7 @@ void qd_connector_decref(qd_connector_t* connector) } } -__attribute__((noinline)) // permit replacement by dummy implementation in unit_tests +__attribute__((weak)) // permit replacement by dummy implementation in unit_tests void qd_server_timeout(qd_server_t *server, qd_duration_t duration) { pn_proactor_set_timeout(server->proactor, duration); } diff --git a/src/timer.c b/src/timer.c index 71698d1..c87e0f2 100644 --- a/src/timer.c +++ b/src/timer.c @@ -202,7 +202,7 @@ void qd_timer_free(qd_timer_t *timer) } -__attribute__((noinline)) // permit replacement by dummy implementation in unit_tests +__attribute__((weak)) // permit replacement by dummy implementation in unit_tests qd_timestamp_t qd_timer_now() { struct timespec tv; @@ -210,7 +210,6 @@ qd_timestamp_t qd_timer_now() return ((qd_timestamp_t)tv.tv_sec) * 1000 + tv.tv_nsec / 1000000; } - void qd_timer_schedule(qd_timer_t *timer, qd_duration_t duration) { sys_mutex_lock(lock); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5aec28d..ef6193d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -40,8 +40,8 @@ set(unit_test_SOURCES thread_test.c ) -add_executable(unit_tests ${unit_test_SOURCES}) -target_link_libraries(unit_tests qpid-dispatch) +add_executable(unit_tests ${unit_test_SOURCES} $<TARGET_OBJECTS:qpid-dispatch>) +target_link_libraries(unit_tests qpid-dispatch-libraries) set(unit_test_size_SOURCES field_test.c @@ -51,11 +51,11 @@ set(unit_test_size_SOURCES run_unit_tests_size.c ) -add_executable(unit_tests_size ${unit_test_size_SOURCES}) -target_link_libraries(unit_tests_size qpid-dispatch) +add_executable(unit_tests_size ${unit_test_size_SOURCES} $<TARGET_OBJECTS:qpid-dispatch>) +target_link_libraries(unit_tests_size qpid-dispatch-libraries) -add_executable(test-sender test-sender.c) -target_link_libraries(test-sender ${Proton_LIBRARIES} qpid-dispatch) +add_executable(test-sender test-sender.c $<TARGET_OBJECTS:qpid-dispatch>) +target_link_libraries(test-sender ${Proton_LIBRARIES} qpid-dispatch-libraries) add_executable(test-receiver test-receiver.c) target_link_libraries(test-receiver ${Proton_LIBRARIES}) @@ -63,8 +63,8 @@ target_link_libraries(test-receiver ${Proton_LIBRARIES}) add_executable(clogger clogger.c) target_link_libraries(clogger ${Proton_LIBRARIES}) -add_executable(threaded_timer_test threaded_timer_test.c) -target_link_libraries(threaded_timer_test qpid-dispatch) +add_executable(threaded_timer_test threaded_timer_test.c $<TARGET_OBJECTS:qpid-dispatch>) +target_link_libraries(threaded_timer_test qpid-dispatch-libraries) # Bubblewrap is an unprivileged sandboxing tool for Linux. Setting --unshare-net allows # running tests in parallel (the ctest -j option) without port clashes diff --git a/tests/c_unittests/CMakeLists.txt b/tests/c_unittests/CMakeLists.txt index deb74c5..c12a923 100644 --- a/tests/c_unittests/CMakeLists.txt +++ b/tests/c_unittests/CMakeLists.txt @@ -22,8 +22,8 @@ file(GLOB unittest_SOURCES ) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_STANDARD_FLAGS} ${SANITIZE_FLAGS}") -add_executable(c_unittests ${unittest_SOURCES}) -target_link_libraries(c_unittests pthread qpid-dispatch) +add_executable(c_unittests ${unittest_SOURCES} $<TARGET_OBJECTS:qpid-dispatch>) +target_link_libraries(c_unittests pthread qpid-dispatch-libraries) add_test( NAME c_unittests --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org