-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests, Github-actions and other improvements (#8)
* improve codebase for succesfull compilation add catch2 for tests * add ctest add action * add debian to the action * add fedora and alma * try use altlinux * try altlinux * use catch2-devel for alt * use gcc and gcc-c++instead of gcc-defaults * use catch2-devel for fedora * try alt sisyphus * adopt for old catch2 * try adopt old catch * error in define for catch * use CATCH_CONFIG_MAIN only for one cpp * fix old catch2 vs new * fix includes * fix action and define * try check catch version * try check catch2 version again * try fix problem with main on alt * try fix problem with main * add ctest as dependency for alt * add separate target for header-only lib add perftest * add define for benchmarking * add define CATCH_CONFIG_ENABLE_BENCHMARKING directly into TU * try fix linkage problem * try again fix linkage * try use cpack * try allow root build rpm on alt * add options for simd and binary-search * add preftest for string rename macro for sanity check --------- Co-authored-by: Alexander B <[email protected]>
- Loading branch information
Showing
25 changed files
with
1,433 additions
and
967 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
Language: Cpp | ||
# BasedOnStyle: Google | ||
AccessModifierOffset: -1 | ||
AlignAfterOpenBracket: Align | ||
AlignConsecutiveAssignments: None | ||
AlignConsecutiveDeclarations: None | ||
AlignOperands: true | ||
AlignTrailingComments: true | ||
AllowAllParametersOfDeclarationOnNextLine: true | ||
AllowShortBlocksOnASingleLine: Never | ||
AllowShortCaseLabelsOnASingleLine: false | ||
AllowShortFunctionsOnASingleLine: All | ||
AllowShortIfStatementsOnASingleLine: true | ||
AllowShortLoopsOnASingleLine: true | ||
AlwaysBreakAfterDefinitionReturnType: None | ||
AlwaysBreakAfterReturnType: None | ||
AlwaysBreakBeforeMultilineStrings: true | ||
AlwaysBreakTemplateDeclarations: Yes | ||
BinPackArguments: false | ||
BinPackParameters: false | ||
BraceWrapping: | ||
AfterClass: false | ||
AfterControlStatement: false | ||
AfterEnum: false | ||
AfterFunction: false | ||
AfterNamespace: false | ||
AfterObjCDeclaration: false | ||
AfterStruct: false | ||
AfterUnion: false | ||
BeforeCatch: false | ||
BeforeElse: false | ||
IndentBraces: false | ||
BreakBeforeBinaryOperators: None | ||
BreakBeforeBraces: Attach | ||
BreakBeforeTernaryOperators: true | ||
BreakConstructorInitializersBeforeComma: false | ||
BreakAfterJavaFieldAnnotations: false | ||
BreakStringLiterals: true | ||
ColumnLimit: 150 | ||
CommentPragmas: '^ IWYU pragma:' | ||
ConstructorInitializerAllOnOneLineOrOnePerLine: true | ||
ConstructorInitializerIndentWidth: 4 | ||
ContinuationIndentWidth: 4 | ||
Cpp11BracedListStyle: true | ||
DerivePointerAlignment: true | ||
DisableFormat: false | ||
ExperimentalAutoDetectBinPacking: false | ||
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] | ||
IncludeCategories: | ||
- Regex: '^<.*\.h>' | ||
Priority: 1 | ||
- Regex: '^<.*' | ||
Priority: 2 | ||
- Regex: '.*' | ||
Priority: 3 | ||
IncludeIsMainRegex: '([-_](test|unittest))?$' | ||
IndentCaseLabels: true | ||
IndentWidth: 2 | ||
IndentWrappedFunctionNames: false | ||
JavaScriptQuotes: Leave | ||
JavaScriptWrapImports: true | ||
KeepEmptyLinesAtTheStartOfBlocks: false | ||
MacroBlockBegin: '' | ||
MacroBlockEnd: '' | ||
MaxEmptyLinesToKeep: 1 | ||
NamespaceIndentation: None | ||
ObjCBlockIndentWidth: 2 | ||
ObjCSpaceAfterProperty: false | ||
ObjCSpaceBeforeProtocolList: false | ||
PenaltyBreakBeforeFirstCallParameter: 1 | ||
PenaltyBreakComment: 300 | ||
PenaltyBreakFirstLessLess: 120 | ||
PenaltyBreakString: 1000 | ||
PenaltyExcessCharacter: 1000000 | ||
PenaltyReturnTypeOnItsOwnLine: 200 | ||
PointerAlignment: Left | ||
ReflowComments: true | ||
SortIncludes: Never | ||
SpaceAfterCStyleCast: false | ||
SpaceAfterTemplateKeyword: true | ||
SpaceBeforeAssignmentOperators: true | ||
SpaceBeforeParens: ControlStatements | ||
SpaceInEmptyParentheses: false | ||
SpacesBeforeTrailingComments: 2 | ||
SpacesInAngles: false | ||
SpacesInContainerLiterals: true | ||
SpacesInCStyleCastParentheses: false | ||
SpacesInParentheses: false | ||
SpacesInSquareBrackets: false | ||
Standard: Auto | ||
TabWidth: 8 | ||
UseTab: Never |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
name: build and cpack | ||
on: [ push, pull_request ] | ||
jobs: | ||
ubuntu-22-04: | ||
runs-on: ubuntu-latest | ||
name: Build on ${{ matrix.container }} x86_64 | ||
strategy: | ||
# | ||
# matrix for containers | ||
# | ||
matrix: | ||
container: | ||
- ubuntu:latest | ||
- debian:latest | ||
- fedora:latest | ||
- alt:sisyphus | ||
|
||
container: | ||
image: ${{ matrix.container }} | ||
|
||
steps: | ||
- name: Get current date | ||
id: date | ||
run: echo "date=$(date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_OUTPUT | ||
- name: Get commit sha | ||
id: git_sha | ||
run: echo "git_sha=$(echo $GITHUB_SHA)" >> $GITHUB_OUTPUT | ||
- uses: actions/checkout@v3 | ||
# install dependencies | ||
- name: devel-pkgs | ||
run: | | ||
case "${{ matrix.container }}" in | ||
ubuntu*|debian*) | ||
apt-get update -y && apt-get install -yq binutils git make cmake catch2 gcc g++ lsb-release | ||
;; | ||
fedora*) | ||
yum update -y && yum install -yq binutils git make cmake catch2-devel rpm-build redhat-lsb | ||
;; | ||
alt*) | ||
apt-get update -y && apt-get install -yq binutils git make cmake ctest catch2-devel gcc gcc-c++ rpm-build lsb-release | ||
;; | ||
esac | ||
# build project | ||
- name: mkdir | ||
run: mkdir cmake-build-release | ||
- name: cmake cmake-build-release | ||
run: cmake -DCOMMITTER_DATE="${{ steps.date.outputs.date }}" -DCOMMITTER_FULLSHA="${{ steps.git_sha.outputs.git_sha }}" -DCOMMITTER_SHORTSHA="$(echo ${{ steps.git_sha.outputs.git_sha }} | cut -c1-7)" -DCMAKE_BUILD_TYPE=Release -Bcmake-build-release -H. | ||
- name: cmake make | ||
run: cmake --build cmake-build-release/ --target all --parallel | ||
- name: get-version | ||
id: get-version | ||
run: echo "prj_ver=$(cat ./VERSION.txt)" >> $GITHUB_OUTPUT | ||
- name: ctest | ||
run: cd cmake-build-release && ctest && cd .. | ||
- name: cpack | ||
run: | | ||
case "${{ matrix.container }}" in | ||
ubuntu*|debian*) | ||
cd cmake-build-release && cpack -G DEB && cd .. | ||
;; | ||
fedora*) | ||
cd cmake-build-release && cpack -G RPM && cd .. | ||
;; | ||
alt*) | ||
cd cmake-build-release && echo "%_allow_root_build 1" > /etc/rpm/macros.d/02-enable-build-root && cpack -G RPM && cd .. | ||
;; | ||
esac | ||
- uses: mad9000/actions-find-and-replace-string@3 | ||
id: container | ||
with: | ||
source: ${{ matrix.container }} | ||
find: ':' # we want to remove : from container name | ||
replace: '-' # and replace it with - | ||
- name: Upload BTree binary | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: ${{ format('BTree-{0}.{1}', steps.get-version.outputs.prj_ver, steps.container.outputs.value) }} | ||
path: cmake-build-release/${{ format('BTree-{0}-noarch.???', steps.get-version.outputs.prj_ver) }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/cmake-build-*/ | ||
/.idea/ | ||
/.vscode/ | ||
/vcpkg/ | ||
CMakeLists.txt.user | ||
vcpkg | ||
VERSION.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,198 @@ | ||
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_SOURCE_DIR}/cmake/modules") | ||
cmake_minimum_required(VERSION 3.16) | ||
project(demo) | ||
|
||
set(MAJOR "0") | ||
set(MINOR "0") | ||
set(PATCH "1") | ||
cmake_policy(SET CMP0048 NEW) | ||
|
||
project(BTree VERSION ${MAJOR}.${MINOR}.${PATCH}) | ||
|
||
option(FORCE_USE_SIMD "force define FC_USE_SIMD (apllicable only for x86_64)" OFF) | ||
option(FORCE_PREFER_BINARY_SEARCH "force define FC_PREFER_BINARY_SEARCH (recommended for clang only)" OFF) | ||
|
||
set(CMAKE_CXX_STANDARD 20) | ||
|
||
add_executable(demo test/perftest.cpp fc_comp.h fc_disk_fixed_alloc.h fc_mmfile.h fc_btree.h fc_disk_btree.h) | ||
find_package(VersionHeader) | ||
set(PROJECT_VERSION "${MAJOR}.${MINOR}.${PATCH}.${COMMITTER_SHORTSHA}") | ||
file(WRITE ${CMAKE_SOURCE_DIR}/VERSION.txt "${MAJOR}.${MINOR}.${PATCH}") | ||
|
||
find_package(Catch2 3 QUIET) | ||
set(Catch_VER 3) | ||
if (NOT Catch2_FOUND) | ||
find_package(Catch2 REQUIRED) | ||
set(Catch_VER 2) | ||
endif() | ||
set(CATCH_LIBS_ALIASES Catch2::Catch2 Catch2::Catch2WithMain) | ||
|
||
function(get_linux_lsb_release_information) | ||
find_program(LSB_RELEASE_EXEC lsb_release) | ||
if(NOT LSB_RELEASE_EXEC) | ||
message(FATAL_ERROR "Could not detect lsb_release executable, can not gather required information") | ||
endif() | ||
|
||
execute_process(COMMAND "${LSB_RELEASE_EXEC}" --short --id OUTPUT_VARIABLE LSB_RELEASE_ID_SHORT OUTPUT_STRIP_TRAILING_WHITESPACE) | ||
execute_process(COMMAND "${LSB_RELEASE_EXEC}" --short --release OUTPUT_VARIABLE LSB_RELEASE_VERSION_SHORT OUTPUT_STRIP_TRAILING_WHITESPACE) | ||
execute_process(COMMAND "${LSB_RELEASE_EXEC}" --short --codename OUTPUT_VARIABLE LSB_RELEASE_CODENAME_SHORT OUTPUT_STRIP_TRAILING_WHITESPACE) | ||
|
||
set(LSB_RELEASE_ID_SHORT "${LSB_RELEASE_ID_SHORT}" PARENT_SCOPE) | ||
set(LSB_RELEASE_VERSION_SHORT "${LSB_RELEASE_VERSION_SHORT}" PARENT_SCOPE) | ||
set(LSB_RELEASE_CODENAME_SHORT "${LSB_RELEASE_CODENAME_SHORT}" PARENT_SCOPE) | ||
endfunction() | ||
|
||
message(STATUS "COMMITTER_FULLSHA ${COMMITTER_FULLSHA}") | ||
message(STATUS "COMMITTER_SHORTSHA ${COMMITTER_SHORTSHA}") | ||
message(STATUS "COMMITTER_DATE ${COMMITTER_DATE}") | ||
message(STATUS "PROJECT_VERSION ${PROJECT_VERSION}") | ||
|
||
if(CMAKE_SYSTEM_NAME MATCHES "Linux") | ||
get_linux_lsb_release_information() | ||
message(STATUS "OS Linux ${LSB_RELEASE_ID_SHORT} ${LSB_RELEASE_VERSION_SHORT} ${LSB_RELEASE_CODENAME_SHORT}") | ||
else() | ||
message(STATUS "OS ${CMAKE_SYSTEM_NAME}") | ||
message(STATUS "OS VERSION ${CMAKE_SYSTEM_VERSION}") | ||
endif() | ||
|
||
|
||
add_library(BTree INTERFACE | ||
include/fc/comp.h | ||
include/fc/disk_fixed_alloc.h | ||
include/fc/mmfile.h | ||
include/fc/btree.h | ||
include/fc/disk_btree.h | ||
include/fc/mmfile_win.h | ||
include/fc/mmfile_nix.h | ||
include/fc/details.h) | ||
|
||
target_include_directories( | ||
BTree | ||
INTERFACE | ||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" | ||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>" ) | ||
|
||
add_library(BTree::BTree ALIAS BTree) | ||
|
||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR FORCE_PREFER_BINARY_SEARCH) | ||
add_definitions(-DFC_PREFER_BINARY_SEARCH=1) | ||
endif() | ||
|
||
if (FORCE_USE_SIMD) | ||
add_definitions(-DFC_USE_SIMD=1) | ||
endif () | ||
|
||
add_executable(fc_tests | ||
test/test_statistics.h | ||
test/test_statistics.cpp | ||
test/fc_catch2.h | ||
test/unittest.cpp | ||
test/rwtest.cpp | ||
test/perftest.cpp | ||
test/perftest_no_simd.cpp | ||
test/perftest_string.cpp) | ||
|
||
if (${Catch_VER} EQUAL 2) | ||
message(STATUS "Used old target for catch2") | ||
if (NOT TARGET Catch2::Catch2WithMain) | ||
set(CATCH_LIBS_ALIASES Catch2::Catch2) | ||
endif() | ||
target_compile_definitions(fc_tests PRIVATE CATCH2_OLD) | ||
endif() | ||
|
||
target_include_directories(fc_tests PRIVATE ${CMAKE_CURRENT_LIST_DIR}) | ||
target_link_libraries(fc_tests PRIVATE ${CATCH_LIBS_ALIASES} BTree::BTree) | ||
|
||
if(MSVC) | ||
target_compile_options(demo PRIVATE /W4 /WX /nologo /MDd /EHsc /std:c++latest /experimental:module) | ||
if (CMAKE_BUILD_TYPE STREQUAL "Debug") | ||
elseif (CMAKE_BUILD_TYPE STREQUAL "Release") | ||
target_compile_options(fc_tests PRIVATE /W4 /WX /nologo /MDd /EHsc /std:c++latest /experimental:module) | ||
if (CMAKE_BUILD_TYPE STREQUAL "Release") | ||
add_compile_options(/Ox) | ||
endif() | ||
else() | ||
target_compile_options(demo PRIVATE -Wall -Wextra -Wpedantic -Werror -march=native) | ||
if (CMAKE_BUILD_TYPE STREQUAL "Debug") | ||
add_compile_options(-g) | ||
elseif (CMAKE_BUILD_TYPE STREQUAL "Release") | ||
add_compile_options(-O3) | ||
endif() | ||
target_compile_options(fc_tests PRIVATE -Wall -Wextra -Wpedantic -Werror -march=native) | ||
endif() | ||
|
||
include(CTest) | ||
include(Catch) | ||
catch_discover_tests(fc_tests | ||
EXTRA_ARGS --benchmark-samples=1) | ||
|
||
set(CPACK_SOURCE_IGNORE_FILES | ||
#git files | ||
"\\\\.git/" | ||
"\\\\.github/" | ||
# temporary files | ||
"\\\\.swp$" | ||
# backup files | ||
"~$" | ||
# eclipse files | ||
"\\\\.cdtproject$" | ||
"\\\\.cproject$" | ||
"\\\\.project$" | ||
"\\\\.settings/" | ||
# others | ||
"\\\\.#" | ||
"/#" | ||
"/build/" | ||
"/_build/" | ||
"/\\\\.git/" | ||
"Makefile\\\\.in$" | ||
) | ||
|
||
include(GNUInstallDirs) | ||
|
||
install( | ||
TARGETS BTree | ||
EXPORT BTree_Targets | ||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) | ||
|
||
include(CMakePackageConfigHelpers) | ||
write_basic_package_version_file( | ||
"BTreeConfigVersion.cmake" | ||
VERSION ${MAJOR}.${MINOR}.${PATCH} | ||
COMPATIBILITY SameMajorVersion) | ||
|
||
configure_package_config_file( | ||
"${PROJECT_SOURCE_DIR}/cmake/BTreeConfig.cmake.in" | ||
"${PROJECT_BINARY_DIR}/BTreeConfig.cmake" | ||
INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/BTree/cmake) | ||
|
||
install( | ||
EXPORT BTree_Targets | ||
FILE BTreeTargets.cmake | ||
NAMESPACE BTree:: | ||
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/BTree/cmake) | ||
|
||
install(FILES "${PROJECT_BINARY_DIR}/BTreeConfig.cmake" | ||
"${PROJECT_BINARY_DIR}/BTreeConfigVersion.cmake" | ||
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/BTree/cmake) | ||
|
||
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/fc | ||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) | ||
|
||
set(CPACK_PACKAGE_NAME "BTree") | ||
set(CPACK_PACKAGE_VERSION "${MAJOR}.${MINOR}.${PATCH}") | ||
set(CPACK_PACKAGE_VENDOR "community") | ||
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-noarch") | ||
set(CMAKE_PROJECT_HOMEPAGE_URL "https://github.com/bas524/BTree") | ||
set(CPACK_PACKAGE_CONTACT "bas524") | ||
set(CPACK_PACKAGE_MAINTAINER "bas524") | ||
set(CPACK_PACKAGE_DESCRIPTION "A general-purpose high-performance lightweight STL-like modern C++ B-Tree") | ||
|
||
set(CPACK_DEBIAN_PACKAGE_NAME ${CPACK_PACKAGE_NAME}) | ||
set(CPACK_DEBIAN_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}) | ||
set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_MAINTAINER}) | ||
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION}) | ||
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE ${CMAKE_PROJECT_HOMEPAGE_URL}) | ||
set(CPACK_DEBIAN_PACKAGE_LICENSE "Apache-2.0") | ||
set(CPACK_DEBIAN_PACKAGE_DEPENDS "") | ||
|
||
set(CPACK_RPM_PACKAGE_NAME ${CPACK_PACKAGE_NAME}) | ||
set(CPACK_RPM_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}) | ||
set(CPACK_RPM_PACKAGE_MAINTAINER ${CPACK_PACKAGE_MAINTAINER}) | ||
set(CPACK_RPM_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION}) | ||
set(CPACK_RPM_PACKAGE_URL ${CMAKE_PROJECT_HOMEPAGE_URL}) | ||
set(CPACK_RPM_PACKAGE_LICENSE "Apache-2.0") | ||
set(CPACK_RPM_PACKAGE_REQUIRES "") | ||
|
||
include(CPack) |
Oops, something went wrong.