Skip to content

Commit

Permalink
fix: no usage of etc/script/ci/build.sh (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexStocks authored Jan 20, 2025
2 parents 9937125 + 9c7cd3b commit 63192bd
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 70 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/import_braft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
- uses: actions/checkout@v4

- name: Build
run: bash ./etc/script/ci/build.sh
run: bash ./etc/script/build.sh gitinfo

- name: Check Format
working-directory: ${{ github.workspace }}/build
working-directory: ${{ github.workspace }}/${{ env.BUILD_DIR }}
run: make check-format

build_on_macos:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/kiwidb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: actions/checkout@v4

- name: Build
run: bash ./etc/script/ci/build.sh
run: bash ./etc/script/build.sh gitinfo

- name: Add LLVM apt repository
run: |
Expand All @@ -34,7 +34,7 @@ jobs:
run: clang-format --version

- name: Check Format
working-directory: ${{ github.workspace }}/build
working-directory: ${{ github.workspace }}/${{ env.BUILD_DIR }}
run: make check-format

build_on_macos:
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ EXECUTE_PROCESS(
MESSAGE(STATUS "GIT_COMMIT_HASH: ${GIT_COMMIT_HASH}")
MESSAGE(STATUS "GIT_COMMIT_DATE: ${BUILD_DATE}")

ADD_DEFINITIONS(-DKIWI_GIT_COMMIT_ID="${GIT_COMMIT_HASH}")
ADD_DEFINITIONS(-DKIWI_BUILD_DATE="${BUILD_DATE}")

IF(CMAKE_BUILD_TYPE STREQUAL "Release")
MESSAGE("Building in Release mode")
ELSE()
Expand Down
114 changes: 75 additions & 39 deletions etc/script/build.sh
Original file line number Diff line number Diff line change
@@ -1,57 +1,87 @@
#!/bin/bash

#color code
# Color codes
C_RED="\033[31m"
C_GREEN="\033[32m"

C_END="\033[0m"

BUILD_TYPE=Release
# Build configuration
K_VERSION="1.0.0"
BUILD_TYPE="Release"
VERBOSE=0
CMAKE_FLAGS=""
MAKE_FLAGS=""
PREFIX="cmake-build"

PWD=`pwd`
PWD=$(pwd)
PROJECT_HOME="${PWD}/"
CONF="${PROJECT_HOME}/etc/conf/kiwi.conf"

# Get build time and commit ID
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

BUILD_TIME="unknown"
SHORT_COMMIT_ID="unknown"

function get_git_info() {
time=$(git log -1 --format=%ai 2>/dev/null || echo "unknown")
if [ "$time" != "unknown" ]; then
time=${time:0:10}
fi
export BUILD_TIME=$time

id=$(git rev-parse HEAD 2>/dev/null || echo "unknown")
id=$([ "$id" != "unknown" ] && echo ${id:0:8} || echo "unknown")
if [ "$id" = "unknown" ]; then
echo "no git commit id"
id="kiwi"
fi
export SHORT_COMMIT_ID=$id
# echo "$BUILD_TIME $SHORT_COMMIT_ID"
}

function build() {
if [ ! -f "/proc/cpuinfo" ];then
CPU_CORE=$(sysctl -n hw.ncpu)
else
CPU_CORE=$(cat /proc/cpuinfo| grep "processor"| wc -l)
fi
if [ ${CPU_CORE} -eq 0 ]; then
CPU_CORE=1
fi

echo "cpu core ${CPU_CORE}"

echo "BUILD_TYPE:" $BUILD_TYPE
echo "CMAKE_FLAGS:" $CMAKE_FLAGS
echo "MAKE_FLAGS:" $MAKE_FLAGS

if [ "${BUILD_TYPE}" == "Release" ]; then
PREFIX="${PREFIX}-release"
else
PREFIX="${PREFIX}-debug"
fi

mkdir -p download
mkdir -p ${PREFIX}
cp CMakeLists.txt ${PREFIX}/

cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} ${CMAKE_FLAGS} -S . -B ${PREFIX}
cmake --build ${PREFIX} -- ${MAKE_FLAGS} -j ${CPU_CORE}

if [ $? -eq 0 ]; then
# echo -e "kiwi compile complete, output file ${C_GREEN} ${PREFIX}/bin/kiwi ${C_END}"
echo -e "kiwi compile complete, output file ${C_GREEN} ./bin/kiwi ${C_END}"
else
echo -e "${C_RED} kiwi compile fail ${C_END}"
exit 1
fi
if [ ! -f "/proc/cpuinfo" ]; then
CPU_CORE=$(sysctl -n hw.ncpu)
else
CPU_CORE=$(cat /proc/cpuinfo | grep "processor" | wc -l)
fi
if [ ${CPU_CORE} -eq 0 ]; then
CPU_CORE=1
fi

echo "CPU cores: ${CPU_CORE}"
echo "BUILD_TIME: $BUILD_TIME"
echo "COMMIT_ID: $SHORT_COMMIT_ID"
echo "BUILD_TYPE: $BUILD_TYPE"
echo "CMAKE_FLAGS: $CMAKE_FLAGS"
echo "MAKE_FLAGS: $MAKE_FLAGS"

if [ "${BUILD_TYPE}" == "Release" ]; then
PREFIX="${PREFIX}-release"
else
PREFIX="${PREFIX}-debug"
fi

mkdir -p download
mkdir -p ${PREFIX}
cp CMakeLists.txt ${PREFIX}/

cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DK_VERSION=$K_VERSION \
-DBUILD_TIME=$BUILD_TIME \
-DGIT_COMMIT_ID=$SHORT_COMMIT_ID \
-DKIWI_BUILD_DATE="$BUILD_TIME" \
-DKIWI_GIT_COMMIT_ID="$SHORT_COMMIT_ID" \
${CMAKE_FLAGS} -S . -B ${PREFIX}
cmake --build ${PREFIX} -- ${MAKE_FLAGS} -j ${CPU_CORE}

if [ $? -eq 0 ]; then
echo -e "kiwi compile complete, output file ${C_GREEN} ./bin/kiwi ${C_END}"
else
echo -e "${C_RED} kiwi compile fail ${C_END}"
exit 1
fi
}

# ":?" makes sure the bash var is not empty.
Expand All @@ -71,6 +101,7 @@ function clear() {

function show_help() {
echo "
sh $0 --gitinfo get git info
sh $0 --debug compile with debug
sh $0 --clang use clang compiler
sh $0 --kiwi only compile kiwi
Expand All @@ -93,6 +124,10 @@ while true; do
clear
shift ;;

--gitinfo)
get_git_info
shift ;;

--debug)
BUILD_TYPE=debug
;;
Expand Down Expand Up @@ -133,5 +168,6 @@ while true; do
shift
done

get_git_info
build

27 changes: 0 additions & 27 deletions etc/script/ci/build.sh

This file was deleted.

0 comments on commit 63192bd

Please sign in to comment.