Skip to content

Commit

Permalink
Merge branch 'unstable' into feat-support-ipv6
Browse files Browse the repository at this point in the history
  • Loading branch information
marsevilspirit committed Jan 15, 2025
2 parents 3868f52 + c9ceb4a commit 2aada3b
Show file tree
Hide file tree
Showing 146 changed files with 1,117 additions and 938 deletions.
4 changes: 2 additions & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ Checks: '
# - { key: readability-identifier-naming.VariableCase, value: lower_case }

WarningsAsErrors: '*'
# HeaderFilterRegex: '(|/src|/src/net|/src/pstd|/src/storage)/include'
# HeaderFilterRegex: '/src/(net|storage|pstd)/include'
# HeaderFilterRegex: '(|/src|/src/net|/src/std|/src/storage)/include'
# HeaderFilterRegex: '/src/(net|storage|std)/include'

#### Disabled checks and why: #####
#
Expand Down
18 changes: 16 additions & 2 deletions .github/workflows/pikiwidb.yml → .github/workflows/kiwidb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [ "unstable" ]
pull_request:
branches: [ "unstable" ]
branches: [ "*" ]

env:
BUILD_DIR: cmake-build-release
Expand All @@ -19,6 +19,20 @@ jobs:
- name: Build
run: bash ./etc/script/ci/build.sh

- name: Add LLVM apt repository
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" | sudo tee /etc/apt/sources.list.d/llvm.list
sudo apt update
- name: Install clang-format-18
run: |
sudo apt install -y clang-format-18
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-18 200
- name: Verify clang-format version
run: clang-format --version

- name: Check Format
working-directory: ${{ github.workspace }}/build
run: make check-format
Expand Down Expand Up @@ -94,7 +108,7 @@ jobs:
- uses: actions/checkout@v4

- name: Install dependencies
run: sudo apt-get install -y ccache
run: sudo apt install -y ccache

- name: Configure ccache
run: |
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ download/
CMakeFiles/
CMakeCache.txt

# clang-format
temp.txt

# Precompiled Headers
*.gch
*.pch
Expand Down
27 changes: 18 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.

CMAKE_MINIMUM_REQUIRED(VERSION 3.14)
CMAKE_MINIMUM_REQUIRED(VERSION 3.25)
PROJECT(kiwi)
include(GNUInstallDirs)

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=return-type")

# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
IF (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
CMAKE_POLICY(SET CMP0135 NEW)
ENDIF ()
CMAKE_POLICY(SET CMP0135 NEW)

SET(CMAKE_CXX_STANDARD 20)
SET(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Expand Down Expand Up @@ -64,8 +61,10 @@ ELSE()
ENDIF()
ENDIF()

EXECUTE_PROCESS(COMMAND uname -p OUTPUT_VARIABLE HOST_ARCH)
STRING(TOLOWER ${HOST_ARCH} HOST_ARCH)
IF (NOT HOST_ARCH)
EXECUTE_PROCESS(COMMAND uname -p OUTPUT_VARIABLE HOST_ARCH)
STRING(TOLOWER ${HOST_ARCH} HOST_ARCH)
ENDIF ()

IF (NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE RELEASE)
Expand Down Expand Up @@ -184,6 +183,7 @@ ENDIF()
SET(LIB ${LIB} CACHE INTERNAL "libs which should be linked for executable target")

INCLUDE(ExternalProject)
INCLUDE(cmake/precommit.cmake)
INCLUDE(cmake/findTools.cmake)
INCLUDE(cmake/openssl.cmake)
INCLUDE(cmake/gflags.cmake)
Expand All @@ -205,9 +205,9 @@ FILE(MAKE_DIRECTORY "${PROTO_OUTPUT_DIR}")

#INCLUDE(cmake/protogen.cmake)

ADD_SUBDIRECTORY(src/pstd)
ADD_SUBDIRECTORY(src/std)
ADD_SUBDIRECTORY(src/net)
ADD_SUBDIRECTORY(src/praft)
ADD_SUBDIRECTORY(src/raft)
ADD_SUBDIRECTORY(src/storage)
ADD_SUBDIRECTORY(src/resp)

Expand All @@ -223,6 +223,15 @@ FOREACH(IGNORE_FILE ${CLANG_FORMAT_IGNORE_FILES})
FILE(APPEND ${BUILD_SUPPORT_DIR}/clang_format_exclusions.txt "${IGNORE_FILE}\n")
ENDFOREACH()

# install git hooks when configure
EXECUTE_PROCESS(
COMMAND ${CMAKE_COMMAND} -E make_directory ${GIT_HOOKS_DIR}
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${HOOKS_SOURCE_DIR}/precommit.sh
${GIT_HOOKS_DIR}/pre-commit
COMMAND ${CMAKE_COMMAND} -E chmod 755 ${GIT_HOOKS_DIR}/pre-commit
)

STRING(CONCAT FORMAT_DIRS "${PROJECT_SOURCE_DIR}/src,")
ADD_CUSTOM_TARGET(format
COMMAND ${BUILD_SUPPORT_DIR}/run_clang_format.py
Expand Down
1 change: 1 addition & 0 deletions cmake/braft.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ ExternalProject_Add(
-DOPENSSL_INCLUDE_DIR=${OPENSSL_INCLUDE_DIR}
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
BUILD_COMMAND make -j${CPU_CORE}
UPDATE_COMMAND ""
)

ADD_DEPENDENCIES(extern_braft brpc gflags)
Expand Down
1 change: 1 addition & 0 deletions cmake/brpc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ ExternalProject_Add(
-DWITH_GLOG=OFF
-DDOWNLOAD_GTEST=OFF
BUILD_COMMAND make -j${CPU_CORE}
UPDATE_COMMAND ""
)
ADD_DEPENDENCIES(extern_brpc ssl crypto zlib protobuf leveldb gflags)
ADD_LIBRARY(brpc STATIC IMPORTED GLOBAL)
Expand Down
2 changes: 2 additions & 0 deletions cmake/findTools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ FIND_PROGRAM(AUTOCONF autoconf PATHS /usr/bin /usr/local/bin)

IF (${AUTOCONF} MATCHES AUTOCONF-NOTFOUND)
MESSAGE(FATAL_ERROR "not find autoconf on localhost")
ELSE()
MESSAGE(STATUS "found autoconf at ${AUTOCONF}")
ENDIF ()

FIND_PROGRAM(CLANG_FORMAT_BIN
Expand Down
1 change: 1 addition & 0 deletions cmake/fmt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ ExternalProject_Add(
-DFMT_TEST=FALSE
-DSHARED_LIBS=FALSE
BUILD_COMMAND make -j${CPU_CORE}
UPDATE_COMMAND ""
)


Expand Down
1 change: 1 addition & 0 deletions cmake/gflags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ ExternalProject_Add(
-DGFLAGS_BUILD_TESTING=OFF
-DCMAKE_INSTALL_PREFIX=${LIB_INSTALL_PREFIX}
BUILD_COMMAND make -j${CPU_CORE}
UPDATE_COMMAND ""
)

ADD_LIBRARY(gflags STATIC IMPORTED GLOBAL)
Expand Down
1 change: 1 addition & 0 deletions cmake/leveldb.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ExternalProject_Add(
-DLEVELDB_BUILD_BENCHMARKS=OFF
-DCMAKE_BUILD_TYPE=${THIRD_PARTY_BUILD_TYPE}
BUILD_COMMAND make -j${CPU_CORE}
UPDATE_COMMAND ""
)

ADD_DEPENDENCIES(extern_leveldb snappy)
Expand Down
1 change: 1 addition & 0 deletions cmake/lz4.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ExternalProject_Add(
-DBUILD_STATIC_LIBS=ON
-DBUILD_SHARED_LIBS=OFF
BUILD_COMMAND make -j${CPU_CORE}
UPDATE_COMMAND ""
)

ADD_LIBRARY(lz4 STATIC IMPORTED GLOBAL)
Expand Down
1 change: 1 addition & 0 deletions cmake/openssl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ ExternalProject_Add(
TEST_COMMAND ""
INSTALL_COMMAND make install_sw
INSTALL_DIR ${OPENSSL_INSTALL_DIR}
UPDATE_COMMAND ""
)

SET(OPENSSL_LIB "lib")
Expand Down
19 changes: 19 additions & 0 deletions cmake/precommit.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) 2025-present, Arana/Kiwi Community. All rights reserved.
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.


# define hooks source and target path
SET(HOOKS_SOURCE_DIR "${CMAKE_SOURCE_DIR}/etc/script")
set(GIT_HOOKS_DIR "${CMAKE_SOURCE_DIR}/.git/hooks")

# # ensure pre-commit hook is installed
# ADD_CUSTOM_TARGET(install_git_hooks
# COMMAND ${CMAKE_COMMAND} -E make_directory ${GIT_HOOKS_DIR}
# COMMAND ${CMAKE_COMMAND} -E copy_if_different
# ${HOOKS_SOURCE_DIR}/precommit.sh
# ${GIT_HOOKS_DIR}/pre-commit
# COMMAND ${CMAKE_COMMAND} -E chmod 755 ${GIT_HOOKS_DIR}/pre-commit
# COMMENT "Installing git hooks..."
# )
1 change: 1 addition & 0 deletions cmake/rocksdb.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ ExternalProject_Add(
-DWITH_GFLAGS=ON
-DUSE_RTTI=ON
BUILD_COMMAND make -j${CPU_CORE}
UPDATE_COMMAND ""
)

ADD_DEPENDENCIES(extern_rocksdb snappy gflags zlib lz4)
Expand Down
1 change: 1 addition & 0 deletions cmake/snappy.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ ExternalProject_Add(
-DSNAPPY_BUILD_BENCHMARKS=OFF
-DBUILD_STATIC_LIBS=ON
-DBUILD_SHARED_LIBS=OFF
UPDATE_COMMAND ""
)

ADD_LIBRARY(snappy STATIC IMPORTED GLOBAL)
Expand Down
1 change: 1 addition & 0 deletions cmake/zlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ExternalProject_Add(
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
BUILD_COMMAND make -j${CPU_CORE}
UPDATE_COMMAND ""
)

ADD_LIBRARY(zlib STATIC IMPORTED GLOBAL)
Expand Down
1 change: 1 addition & 0 deletions cmake/zstd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ExternalProject_Add(
-DZSTD_BUILD_STATIC=ON
-DZSTD_BUILD_SHARED=OFF
BUILD_COMMAND make -j${CPU_CORE}
UPDATE_COMMAND ""
)

ADD_LIBRARY(zstd STATIC IMPORTED GLOBAL)
Expand Down
2 changes: 2 additions & 0 deletions etc/script/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ while true; do
--kiwi)
MAKE_FLAGS="${MAKE_FLAGS} kiwi"
;;

-h|--help)
show_help
;;
Expand Down Expand Up @@ -133,3 +134,4 @@ while true; do
done

build

61 changes: 61 additions & 0 deletions etc/script/check_format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash

# Check if clang-format is installed
if ! command -v clang-format &> /dev/null; then
echo "Error: clang-format is not installed"
echo "Please install clang-format first"
exit 1
fi

# Set color output
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color

# Counters
error_count=0
checked_count=0

# Check file
check_file() {
local file=$1
# Create a temporary file with formatted content
clang-format $file > temp.txt

# Compare the original file with the formatted file
if ! diff -u "$file" temp.txt > /dev/null; then
echo -e "${RED}Needs formatting: $file${NC}"
# Show specific differences
diff -u "$file" temp.txt | grep -E "^[\+\-]" | head -n 10
echo "..."
((error_count++))
else
echo -e "${GREEN}Correctly formatted: $file${NC}"
fi
((checked_count++))

# Clean up temporary file
rm temp.txt
}

# Main function
main() {
echo "Starting code format check..."

# Find all C/C++ source files
while IFS= read -r -d '' file; do
check_file "$file"
done < <(find ./src -type f \( -name "*.cpp" -o -name "*.hpp" -o -name "*.c" -o -name "*.h" -o -name "*.cc" \) -print0)

# Output summary
echo "----------------------------------------"
echo "Check completed!"
echo "Total files checked: $checked_count"
echo "Files needing formatting: $error_count"

# Return non-zero if there are errors
[ "$error_count" -gt 0 ] && exit 1 || exit 0
}

# Run the main function
main
31 changes: 31 additions & 0 deletions etc/script/precommit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

# Path to the check_format.sh script
SCRIPT_PATH="etc/script/check_format.sh"

# Check if the script exists
if [ ! -f "$SCRIPT_PATH" ]; then
echo "Error: $SCRIPT_PATH not found!"
exit 1
fi

# Make sure the script is executable
chmod +x "$SCRIPT_PATH"

# Run the script on all staged files
#STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(cpp|cc|h|hpp|c)$')

# if [ -n "$STAGED_FILES" ]; then
# for file in $STAGED_FILES; do
# "$SCRIPT_PATH" "$file"
# if [ $? -ne 0 ]; then
# echo "Commit aborted due to formatting issues."
# exit 1
# fi
# done
# fi

sh $SCRIPT_PATH

exit 0 # Path to the check_format.sh script

Loading

0 comments on commit 2aada3b

Please sign in to comment.