Skip to content

Enable Building Both libjbpf.a and libjbpf.so with cmake option -DJBPF_STATIC=Both#124

Open
doctorlai-msrc wants to merge 3 commits into
devfrom
zhihua/cmake
Open

Enable Building Both libjbpf.a and libjbpf.so with cmake option -DJBPF_STATIC=Both#124
doctorlai-msrc wants to merge 3 commits into
devfrom
zhihua/cmake

Conversation

@doctorlai-msrc

Copy link
Copy Markdown
Collaborator

This PR changes the cmake option JBPF_STATIC to 3 states: On, Off and Both.
When set to Both, both the libjbpf.a and libjbpf.so will be built

Originally, this PR was in #22 it got merged by mistakes and reverted in #120 .
Thus, re-creating the PR.

@doctorlai-msrc doctorlai-msrc marked this pull request as ready for review July 11, 2025 09:09
@doctorlai-msrc doctorlai-msrc requested a review from Copilot June 30, 2026 22:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the build system to treat JBPF_STATIC as a tri-state CMake setting (ON, OFF, BOTH) so the project can build either a static lib, a shared lib, or both in one build.

Changes:

  • Convert JBPF_STATIC from a boolean option to a 3-value cache string (ON|OFF|BOTH) and thread the normalized value (JBPF_STATIC_OPTION_UPPER) through subdirectories.
  • Refactor core library CMake logic to support producing both libjbpf.a and a shared library in the same configuration.
  • Update Docker build scripts, tests, docs, and CI workflows to exercise/configure the new JBPF_STATIC=2 (“both”) behavior.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
CMakeLists.txt Defines tri-state JBPF_STATIC cache string and updates global JBPF_SHARED_LIB definition behavior.
src/core/CMakeLists.txt Refactors core library creation and adds BOTH mode to build static + shared artifacts.
jbpf_tests/CMakeLists.txt Propagates JBPF_STATIC_OPTION_UPPER to subdirectories for tests.
jbpf_tests/unit_tests/CMakeLists.txt Propagates JBPF_STATIC_OPTION_UPPER within unit test subdir tree.
jbpf_tests/unit_tests/bitmap/CMakeLists.txt Adjusts unit test linking based on ON/OFF/BOTH semantics.
helper_build_files/build_utils.sh Adds JBPF_STATIC=2 / unset handling to emit -DJBPF_STATIC=both.
helper_build_files/test_build_utils.sh Extends flag expectation tests for JBPF_STATIC=2 and new default behavior.
docs/integrate_lib.md Updates integration documentation to describe updated build option semantics.
.github/workflows/docker_build_and_test.yaml Adds new CI cases to run Docker build/test with JBPF_STATIC=2.
.github/workflows/docker-build-and-test-arm.yaml Adds new ARM CI cases to run Docker build/test with JBPF_STATIC=2.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/core/CMakeLists.txt
ARCHIVE_OUTPUT_DIRECTORY "${OUTPUT_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${OUTPUT_DIR}/lib"
)
add_library(jbpf::core_lib ALIAS ${LIB_NAME})
Comment thread src/core/CMakeLists.txt
Comment on lines +91 to +93
create_jbpf_library(${JBPF_LIB} "static")
add_library(jbpf::core_lib ALIAS ${JBPF_LIB})
elseif(JBPF_STATIC_OPTION_UPPER STREQUAL "OFF")
Comment thread src/core/CMakeLists.txt
Comment on lines +104 to +107
## move libjbpf_shared.so to libjbpf.so
add_custom_command(TARGET ${JBPF_LIB}_shared POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${JBPF_LIB}_shared> ${OUTPUT_DIR}/lib/lib${JBPF_LIB}.so
)
Comment thread docs/integrate_lib.md
Comment on lines +39 to +41
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).
Comment on lines +33 to +34
OUTPUT="$OUTPUT Building jbpf as a both shared and static libraries.\n"
FLAGS="$FLAGS -DJBPF_STATIC=both"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants