Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: use the system provided libmsgpack and libsqlite3 if found #9572

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pr-compile-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install -y curl gcc-7 g++-7 clang-6.0 libsystemd-dev gcovr libyaml-dev libluajit-5.1-dev \
libnghttp2-dev libjemalloc-dev
libnghttp2-dev libjemalloc-dev libsqlite3-dev
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the whole intention of this PR. Allowing to link fluent-bit against system libraries instead of build-int libraries. So adding this to the apt-get hook, ensures we test the libsqlite3 linking.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure but where do we test it?

My main query was we added it here but not the actual packaging build and not any of the other libraries in this PR so wanted to check why. Can we add a comment to indicate this was added specifically to test the linkage? Otherwise someone will remove it later or wonder why (probably me!).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test here is about this
"# Sanity check for compilation using system libraries"

But it's perhaps better to effective assert if these libs are used.

See the ldd ./bin/fluent-bit which gives something like:
(See https://github.com/fluent/fluent-bit/actions/runs/12705012946/job/35415319384)

Run ldd ./bin/fluent-bit
  ldd ./bin/fluent-bit
  shell: /usr/bin/bash -e {0}
	linux-vdso.so.1 (0x00007ffdc73ee000)
	libjemalloc.so.[2](https://github.com/fluent/fluent-bit/actions/runs/12705012946/job/35415319384#step:5:2) => /lib/x86_64-linux-gnu/libjemalloc.so.2 (0x00007f4fa96fc000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f4fa96d9000)
	libluajit-5.1.so.2 => /lib/x86_64-linux-gnu/libluajit-5.1.so.2 (0x00007f4fa965e000)
	libsqlite[3](https://github.com/fluent/fluent-bit/actions/runs/12705012946/job/35415319384#step:5:3).so.0 => /lib/x86_64-linux-gnu/libsqlite3.so.0 (0x00007f[4](https://github.com/fluent/fluent-bit/actions/runs/12705012946/job/35415319384#step:5:5)fa9535000)
	libnghttp2.so.14 => /lib/x86_64-linux-gnu/libnghttp2.so.14 (0x00007f4fa9[5](https://github.com/fluent/fluent-bit/actions/runs/12705012946/job/35415319384#step:5:6)0b000)
	libyaml-0.so.2 => /lib/x86_64-linux-gnu/libyaml-0.so.2 (0x00007f4fa94e9000)
	libsystemd.so.0 => /lib/x8[6](https://github.com/fluent/fluent-bit/actions/runs/12705012946/job/35415319384#step:5:7)_64-linux-gnu/libsystemd.so.0 (0x00007f4fa9438000)
	libssl.so.1.1 => /lib/x86_64-linux-gnu/libssl.so.1.1 (0x0000[7](https://github.com/fluent/fluent-bit/actions/runs/12705012946/job/35415319384#step:5:8)f4fa93a5000)
	libcrypto.so.1.1 => /lib/x86_64-linux-gnu/libcrypto.so.1.1 (0x00007f4fa90ce000)
	libz.so.1 => /lib/x[8](https://github.com/fluent/fluent-bit/actions/runs/12705012946/job/35415319384#step:5:9)6_64-linux-gnu/libz.so.1 (0x00007f4fa90b2000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f4fa8f63000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f4fa8f5d000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f4fa8f40000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4fa8d4e000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f4faab88000)
	libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f4fa8b6c000)
	librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f4fa8b62000)
	liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f4fa8b3[9](https://github.com/fluent/fluent-bit/actions/runs/12705012946/job/35415319384#step:5:10)000)
	liblz4.so.1 => /lib/x86_64-linux-gnu/liblz4.so.1 (0x00007f4fa8b18000)
	libgcrypt.so.20 => /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007f4fa89f8000)
	libgpg-error.so.0 => /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007f4fa89d5000)

So perhaps we should assert that libsqlite3 is in that list, together with the other tested libraries.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a commit to test it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah we can do that I think, sorry if I missed where it was being done but a comment saying "adding this to support using system libraries and verified here: xxx" would help.

We can then see why it should not be mirrored into the centos7 image used for building - which would not be obvious particularly next time we have to tweak deps on both.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated that last commit, with an extra step to make it clear that these packages are part of the test.

sudo ln -s /usr/bin/llvm-symbolizer-6.0 /usr/bin/llvm-symbolizer || true
mkdir -p /tmp/libbacktrace/build && \
curl -L https://github.com/ianlancetaylor/libbacktrace/archive/8602fda.tar.gz | \
Expand Down
28 changes: 22 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ option(FLB_PREFER_SYSTEM_LIB_CARES "Prefer the libcares system library"
option(FLB_PREFER_SYSTEM_LIB_JEMALLOC "Prefer the libjemalloc system library" ${FLB_PREFER_SYSTEM_LIBS})
option(FLB_PREFER_SYSTEM_LIB_KAFKA "Prefer the libkafka system library" ${FLB_PREFER_SYSTEM_LIBS})
option(FLB_PREFER_SYSTEM_LIB_LUAJIT "Prefer the libluajit system library" ${FLB_PREFER_SYSTEM_LIBS})
option(FLB_PREFER_SYSTEM_LIB_MSGPACK "Prefer the libmsgpack system library" ${FLB_PREFER_SYSTEM_LIBS})
option(FLB_PREFER_SYSTEM_LIB_NGHTTP2 "Prefer the libnghttp2 system library" ${FLB_PREFER_SYSTEM_LIBS})
option(FLB_PREFER_SYSTEM_LIB_SQLITE "Prefer the libsqlite3 system library" ${FLB_PREFER_SYSTEM_LIBS})

# Enable all features
if(FLB_ALL)
Expand Down Expand Up @@ -472,11 +474,16 @@ FLB_OPTION(FLUENT_PROTO_PROFILES ON)
add_subdirectory(${FLB_PATH_LIB_FLUENT_OTEL} EXCLUDE_FROM_ALL)

# MsgPack options
option(MSGPACK_ENABLE_CXX OFF)
option(MSGPACK_ENABLE_SHARED OFF)
option(MSGPACK_BUILD_TESTS OFF)
option(MSGPACK_BUILD_EXAMPLES OFF)
add_subdirectory(${FLB_PATH_LIB_MSGPACK} EXCLUDE_FROM_ALL)
if(FLB_PREFER_SYSTEM_LIB_MSGPACK)
find_package(PkgConfig)
pkg_check_modules(MSGPACK msgpack>=4.0.0)
endif()
if(MSGPACK_FOUND)
include_directories(${MSGPACK_INCLUDE_DIRS})
link_directories(${MSGPACK_LIBRARY_DIRS})
else()
include(cmake/msgpack.cmake)
endif()

# MPack
add_definitions(-DMPACK_EXTENSIONS=1)
Expand Down Expand Up @@ -683,8 +690,17 @@ if (FLB_SIGNV4)
endif()

if(FLB_SQLDB)
if(FLB_PREFER_SYSTEM_LIB_SQLITE)
find_package(PkgConfig)
pkg_check_modules(SQLITE sqlite3>=3.0.0)
endif()
if(SQLITE_FOUND)
include_directories(${SQLITE_INCLUDE_DIRS})
link_directories(${SQLITE_LIBRARY_DIRS})
else()
include(cmake/sqlite.cmake)
endif()
FLB_DEFINITION(FLB_HAVE_SQLDB)
add_subdirectory(${FLB_PATH_LIB_SQLITE})
endif()

if(FLB_TRACE)
Expand Down
2 changes: 0 additions & 2 deletions cmake/headers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ include_directories(

${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_CO}
${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_RBTREE}
${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_MSGPACK}/include

# Chunk I/O generate headers also in the binary path
${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_CHUNKIO}/include
Expand All @@ -25,7 +24,6 @@ include_directories(
${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_MONKEY}/include
${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_MONKEY}/include/monkey
${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_MBEDTLS}/include
${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_SQLITE}
${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_MPACK}/src
${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_MINIZ}/
${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_ONIGMO}
Expand Down
10 changes: 10 additions & 0 deletions cmake/msgpack.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# msgpack cmake
option(MSGPACK_ENABLE_CXX OFF)
option(MSGPACK_ENABLE_SHARED OFF)
option(MSGPACK_BUILD_TESTS OFF)
option(MSGPACK_BUILD_EXAMPLES OFF)
include_directories(
${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_MSGPACK}/include
)
add_subdirectory(${FLB_PATH_LIB_MSGPACK} EXCLUDE_FROM_ALL)
set(MSGPACK_LIBRARIES "msgpack-c-static")
6 changes: 6 additions & 0 deletions cmake/sqlite.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# sqlite cmake
include_directories(
${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_SQLITE}
)
add_subdirectory(${FLB_PATH_LIB_SQLITE})
set(SQLITE_LIBRARIES "sqlite3")
2 changes: 1 addition & 1 deletion plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ endmacro()
macro(FLB_PLUGIN name src deps)
add_library(flb-plugin-${name} STATIC ${src})
add_sanitizers(flb-plugin-${name})
target_link_libraries(flb-plugin-${name} fluent-bit-static msgpack-c-static ${deps})
target_link_libraries(flb-plugin-${name} fluent-bit-static ${MSGPACK_LIBRARIES} ${deps})
endmacro()


Expand Down
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ if(FLB_SQLDB)
)
set(extra_libs
${extra_libs}
"sqlite3")
${SQLITE_LIBRARIES})
endif()

if(FLB_STATIC_CONF)
Expand Down Expand Up @@ -383,7 +383,7 @@ set(FLB_DEPS
ctraces-static
mk_core
jsmn
msgpack-c-static
${MSGPACK_LIBRARIES}
mpack-static
chunkio-static
miniz
Expand Down
Loading