Skip to content

Commit

Permalink
add sqlite3 targets (#393)
Browse files Browse the repository at this point in the history
Adds SQLite3 targets for logging to a SQLite database.

The indent wrapper script has been removed as part of this change, as
some of the formatting that it enforces is undesirable. Specifically,
the indention of #define statements within header guards, and function
calls with no parameters having two spaces inside will no longer be used
in new code moving forward.
  • Loading branch information
goatshriek authored Dec 10, 2023
1 parent c2cb789 commit 89fcee4
Show file tree
Hide file tree
Showing 74 changed files with 4,792 additions and 373 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ jobs:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
- name: Configure
run: |
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_SHARED_LIBS=OFF .
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_SHARED_LIBS=OFF -DENABLE_JOURNALD_TARGETS=OFF -DENABLE_SQLITE3_TARGETS=OFF .
- name: Build
run: |
make all
Expand Down Expand Up @@ -277,7 +277,7 @@ jobs:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
- name: Configure
run: |
cmake -DCOVERAGE=ON -DCMAKE_BUILD_TYPE=Debug -DENABLE_JOURNALD_TARGETS=OFF -DENABLE_NETWORK_TARGETS=OFF -DENABLE_SOCKET_TARGETS=OFF -DENABLE_WINDOWS_EVENT_LOG_TARGETS=OFF -DENABLE_THREAD_SAFETY=OFF .
cmake -DCOVERAGE=ON -DCMAKE_BUILD_TYPE=Debug -DENABLE_JOURNALD_TARGETS=OFF -DENABLE_NETWORK_TARGETS=OFF -DENABLE_SOCKET_TARGETS=OFF -DENABLE_SQLITE3_TARGETS=OFF -DENABLE_WINDOWS_EVENT_LOG_TARGETS=OFF -DENABLE_THREAD_SAFETY=OFF .
- name: Build
run: |
make all
Expand All @@ -303,7 +303,7 @@ jobs:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
- name: Configure
run: |
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_JOURNALD_TARGETS=OFF -DENABLE_NETWORK_TARGETS=OFF -DENABLE_SOCKET_TARGETS=OFF -DENABLE_WINDOWS_EVENT_LOG_TARGETS=OFF -DENABLE_THREAD_SAFETY=OFF .
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_JOURNALD_TARGETS=OFF -DENABLE_NETWORK_TARGETS=OFF -DENABLE_SOCKET_TARGETS=OFF -DENABLE_SQLITE3_TARGETS=OFF -DENABLE_WINDOWS_EVENT_LOG_TARGETS=OFF -DENABLE_THREAD_SAFETY=OFF .
- name: Build
run: |
make all
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ jobs:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
- name: Configure
run: |
cmake -DCOVERAGE=ON -DENABLE_JOURNALD_TARGETS=OFF -DENABLE_NETWORK_TARGETS=OFF -DENABLE_SOCKET_TARGETS=OFF -DENABLE_WINDOWS_EVENT_LOG_TARGETS=OFF -DENABLE_THREAD_SAFETY=OFF .
cmake -DCOVERAGE=ON -DENABLE_JOURNALD_TARGETS=OFF -DENABLE_NETWORK_TARGETS=OFF -DENABLE_SOCKET_TARGETS=OFF -DENABLE_SQLITE3_TARGETS=OFF -DENABLE_WINDOWS_EVENT_LOG_TARGETS=OFF -DENABLE_THREAD_SAFETY=OFF .
- name: Build
run: |
make all
Expand Down
24 changes: 23 additions & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,36 @@ jobs:
- name: Run Examples
run: |
cmake --build . --config Release --target examples-single-file
windows-sqlite3:
name: "windows, release, sqlite3 source"
runs-on: "windows-2019"
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
- name: Download SQLite3 Amalgamation
run: |
Invoke-WebRequest -Uri https://sqlite.org/2023/sqlite-amalgamation-3440200.zip -OutFile sqlite.zip
Expand-Archive -Path sqlite.zip
shell: pwsh
- name: Configure
run: |
cmake -G "Visual Studio 16 2019" -DCMAKE_BUILD_TYPE=Release -DSQLITE3_SRC_PATH=D:\a\stumpless\stumpless\sqlite\sqlite-amalgamation-3440200\sqlite3.c -DSQLITE3_INCLUDE_PATH=D:\a\stumpless\stumpless\sqlite\sqlite-amalgamation-3440200\sqlite3.h .
- name: Build
run: |
cmake --build . --config Release
- name: Test
run: |
cmake --build . --config Release --target check
- name: Thread Safety Tests
run: |
cmake --build . --config Release --target check-thread-safety
windows-all-disabled:
name: "windows, all features disabled"
runs-on: "windows-2019"
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
- name: Configure
run: |
cmake -G "Visual Studio 16 2019" -DENABLE_JOURNALD_TARGETS=OFF -DENABLE_NETWORK_TARGETS=OFF -DENABLE_SOCKET_TARGETS=OFF -DCMAKE_BUILD_TYPE=Release -DENABLE_THREAD_SAFETY=OFF .
cmake -G "Visual Studio 16 2019" -DENABLE_JOURNALD_TARGETS=OFF -DENABLE_NETWORK_TARGETS=OFF -DENABLE_SOCKET_TARGETS=OFF -DENABLE_SQLITE3_TARGETS=OFF -DCMAKE_BUILD_TYPE=Release -DENABLE_THREAD_SAFETY=OFF .
- name: Build
run: |
cmake --build . --config Release
Expand Down
85 changes: 79 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ option(ENABLE_THREAD_SAFETY "support thread-safe functionality" ON)
option(ENABLE_JOURNALD_TARGETS "support systemd journald service targets" ON)
option(ENABLE_NETWORK_TARGETS "support network targets" ON)
option(ENABLE_SOCKET_TARGETS "support unix domain socket targets" ON)
option(ENABLE_SQLITE3_TARGETS "support sqlite3 targets" ON)
option(ENABLE_WINDOWS_EVENT_LOG_TARGETS "support windows event log targets" ON)

option(INSTALL_EXAMPLES "install examples" ON)
Expand Down Expand Up @@ -55,6 +56,32 @@ set(FALLBACK_PAGESIZE 4096
CACHE STRING "the memory page size to use if it cannot be detected at runtime"
)

string(CONCAT sqlite3_src_path_help_string
"The path to a SQLite3 source file, referred to as an 'amalgamation' in "
"SQLite documentation. If this variable is set, it is used to link SQLite3 "
"statically with Stumpless, instead of the default dynamic linking."
)
set(SQLITE3_SRC_PATH ""
CACHE FILEPATH ${sqlite3_src_path_help_string}
)

string(CONCAT sqlite3_include_path_help_string
"The path to the sqlite3.h header matching the source file provided in "
"SQLITE3_SRC_PATH. If the header is already in the include directores, this "
"does not need to be specified."
)
set(SQLITE3_INCLUDE_PATH ""
CACHE FILEPATH ${sqlite3_include_path_help_string}
)

set(SQLITE3_DEFAULT_TABLE_NAME "logs"
CACHE STRING "the name of the table used by default for SQLite3 targets"
)

set(SQLITE3_RETRY_MAX 3
CACHE STRING "the maximum number of retries on SQLite3 operations"
)

string(CONCAT benchmark_path_help_string
"A directory with a build of google benchmark that can be used instead of "
"downloading and building the library during build. "
Expand Down Expand Up @@ -120,8 +147,16 @@ include(tools/cmake/test.cmake)


# building configuration
if(EXISTS ${SQLITE3_INCLUDE_PATH})
file(COPY
"${SQLITE3_INCLUDE_PATH}"
DESTINATION "${PROJECT_BINARY_DIR}/include"
)
endif()

check_include_files(pthread.h HAVE_PTHREAD_H)
check_include_files(stdatomic.h HAVE_STDATOMIC_H)
check_include_files("sqlite3.h" HAVE_SQLITE3_H)
check_include_files(sys/socket.h HAVE_SYS_SOCKET_H)
check_include_files(syslog.h STUMPLESS_SYSLOG_H_COMPATIBLE)
check_include_files(systemd/sd-journal.h HAVE_SYSTEMD_SD_JOURNAL_H)
Expand Down Expand Up @@ -458,6 +493,45 @@ else()
endif()


# sqlite3 target support
if(NOT ENABLE_SQLITE3_TARGETS)
set(STUMPLESS_SQLITE3_TARGETS_SUPPORTED FALSE)
elseif(SQLITE3_SRC_PATH)
if(NOT EXISTS "${SQLITE3_SRC_PATH}")
message("the specified sqlite3 source file does not exist")
set(STUMPLESS_SQLITE3_TARGETS_SUPPORTED FALSE)
else()
list(APPEND STUMPLESS_SOURCES "${SQLITE3_SRC_PATH}")
set(STUMPLESS_SQLITE3_TARGETS_SUPPORTED TRUE)
endif()
elseif(NOT HAVE_SQLITE3_H)
message("sqlite3 targets are not supported without sqlite3.h")
set(STUMPLESS_SQLITE3_TARGETS_SUPPORTED FALSE)
else()
find_library(LIBSQLITE3_FOUND sqlite3)
if(LIBSQLITE3_FOUND)
set(STUMPLESS_SQLITE3_TARGETS_SUPPORTED TRUE)
else()
message("sqlite3 targets are not supported without libsqlite3")
set(STUMPLESS_SQLITE3_TARGETS_SUPPORTED FALSE)
endif()
endif()

if(STUMPLESS_SQLITE3_TARGETS_SUPPORTED)
include(tools/cmake/sqlite3.cmake)
else()
list(APPEND
STUMPLESS_SOURCES "${PROJECT_SOURCE_DIR}/src/config/sqlite3_unsupported.c"
)

add_function_test(sqlite3_unsupported
SOURCES
${PROJECT_SOURCE_DIR}/test/function/config/sqlite3_unsupported.cpp
$<TARGET_OBJECTS:test_helper_fixture>
)
endif()


# windows event log target support
if(NOT ENABLE_WINDOWS_EVENT_LOG_TARGETS)
set(STUMPLESS_WINDOWS_EVENT_LOG_TARGETS_SUPPORTED FALSE)
Expand Down Expand Up @@ -546,17 +620,15 @@ endif()
add_library(stumpless ${STUMPLESS_SOURCES})
set_target_properties(stumpless PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties(stumpless PROPERTIES PUBLIC_HEADER include/stumpless.h)

target_link_libraries(stumpless PRIVATE ${STUMPLESS_LINK_LIBRARIES})

if(MINGW)
target_compile_options(stumpless PRIVATE -D__USE_MINGW_ANSI_STDIO)
set_target_properties(stumpless PROPERTIES PREFIX "")
endif()

if(STUMPLESS_JOURNALD_TARGETS_SUPPORTED)
target_link_libraries(stumpless PRIVATE systemd)
endif()

if(STUMPLESS_WINDOWS_EVENT_LOG_TARGETS_SUPPORTED)
target_link_libraries(stumpless PRIVATE KtmW32)
add_dependencies(stumpless default_events)
endif()

Expand Down Expand Up @@ -584,7 +656,7 @@ endif(FUZZ)
target_include_directories(stumpless
PRIVATE
${PROJECT_SOURCE_DIR}/include
${CMAKE_BINARY_DIR}/include
${PROJECT_BINARY_DIR}/include
)


Expand Down Expand Up @@ -676,6 +748,7 @@ install(FILES
${PROJECT_SOURCE_DIR}/include/stumpless/target/buffer.h
${PROJECT_SOURCE_DIR}/include/stumpless/target/file.h
${PROJECT_SOURCE_DIR}/include/stumpless/target/function.h
${PROJECT_SOURCE_DIR}/include/stumpless/target/sqlite3.h
${PROJECT_SOURCE_DIR}/include/stumpless/target/stream.h
DESTINATION "include/stumpless/target"
)
Expand Down
3 changes: 2 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ fixes, check out the
[roadmap](https://github.com/goatshriek/stumpless/blob/master/docs/roadmap.md).


## [2.2.0] - 2023-10-14
## [2.2.0] - 2023-12-10
### Added
- @since format check enforcement in CI pipeline.
- `single-file` target for rollup `.c` and `.h` files.
- SQLite3 logging targets.
### Fixed
- Deadlock potential in `stumpless_set_entry_hostname` and
`stumpless_set_entry_procid` when validation fails.
Expand Down
1 change: 0 additions & 1 deletion docs/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ additional tools:
* `ruby` for some of the development scripts. If you have bundler, you can use
the Gemfile (run `bundle install` from the project root) to install all the
gems you might need at once.
* `indent` to format sources according to the project standard

## Simplified Wrapper Interface Generator (SWIG)
The SWIG project is used to expose the functionality of Stumpless to languages
Expand Down
Loading

0 comments on commit 89fcee4

Please sign in to comment.