Skip to content

Commit

Permalink
Add spl compilation switch, supports turning off spl function during …
Browse files Browse the repository at this point in the history
…compilation for better compatibility. (#1892)
  • Loading branch information
linrunqi08 authored Nov 18, 2024
1 parent 14c9ae5 commit ffbc94c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
14 changes: 12 additions & 2 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ endif ()
option(BUILD_LOGTAIL "Build Logtail executable and tools" ON)
option(BUILD_LOGTAIL_SHARED_LIBRARY "Build Logtail shared library")
option(ENABLE_ENTERPRISE "enable enterprise feature")
option(WITHSPL "Build Logtail and UT with SPL" ON)
cmake_dependent_option(ENABLE_COMPATIBLE_MODE "Build Logtail in compatible mode (for low version Linux)" OFF "LINUX" OFF)
cmake_dependent_option(ENABLE_STATIC_LINK_CRT "Build Logtail by linking CRT statically" OFF "LINUX" OFF)
option(WITHOUTGDB "Build Logtail without gdb")
Expand All @@ -40,6 +41,10 @@ else ()
include(${CMAKE_CURRENT_SOURCE_DIR}/options.cmake)
endif ()

if (NOT WITHSPL)
add_definitions(-D__EXCLUDE_SPL__)
endif()

# Default C/CXX flags.
if (UNIX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fpic -fPIC -D_LARGEFILE64_SOURCE")
Expand Down Expand Up @@ -88,7 +93,10 @@ set(SUB_DIRECTORIES_LIST
profile_sender reader sdk sender sls_control fuse
)
if (LINUX)
set(SUB_DIRECTORIES_LIST ${SUB_DIRECTORIES_LIST} observer spl)
if (WITHSPL)
set(SUB_DIRECTORIES_LIST ${SUB_DIRECTORIES_LIST} spl)
endif()
set(SUB_DIRECTORIES_LIST ${SUB_DIRECTORIES_LIST} observer)
if (ENABLE_ENTERPRISE)
set(SUB_DIRECTORIES_LIST ${SUB_DIRECTORIES_LIST} shennong streamlog)
endif()
Expand All @@ -108,7 +116,9 @@ macro(append_source_files source_files)
endmacro()
# Module includes & add_subdirectory.
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories("/opt/logtail_spl/include")
if (WITHSPL)
include_directories("/opt/logtail_spl/include")
endif()
foreach (DIR_NAME ${SUB_DIRECTORIES_LIST})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/${DIR_NAME})
endforeach (DIR_NAME)
Expand Down
4 changes: 2 additions & 2 deletions core/plugin/PluginRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#include "processor/inner/ProcessorSplitLogStringNative.h"
#include "processor/inner/ProcessorSplitMultilineLogStringNative.h"
#include "processor/inner/ProcessorTagNative.h"
#if defined(__linux__) && !defined(__ANDROID__)
#if defined(__linux__) && !defined(__ANDROID__) && !defined(__EXCLUDE_SPL__)
#include "processor/ProcessorSPL.h"
#endif
#include "common/Flags.h"
Expand Down Expand Up @@ -271,7 +271,7 @@ void PluginRegistry::LoadStaticPlugins() {
RegisterProcessorCreator(new StaticProcessorCreator<ProcessorParseRegexNative>());
RegisterProcessorCreator(new StaticProcessorCreator<ProcessorParseTimestampNative>());
RegisterProcessorCreator(new StaticProcessorCreator<ProcessorFilterNative>());
#if defined(__linux__) && !defined(__ANDROID__)
#if defined(__linux__) && !defined(__ANDROID__) && !defined(__EXCLUDE_SPL__)
if (BOOL_FLAG(enable_processor_spl)) {
RegisterProcessorCreator(new StaticProcessorCreator<ProcessorSPL>());
}
Expand Down
6 changes: 4 additions & 2 deletions core/processor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if (MSVC)
endif ()

file(GLOB LIB_SOURCE_FILES *.cpp *.h)
if (NOT LINUX)
if ((NOT LINUX) OR (NOT WITHSPL))
list(REMOVE_ITEM LIB_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/ProcessorSPL.h ${CMAKE_CURRENT_SOURCE_DIR}/ProcessorSPL.cpp)
endif ()
append_source_files(LIB_SOURCE_FILES)
Expand All @@ -41,5 +41,7 @@ target_link_libraries(${PROJECT_NAME} fuse)
target_link_libraries(${PROJECT_NAME} plugin_interface)
link_re2(${PROJECT_NAME})
if (LINUX)
target_link_libraries(${PROJECT_NAME} spl)
if (WITHSPL)
target_link_libraries(${PROJECT_NAME} spl)
endif ()
endif ()
12 changes: 10 additions & 2 deletions core/unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
cmake_minimum_required(VERSION 3.22)
project(unittest_base)

if (NOT WITHSPL)
add_definitions(-D__EXCLUDE_SPL__)
endif()

add_definitions(-DAPSARA_UNIT_TEST_MAIN)
set(NO_TCMALLOC TRUE)
add_definitions(-DLOGTAIL_NO_TC_MALLOC)
Expand All @@ -37,7 +41,9 @@ link_protobuf(${PROJECT_NAME})
link_cityhash(${PROJECT_NAME})
link_leveldb(${PROJECT_NAME})
link_asan(${PROJECT_NAME})
link_spl(${PROJECT_NAME})
if (WITHSPL)
link_spl(${PROJECT_NAME})
endif()
link_tcmalloc(${PROJECT_NAME})

if (UNIX)
Expand Down Expand Up @@ -80,6 +86,8 @@ add_subdirectory(sdk)
add_subdirectory(sender)

if (LINUX)
add_subdirectory(spl)
if (WITHSPL)
add_subdirectory(spl)
endif()
add_subdirectory(observer)
endif ()
Original file line number Diff line number Diff line change
Expand Up @@ -1577,7 +1577,7 @@ HTTP/2.0' '200' '154' 'go-sdk'"

// run function ProcessorParseDelimiterNative
ProcessorParseDelimiterNative& processorParseDelimiterNative = *(new ProcessorParseDelimiterNative);
ProcessorInstance processorInstance(&processorParseDelimiterNative, pluginId);
ProcessorInstance processorInstance(&processorParseDelimiterNative, getPluginMeta());
APSARA_TEST_TRUE_FATAL(processorInstance.Init(config, mContext));
processorParseDelimiterNative.Process(eventGroup);

Expand Down

0 comments on commit ffbc94c

Please sign in to comment.