From 3e497170b78e5eef3b481193879f95098414dee5 Mon Sep 17 00:00:00 2001 From: Zhihua Lai Date: Wed, 2 Jul 2025 13:56:19 +0100 Subject: [PATCH 1/4] Revert "Revert "Enable Building Both libjbpf.a and libjbpf.so with cmake option -DJBPF_STATIC=Both"" This reverts commit 955049af95bac1f393010268c86ec11e45df4dd9. --- .../workflows/docker-build-and-test-arm.yaml | 4 + .github/workflows/docker_build_and_test.yaml | 4 + CMakeLists.txt | 13 +- docs/integrate_lib.md | 4 +- helper_build_files/build_utils.sh | 8 +- helper_build_files/test_build_utils.sh | 7 +- jbpf_tests/CMakeLists.txt | 1 + jbpf_tests/unit_tests/CMakeLists.txt | 3 +- jbpf_tests/unit_tests/bitmap/CMakeLists.txt | 7 +- src/core/CMakeLists.txt | 151 ++++++++++-------- 10 files changed, 127 insertions(+), 75 deletions(-) diff --git a/.github/workflows/docker-build-and-test-arm.yaml b/.github/workflows/docker-build-and-test-arm.yaml index 982da470..a95252db 100644 --- a/.github/workflows/docker-build-and-test-arm.yaml +++ b/.github/workflows/docker-build-and-test-arm.yaml @@ -112,6 +112,10 @@ jobs: test5) echo "staticBuildParam=-e JBPF_STATIC=1 -e JBPF_EXPERIMENTAL_FEATURES=1" >> "$GITHUB_ENV"; echo "sanitizerBuildParam=-e SANITIZER=1" >> "$GITHUB_ENV";; test6) echo "staticBuildParam=" >> "$GITHUB_ENV"; echo "sanitizerBuildParam=-e JBPF_EXPERIMENTAL_FEATURES=1" >> "$GITHUB_ENV";; test7) echo "staticBuildParam=-e JBPF_STATIC=1 -e JBPF_EXPERIMENTAL_FEATURES=1" >> "$GITHUB_ENV"; echo "sanitizerBuildParam=" >> "$GITHUB_ENV";; + test8) echo "staticBuildParam=-e JBPF_STATIC=2 -e JBPF_EXPERIMENTAL_FEATURES=1" >> "$GITHUB_ENV"; echo "sanitizerBuildParam=" >> "$GITHUB_ENV";; + test9) echo "staticBuildParam=-e JBPF_STATIC=2" >> "$GITHUB_ENV"; echo "sanitizerBuildParam=" >> "$GITHUB_ENV";; + test10) echo "staticBuildParam=-e JBPF_STATIC=2 -e JBPF_EXPERIMENTAL_FEATURES=1" >> "$GITHUB_ENV"; echo "sanitizerBuildParam=-e SANITIZER=1" >> "$GITHUB_ENV";; + test11) echo "staticBuildParam=-e JBPF_STATIC=2" >> "$GITHUB_ENV"; echo "sanitizerBuildParam=-e SANITIZER=1" >> "$GITHUB_ENV";; esac - name: Display Build Parameters diff --git a/.github/workflows/docker_build_and_test.yaml b/.github/workflows/docker_build_and_test.yaml index dbdf1898..e168aee1 100644 --- a/.github/workflows/docker_build_and_test.yaml +++ b/.github/workflows/docker_build_and_test.yaml @@ -67,6 +67,10 @@ jobs: test5) echo "staticBuildParam=-e JBPF_STATIC=1 -e JBPF_EXPERIMENTAL_FEATURES=1" >> "$GITHUB_ENV"; echo "sanitizerBuildParam=-e SANITIZER=1" >> "$GITHUB_ENV";; test6) echo "staticBuildParam=" >> "$GITHUB_ENV"; echo "sanitizerBuildParam=-e JBPF_EXPERIMENTAL_FEATURES=1" >> "$GITHUB_ENV";; test7) echo "staticBuildParam=-e JBPF_STATIC=1 -e JBPF_EXPERIMENTAL_FEATURES=1" >> "$GITHUB_ENV"; echo "sanitizerBuildParam=" >> "$GITHUB_ENV";; + test8) echo "staticBuildParam=-e JBPF_STATIC=2 -e JBPF_EXPERIMENTAL_FEATURES=1" >> "$GITHUB_ENV"; echo "sanitizerBuildParam=" >> "$GITHUB_ENV";; + test9) echo "staticBuildParam=-e JBPF_STATIC=2" >> "$GITHUB_ENV"; echo "sanitizerBuildParam=" >> "$GITHUB_ENV";; + test10) echo "staticBuildParam=-e JBPF_STATIC=2 -e JBPF_EXPERIMENTAL_FEATURES=1" >> "$GITHUB_ENV"; echo "sanitizerBuildParam=-e SANITIZER=1" >> "$GITHUB_ENV";; + test11) echo "staticBuildParam=-e JBPF_STATIC=2" >> "$GITHUB_ENV"; echo "sanitizerBuildParam=-e SANITIZER=1" >> "$GITHUB_ENV";; esac - name: Display Build Parameters diff --git a/CMakeLists.txt b/CMakeLists.txt index 8cf818fe..f5055bc4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,12 +9,17 @@ option(USE_JBPF_PERF_OPT "Assume CPU affinity when running jbpf hooks and use rd option(USE_JBPF_PRINTF_HELPER "Enable printing from codelets using jbpf_printf_debug() helper function" ON) option(JBPF_THREADS_LARGE "Allow more threads to be registered by jbpf and the IO lib" OFF) option(ENABLE_POISONING "Enable ASAN poisoning. Should not be used for IPC mode tests and must be used in conjunction with ASAN" OFF) -option(JBPF_STATIC "Build jbpf as static library" OFF) option(JBPF_EXPERIMENTAL_FEATURES "Enable experimental features of jbpf" OFF) option(CLANG_FORMAT_CHECK "Enable clang-format check" OFF) option(CPP_CHECK "Enable cppcheck" OFF) option(BUILD_TESTING "Enable tests" ON) +# Define the JBPF_STATIC option with three states: ON, OFF, BOTH +# Default is BOTH, which means both static and shared libraries will be built +set(JBPF_STATIC "BOTH" CACHE STRING "Build jbpf as static library: ON, OFF, or BOTH") +set_property(CACHE JBPF_STATIC PROPERTY STRINGS ON OFF BOTH) +string(TOUPPER "${JBPF_STATIC}" JBPF_STATIC_OPTION_UPPER) + set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) @@ -61,9 +66,9 @@ if(JBPF_THREADS_LARGE) add_definitions(-DJBPF_MAX_NUM_REG_THREADS=256) endif(JBPF_THREADS_LARGE) -if(NOT JBPF_STATIC) - add_definitions(-DJBPF_SHARED_LIB) -endif(NOT JBPF_STATIC) +if(JBPF_STATIC_OPTION_UPPER STREQUAL "OFF") + add_definitions(-DJBPF_SHARED_LIB) +endif() # To build static library on ARM, disable out-of-line helpers for atomics if ((JBPF_STATIC) AND (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")) diff --git a/docs/integrate_lib.md b/docs/integrate_lib.md index 4bad5f68..d5159a67 100644 --- a/docs/integrate_lib.md +++ b/docs/integrate_lib.md @@ -36,9 +36,9 @@ sudo -E docker run -v $DEST_PATH:/jbpf_out_lib \ The `$DEST_PATH` should be set to the absolute path of the directory where you want the output to be stored. ### Available Build Options: -When building the library, you can pass various options using the -e OPTION_NAME={0,1} format. Here are some available options: +When building the library, you can pass various options using the -e OPTION_NAME={0,1} format where 0 is disabled and 1 is enabled. Here are some available options: -* JBPF_STATIC - Build jbpf as a static library (**default: disabled**) +* JBPF_STATIC - Build jbpf as a static library. By default this is set to value 2 which means to build the jbpf in both `libjbpf.so` (when set to 0) and `libjbpf.a` (when set to 1). * USE_NATIVE - Enable/disable `-march=native` compilation flag (**default: enabled**) * USE_JBPF_PERF_OPT - Performance optimizations that assume threads calling jbpf codelets are pinned to a certain core (**default: enabled**) * USE_JBPF_PRINTF_HELPER - Disable the use of the helper function jbpf_printf_debug() (**default: enabled**) diff --git a/helper_build_files/build_utils.sh b/helper_build_files/build_utils.sh index 3cd7d24e..0abd6c94 100644 --- a/helper_build_files/build_utils.sh +++ b/helper_build_files/build_utils.sh @@ -24,10 +24,16 @@ get_flags() { if [[ "$JBPF_STATIC" == "1" ]]; then OUTPUT="$OUTPUT Building jbpf as a static library\n" FLAGS="$FLAGS -DJBPF_STATIC=on" - else + fi + if [[ "$JBPF_STATIC" == "0" ]]; then OUTPUT="$OUTPUT Building jbpf as a dynamic library\n" FLAGS="$FLAGS -DJBPF_STATIC=off" fi + if [[ "$JBPF_STATIC" == "2" || "$JBPF_STATIC" == "" ]]; then + OUTPUT="$OUTPUT Building jbpf as a both shared and static libraries.\n" + FLAGS="$FLAGS -DJBPF_STATIC=both" + fi + if [[ "$USE_NATIVE" == "1" || "$USE_NATIVE" == "" ]]; then OUTPUT="$OUTPUT Enabling flag -march=native\n" FLAGS="$FLAGS -DUSE_NATIVE=on" diff --git a/helper_build_files/test_build_utils.sh b/helper_build_files/test_build_utils.sh index d8f4c852..5f70234c 100755 --- a/helper_build_files/test_build_utils.sh +++ b/helper_build_files/test_build_utils.sh @@ -91,8 +91,13 @@ if ! test_flags "-DJBPF_STATIC=off" "When JBPF_STATIC=0 flags should contain -DJ exit 1 fi +JBPF_STATIC=2 +if ! test_flags "-DJBPF_STATIC=both" "When JBPF_STATIC=2 flags should contain -DJBPF_STATIC=both"; then + exit 1 +fi + JBPF_STATIC= -if ! test_flags "-DJBPF_STATIC=off" "When JBPF_STATIC is unset flags should contain -DJBPF_STATIC=off"; then +if ! test_flags "-DJBPF_STATIC=both" "When JBPF_STATIC is unset flags should contain -DJBPF_STATIC=both"; then exit 1 fi diff --git a/jbpf_tests/CMakeLists.txt b/jbpf_tests/CMakeLists.txt index 862d5e16..ce0c5adf 100644 --- a/jbpf_tests/CMakeLists.txt +++ b/jbpf_tests/CMakeLists.txt @@ -27,3 +27,4 @@ add_subdirectory(stress_tests) add_subdirectory(concurrency) set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) +set(JBPF_STATIC_OPTION_UPPER ${JBPF_STATIC_OPTION_UPPER} PARENT_SCOPE) \ No newline at end of file diff --git a/jbpf_tests/unit_tests/CMakeLists.txt b/jbpf_tests/unit_tests/CMakeLists.txt index 696c8600..32902587 100644 --- a/jbpf_tests/unit_tests/CMakeLists.txt +++ b/jbpf_tests/unit_tests/CMakeLists.txt @@ -8,4 +8,5 @@ add_subdirectory(io_mem) add_subdirectory(array) add_subdirectory(helper_functions) add_subdirectory(hashmap) -set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) \ No newline at end of file +set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) +set(JBPF_STATIC_OPTION_UPPER ${JBPF_STATIC_OPTION_UPPER} PARENT_SCOPE) \ No newline at end of file diff --git a/jbpf_tests/unit_tests/bitmap/CMakeLists.txt b/jbpf_tests/unit_tests/bitmap/CMakeLists.txt index d600cc2c..2c5cb26a 100644 --- a/jbpf_tests/unit_tests/bitmap/CMakeLists.txt +++ b/jbpf_tests/unit_tests/bitmap/CMakeLists.txt @@ -4,10 +4,13 @@ set(JBPF_BITMAP_TEST jbpf_bitmap_test) set(JBPF_BITMAP_TESTS_SOURCE jbpf_bitmap_test.c ${TESTS_COMMON}/jbpf_test_lib.c) add_executable(${JBPF_BITMAP_TEST} ${JBPF_BITMAP_TESTS_SOURCE}) -if(JBPF_STATIC) +set(JBPF_STATIC_OPTION_UPPER ${JBPF_STATIC_OPTION_UPPER} PARENT_SCOPE) +if(JBPF_STATIC_OPTION_UPPER STREQUAL "ON") target_link_libraries(${JBPF_BITMAP_TEST} PUBLIC jbpf::core_lib jbpf::logger_lib jbpf::mem_mgmt_lib) -else() +elseif(JBPF_STATIC_OPTION_UPPER STREQUAL "OFF") target_link_libraries(${JBPF_BITMAP_TEST} PUBLIC jbpf::core_lib) +elseif(JBPF_STATIC_OPTION_UPPER STREQUAL "BOTH") + target_link_libraries(${JBPF_BITMAP_TEST} PUBLIC jbpf::core_lib jbpf::logger_lib jbpf::mem_mgmt_lib) endif() target_include_directories(${JBPF_BITMAP_TEST} PUBLIC ${JBPF_LIB_HEADER_FILES} ${TEST_HEADER_FILES} ${JBPF_LOGGER_HEADERS}) add_test(NAME unit_tests/${JBPF_BITMAP_TEST} COMMAND ${JBPF_BITMAP_TEST}) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 16fee413..bcae509b 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -4,82 +4,105 @@ cmake_minimum_required(VERSION 3.16) project(jbpf_core) set(JBPF_LIB jbpf) - set(JBPF_LIB_DIR ${PROJECT_SOURCE_DIR}) set(JBPF_LIB_SOURCES ${JBPF_LIB_DIR}/jbpf_helper_impl.c - ${JBPF_LIB_DIR}/jbpf_bpf_array.c - ${JBPF_LIB_DIR}/jbpf_bpf_hashmap.c - ${JBPF_LIB_DIR}/jbpf_bpf_spsc_hashmap.c - ${JBPF_LIB_DIR}/jbpf.c - ${JBPF_LIB_DIR}/jbpf_hook.c - ${JBPF_LIB_DIR}/jbpf_perf.c - ${JBPF_LIB_DIR}/jbpf_lookup3.c - ${JBPF_LIB_DIR}/jbpf_memory.c - ${JBPF_LIB_DIR}/jbpf_utils.c) + ${JBPF_LIB_DIR}/jbpf_bpf_array.c + ${JBPF_LIB_DIR}/jbpf_bpf_hashmap.c + ${JBPF_LIB_DIR}/jbpf_bpf_spsc_hashmap.c + ${JBPF_LIB_DIR}/jbpf.c + ${JBPF_LIB_DIR}/jbpf_hook.c + ${JBPF_LIB_DIR}/jbpf_perf.c + ${JBPF_LIB_DIR}/jbpf_lookup3.c + ${JBPF_LIB_DIR}/jbpf_memory.c + ${JBPF_LIB_DIR}/jbpf_utils.c) set(JBPF_LIB_HEADER_FILES ${PROJECT_SOURCE_DIR} PARENT_SCOPE) +set(JBPF_STATIC_OPTION_UPPER ${JBPF_STATIC_OPTION_UPPER} PARENT_SCOPE) -if(JBPF_STATIC) - add_library(${JBPF_LIB} ${JBPF_LIB_SOURCES} ${JBPF_LIB_HEADER_FILES} - $ - $ - $ - $) - - target_link_libraries(${JBPF_LIB} libubpf - ${JBPF_CK_STATIC_LIB} - mimalloc-static - pthread - dl - rt) - -else(JBPF_STATIC) - add_library(${JBPF_LIB} SHARED ${JBPF_LIB_SOURCES} ${JBPF_LIB_HEADER_FILES}) - set_target_properties(${JBPF_LIB} PROPERTIES LINK_FLAGS "-Wl,-z,now -Wl,--version-script=${JBPF_HELPER_BUILD_FILES}/symver.map" ) - target_link_libraries(${JBPF_LIB} PUBLIC jbpf::lcm_ipc_lib +function(create_jbpf_library LIB_NAME LIBRARY_TYPE) + if(LIBRARY_TYPE STREQUAL "static") + add_library(${LIB_NAME} STATIC ${JBPF_LIB_SOURCES} ${JBPF_LIB_HEADER_FILES} + $ + $ + $ + $) + target_link_libraries(${LIB_NAME} libubpf + ${JBPF_CK_STATIC_LIB} + mimalloc-static + pthread + dl + rt) + elseif(LIBRARY_TYPE STREQUAL "shared") + add_library(${LIB_NAME} SHARED ${JBPF_LIB_SOURCES} ${JBPF_LIB_HEADER_FILES}) + target_link_libraries(${LIB_NAME} PUBLIC jbpf::lcm_ipc_lib jbpf::logger_lib jbpf::io_lib jbpf::mem_mgmt_lib - libubpf - ${JBPF_CK_STATIC_LIB} + libubpf + ${JBPF_CK_STATIC_LIB} mimalloc-static - pthread - dl + pthread + dl rt) - target_compile_options(${JBPF_LIB} PUBLIC -flto) -endif(JBPF_STATIC) -add_library(jbpf::core_lib ALIAS ${JBPF_LIB}) -target_include_directories(${JBPF_LIB} PUBLIC ${JBPF_LIB_HEADER_FILES} - ${JBPF_COMMON_HEADERS} - ${JBPF_IO_HEADER_FILES} - ${JBPF_LCM_IPC_HEADER_FILES} - ${JBPF_LOGGER_HEADERS} - ${JBPF_CK_INCLUDES}) + target_compile_options(${LIB_NAME} PUBLIC -flto) + endif() + + set_target_properties(${LIB_NAME} PROPERTIES + LINK_FLAGS "-Wl,-z,now -Wl,--version-script=${JBPF_HELPER_BUILD_FILES}/symver.map" + ARCHIVE_OUTPUT_DIRECTORY "${OUTPUT_DIR}/lib" + LIBRARY_OUTPUT_DIRECTORY "${OUTPUT_DIR}/lib" + ) + add_library(jbpf::core_lib ALIAS ${LIB_NAME}) + + target_include_directories(${LIB_NAME} PUBLIC ${JBPF_LIB_HEADER_FILES} + ${JBPF_COMMON_HEADERS} + ${JBPF_IO_HEADER_FILES} + ${JBPF_LCM_IPC_HEADER_FILES} + ${JBPF_LOGGER_HEADERS} + ${JBPF_CK_INCLUDES}) + + add_dependencies(${LIB_NAME} jbpf_libck libubpf generate_jbpf_lib_version) + add_clang_format_check(${LIB_NAME} ${JBPF_LIB_SOURCES}) + add_cppcheck(${LIB_NAME} ${JBPF_LIB_SOURCES}) + + add_custom_command(TARGET ${LIB_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory ${OUTPUT_DIR}/inc/ + COMMAND ${CMAKE_COMMAND} -E copy ${JBPF_LIB_DIR}/jbpf.h ${OUTPUT_DIR}/inc/ + COMMAND ${CMAKE_COMMAND} -E copy ${JBPF_LIB_DIR}/jbpf_device_defs.h ${OUTPUT_DIR}/inc/ + COMMAND ${CMAKE_COMMAND} -E copy ${JBPF_LIB_DIR}/jbpf_config.h ${OUTPUT_DIR}/inc/ + COMMAND ${CMAKE_COMMAND} -E copy ${JBPF_LIB_DIR}/jbpf_hook_defs.h ${OUTPUT_DIR}/inc/ + COMMAND ${CMAKE_COMMAND} -E copy ${JBPF_LIB_DIR}/jbpf_hook.h ${OUTPUT_DIR}/inc/ + COMMAND ${CMAKE_COMMAND} -E copy ${JBPF_LIB_DIR}/jbpf_perf_ext.h ${OUTPUT_DIR}/inc/ + COMMAND ${CMAKE_COMMAND} -E copy ${JBPF_LIB_DIR}/jbpf_perf.h ${OUTPUT_DIR}/inc/ + COMMAND ${CMAKE_COMMAND} -E copy ${JBPF_LIB_DIR}/jbpf_utils.h ${OUTPUT_DIR}/inc/ + COMMAND ${CMAKE_COMMAND} -E copy ${JBPF_LIB_DIR}/jbpf_helper.h ${OUTPUT_DIR}/inc/ + COMMAND ${CMAKE_COMMAND} -E copy ${JBPF_LIB_DIR}/jbpf_helper_api_defs.h ${OUTPUT_DIR}/inc/ + COMMAND ${CMAKE_COMMAND} -E copy_directory ${JBPF_CK_INCLUDES} ${OUTPUT_DIR}/inc/ + ) + + add_dependencies(${LIB_NAME} copy-common-headers) +endfunction() -add_dependencies(${JBPF_LIB} jbpf_libck libubpf generate_jbpf_lib_version) -add_clang_format_check(${JBPF_LIB} ${JBPF_LIB_SOURCES}) -add_cppcheck(${JBPF_LIB} ${JBPF_LIB_SOURCES}) +message(STATUS "JBPF_STATIC_OPTION_UPPER: ${JBPF_STATIC_OPTION_UPPER}") -set_target_properties(${JBPF_LIB} - PROPERTIES - ARCHIVE_OUTPUT_DIRECTORY "${OUTPUT_DIR}/lib" - LIBRARY_OUTPUT_DIRECTORY "${OUTPUT_DIR}/lib" -) +if(JBPF_STATIC_OPTION_UPPER STREQUAL "ON") + message(STATUS "Building static library i.e. lib${JBPF_LIB}.a") + create_jbpf_library(${JBPF_LIB} "static") + add_library(jbpf::core_lib ALIAS ${JBPF_LIB}) +elseif(JBPF_STATIC_OPTION_UPPER STREQUAL "OFF") + message(STATUS "Building shared library i.e. lib${JBPF_LIB}.so") + create_jbpf_library(${JBPF_LIB} "shared") +elseif(JBPF_STATIC_OPTION_UPPER STREQUAL "BOTH") + message(STATUS "Building both static and shared libraries i.e. lib${JBPF_LIB}.a and lib${JBPF_LIB}.so") + create_jbpf_library(${JBPF_LIB} "static") + create_jbpf_library(${JBPF_LIB}_shared "shared") -add_custom_command(TARGET ${JBPF_LIB} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E make_directory ${OUTPUT_DIR}/inc/ - COMMAND ${CMAKE_COMMAND} -E copy ${JBPF_LIB_DIR}/jbpf.h ${OUTPUT_DIR}/inc/ - COMMAND ${CMAKE_COMMAND} -E copy ${JBPF_LIB_DIR}/jbpf_device_defs.h ${OUTPUT_DIR}/inc/ - COMMAND ${CMAKE_COMMAND} -E copy ${JBPF_LIB_DIR}/jbpf_config.h ${OUTPUT_DIR}/inc/ - COMMAND ${CMAKE_COMMAND} -E copy ${JBPF_LIB_DIR}/jbpf_hook_defs.h ${OUTPUT_DIR}/inc/ - COMMAND ${CMAKE_COMMAND} -E copy ${JBPF_LIB_DIR}/jbpf_hook.h ${OUTPUT_DIR}/inc/ - COMMAND ${CMAKE_COMMAND} -E copy ${JBPF_LIB_DIR}/jbpf_perf_ext.h ${OUTPUT_DIR}/inc/ - COMMAND ${CMAKE_COMMAND} -E copy ${JBPF_LIB_DIR}/jbpf_perf.h ${OUTPUT_DIR}/inc/ - COMMAND ${CMAKE_COMMAND} -E copy ${JBPF_LIB_DIR}/jbpf_utils.h ${OUTPUT_DIR}/inc/ - COMMAND ${CMAKE_COMMAND} -E copy ${JBPF_LIB_DIR}/jbpf_helper.h ${OUTPUT_DIR}/inc/ - COMMAND ${CMAKE_COMMAND} -E copy ${JBPF_LIB_DIR}/jbpf_helper_api_defs.h ${OUTPUT_DIR}/inc/ - COMMAND ${CMAKE_COMMAND} -E copy_directory ${JBPF_CK_INCLUDES} ${OUTPUT_DIR}/inc/ -) + ## add JBPF_SHARED_LIB definition to shared library + target_compile_definitions(${JBPF_LIB}_shared PRIVATE JBPF_SHARED_LIB) -add_dependencies(${JBPF_LIB} copy-common-headers) \ No newline at end of file + ## move libjbpf_shared.so to libjbpf.so + add_custom_command(TARGET ${JBPF_LIB}_shared POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ ${OUTPUT_DIR}/lib/lib${JBPF_LIB}.so + ) +endif() From b15dd0306b8be9ce1217f9de84411c36699de2d3 Mon Sep 17 00:00:00 2001 From: Zhihua Lai <92519564+doctorlai-msrc@users.noreply.github.com> Date: Wed, 2 Jul 2025 17:32:40 +0100 Subject: [PATCH 2/4] syncs from the dev branch to the main branch (#122) * Adding a emulator * Add Python/ctypesgen dependencies for emulator * Add jbpf_agent_hooks.h and generate py * Add time helper functions * Test emulator * Add missing file * Add missing fields * Fix time event initialization * Refactor * Remove protobuf, update jbpf_stats_report.o * Add xran helper functions, and create random stream_id * Clang-format * Fix cppcheck issue * Refactor default values * Default num_codelet_descriptors to len(codelet_descriptors) * Enable ASAN in tests, ignore ODR, cleanup * Clangformat * Support custom helper functions and refactor * Fix clang-format * Move definitions above users include file * Remove XRAN * Add Custom init code * Add yaml_to_json, refactor * Fix path * Add debug option to emulator_utils.jbpf_handle_out_bufs * Match codelet_descriptor in yaml * Add missing define agent hooks * Revert * jbpf_handle_out_bufs should return how many messages that have been processed * Add some debug output when calling periodic_call and report_stats hook * Add a test to make sure the report_stats is actually called * Add comment * Clang-format -i * Add debug printf * Continued work * Add matching ck_epoch_end * Clang * Continued testing * Add more debugging * Clang * Debug * Debug print * Add more debugging message * More debugging * Add tests for report_stats and periodic_call, add debugging * Clang-format * Pipeline integration * simple_output2.o * Add missing files * Refactor & debug * COntinued work * Continued work * Revert and Cleanup * Revert * Fix * Ignore dynamic builds * Fix * Fix syntax * Fix syntax * Keep static mode only * Revert * Emulate time and add a test * Add test * Fix clang-format * Add missing file * Fix compilation under ubuntu20 * Init draft of adding both options * Fix * Pipeline * Move autogen wrappers * Fix cppcheck issue * Build both by default * Fix JBPF_SHARED_LIB * Fix build under ubuntu24.04 * Fix segfault at Static * Add emulator tests to github action, fix RELEASE * Typo * First round of addressing comments * Improve test description comments * Add some more doc * Add to ARM pipeline * Sync dev with main (#105) * Add helper function for fixed points (#71) * Add helper function for fixed points * Addressing the comments * Revert * Continued work * Fix the algorithms and tests * Minor tweaks * Cleanup * Avoid clang optimise the code * Fix implementations * Test fixed_to_float and fixed_to_double * Fix type * Add 2 more tests * Cleanup * Clang format inconsistent fix * Add more tests in the codelet * Increase MAX_NUM_HOOKS from 64 to 128 (#90) * Increase MAX_NUM_HOOKS from 64 to 96 * Increase MAX_NUM_HOOKS to 128 --------- Co-authored-by: Zhihua Lai <92519564+doctorlai-msrc@users.noreply.github.com> Co-authored-by: matthewbalkwill <93522480+matthewbalkwill@users.noreply.github.com> * Refactor docker files * Add to github actions * Add System Information * Merge and fix * Fix comments * Readme * More doc * Update docs * Move emulator tests to the end * Add debug messages * Add more debug * Update codelet to provide more information * Comment * Fix print error * Revert "Update codelet to provide more information" This reverts commit 95dc9e4db9ae44e5f0b715a29917cc5c3db73d77. * Fix segfault * Use smart ptr * Revert "Adding a emulator" * Revert "Enable Building Both libjbpf.a and libjbpf.so with cmake option -DJBPF_STATIC=Both" --------- Co-authored-by: Xenofon Foukas <137962+xfoukas@users.noreply.github.com> Co-authored-by: matthewbalkwill <93522480+matthewbalkwill@users.noreply.github.com> --- src/io/jbpf_io_channel.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/io/jbpf_io_channel.c b/src/io/jbpf_io_channel.c index 3956df90..20262de0 100644 --- a/src/io/jbpf_io_channel.c +++ b/src/io/jbpf_io_channel.c @@ -442,11 +442,9 @@ jbpf_io_destroy_out_channel(struct jbpf_io_channel_list* channel_list, struct jb ck_epoch_end(local_out_channel_list_epoch_record, NULL); ck_epoch_call(local_out_channel_list_epoch_record, &io_channel->epoch_entry, io_channel_destructor); ck_epoch_barrier(local_out_channel_list_epoch_record); - jbpf_logger( - JBPF_INFO, - "Barrier reached and channel %p was destroyed (stream id %s)\n", - io_channel, - io_channel->stream_id.id); + char sname[JBPF_IO_STREAM_ID_LEN * 3]; + _jbpf_io_tohex_str(io_channel->stream_id.id, JBPF_IO_STREAM_ID_LEN, sname, JBPF_IO_STREAM_ID_LEN * 3); + jbpf_logger(JBPF_INFO, "Barrier reached and channel %p was destroyed (stream id %s)\n", io_channel, sname); } void @@ -673,7 +671,9 @@ jbpf_io_channel_send_data(struct jbpf_io_channel* channel, void* data, size_t si jbpf_channel_buf_ptr data_buf = jbpf_io_channel_reserve_buf(channel); if (!data_buf) { - jbpf_logger(JBPF_ERROR, "Error reserving buffer for channel %s\n", channel->stream_id.id); + char sname[JBPF_IO_STREAM_ID_LEN * 3]; + _jbpf_io_tohex_str(channel->stream_id.id, JBPF_IO_STREAM_ID_LEN, sname, JBPF_IO_STREAM_ID_LEN * 3); + jbpf_logger(JBPF_ERROR, "Error reserving buffer for channel %s\n", sname); return -1; } memcpy(data_buf, data, size); From 50fd9ab5cc134bfe9e21ffbb2b182f9f88aee7bc Mon Sep 17 00:00:00 2001 From: Zhihua Lai Date: Fri, 21 Aug 2026 15:55:51 +0100 Subject: [PATCH 3/4] fix(build): address dual-library review findings Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- docs/integrate_lib.md | 4 ++-- helper_build_files/build_utils.sh | 2 +- src/core/CMakeLists.txt | 10 +++------- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/docs/integrate_lib.md b/docs/integrate_lib.md index d5159a67..95170366 100644 --- a/docs/integrate_lib.md +++ b/docs/integrate_lib.md @@ -36,9 +36,9 @@ sudo -E docker run -v $DEST_PATH:/jbpf_out_lib \ The `$DEST_PATH` should be set to the absolute path of the directory where you want the output to be stored. ### Available Build Options: -When building the library, you can pass various options using the -e OPTION_NAME={0,1} format where 0 is disabled and 1 is enabled. Here are some available options: +When building the library, pass options using the `-e OPTION_NAME=VALUE` format. Most options use `0` for disabled and `1` for enabled; `JBPF_STATIC` also accepts `2`. Here are some available options: -* JBPF_STATIC - Build jbpf as a static library. By default this is set to value 2 which means to build the jbpf in both `libjbpf.so` (when set to 0) and `libjbpf.a` (when set to 1). +* JBPF_STATIC - Select which library artifacts to build: `0` builds only `libjbpf.so`, `1` builds only `libjbpf.a`, and `2` builds both (**default: `2`**). * USE_NATIVE - Enable/disable `-march=native` compilation flag (**default: enabled**) * USE_JBPF_PERF_OPT - Performance optimizations that assume threads calling jbpf codelets are pinned to a certain core (**default: enabled**) * USE_JBPF_PRINTF_HELPER - Disable the use of the helper function jbpf_printf_debug() (**default: enabled**) diff --git a/helper_build_files/build_utils.sh b/helper_build_files/build_utils.sh index 0abd6c94..47f623d5 100644 --- a/helper_build_files/build_utils.sh +++ b/helper_build_files/build_utils.sh @@ -30,7 +30,7 @@ get_flags() { FLAGS="$FLAGS -DJBPF_STATIC=off" fi if [[ "$JBPF_STATIC" == "2" || "$JBPF_STATIC" == "" ]]; then - OUTPUT="$OUTPUT Building jbpf as a both shared and static libraries.\n" + OUTPUT="$OUTPUT Building jbpf as both shared and static libraries.\n" FLAGS="$FLAGS -DJBPF_STATIC=both" fi diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index bcae509b..40e1cac9 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -53,7 +53,6 @@ function(create_jbpf_library LIB_NAME LIBRARY_TYPE) ARCHIVE_OUTPUT_DIRECTORY "${OUTPUT_DIR}/lib" LIBRARY_OUTPUT_DIRECTORY "${OUTPUT_DIR}/lib" ) - add_library(jbpf::core_lib ALIAS ${LIB_NAME}) target_include_directories(${LIB_NAME} PUBLIC ${JBPF_LIB_HEADER_FILES} ${JBPF_COMMON_HEADERS} @@ -89,7 +88,6 @@ message(STATUS "JBPF_STATIC_OPTION_UPPER: ${JBPF_STATIC_OPTION_UPPER}") if(JBPF_STATIC_OPTION_UPPER STREQUAL "ON") message(STATUS "Building static library i.e. lib${JBPF_LIB}.a") create_jbpf_library(${JBPF_LIB} "static") - add_library(jbpf::core_lib ALIAS ${JBPF_LIB}) elseif(JBPF_STATIC_OPTION_UPPER STREQUAL "OFF") message(STATUS "Building shared library i.e. lib${JBPF_LIB}.so") create_jbpf_library(${JBPF_LIB} "shared") @@ -97,12 +95,10 @@ elseif(JBPF_STATIC_OPTION_UPPER STREQUAL "BOTH") message(STATUS "Building both static and shared libraries i.e. lib${JBPF_LIB}.a and lib${JBPF_LIB}.so") create_jbpf_library(${JBPF_LIB} "static") create_jbpf_library(${JBPF_LIB}_shared "shared") + set_target_properties(${JBPF_LIB}_shared PROPERTIES OUTPUT_NAME ${JBPF_LIB}) ## add JBPF_SHARED_LIB definition to shared library target_compile_definitions(${JBPF_LIB}_shared PRIVATE JBPF_SHARED_LIB) - - ## move libjbpf_shared.so to libjbpf.so - add_custom_command(TARGET ${JBPF_LIB}_shared POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ ${OUTPUT_DIR}/lib/lib${JBPF_LIB}.so - ) endif() + +add_library(jbpf::core_lib ALIAS ${JBPF_LIB}) From d53317619be7a31187a4b3844a63838198c38657 Mon Sep 17 00:00:00 2001 From: Zhihua Lai Date: Fri, 21 Aug 2026 17:26:52 +0100 Subject: [PATCH 4/4] fix(build): wait for shared library before examples --- examples/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 480ad3df..6c144e7e 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -6,4 +6,8 @@ add_custom_target(examples ALL add_dependencies(examples jbpf::core_lib) +if(TARGET jbpf_shared) + add_dependencies(examples jbpf_shared) +endif() + add_subdirectory(reverse_proxy)