From ab2ad5ad44941d270b922405e6a536f0866ab9c4 Mon Sep 17 00:00:00 2001 From: Chen Bo Date: Thu, 3 Aug 2023 00:44:42 +0800 Subject: [PATCH] Set CMAKE_BUILD_PARALLEL_LEVEL to the num of CPU --- .github/workflows/ci.linux.arm.yml | 40 +++++++++++++++ .github/workflows/ci.linux.x86.yml | 73 +++++++++++++++++++++++++++ .github/workflows/ci.linux.yml | 52 ------------------- .github/workflows/ci.macos.yml | 8 +-- CMakeLists.txt | 51 +++++++++++-------- doc/docs/introduction/how-to-build.md | 21 ++++---- 6 files changed, 158 insertions(+), 87 deletions(-) create mode 100644 .github/workflows/ci.linux.arm.yml create mode 100644 .github/workflows/ci.linux.x86.yml delete mode 100644 .github/workflows/ci.linux.yml diff --git a/.github/workflows/ci.linux.arm.yml b/.github/workflows/ci.linux.arm.yml new file mode 100644 index 00000000..3a99e5e6 --- /dev/null +++ b/.github/workflows/ci.linux.arm.yml @@ -0,0 +1,40 @@ +name: Linux ARM + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + centos8-gcc921-epoll: + runs-on: [self-hosted, Linux, ARM64] + + container: + image: dokken/centos-stream-8:sha-40294ce + options: --cpus 4 + + steps: + - uses: actions/checkout@v3 + + - name: Install Dependencies + run: | + dnf install -y git gcc-c++ cmake + dnf install -y gcc-toolset-9-gcc-c++ + dnf install -y openssl-devel libcurl-devel libaio-devel + dnf install -y epel-release + dnf install -y fuse-devel libgsasl-devel + + - name: Build + run: | + source /opt/rh/gcc-toolset-9/enable + cmake -B build -D BUILD_TESTING=ON -D CMAKE_BUILD_TYPE=RelWithDebInfo \ + -D ENABLE_SASL=ON -D ENABLE_FUSE=ON \ + -D ENABLE_URING=OFF -D FETCH_GTEST_GFLAGS_SOURCE=ON + cmake --build build + + - name: Test + run: | + ulimit -l unlimited + cd build + ctest --timeout 3600 -V diff --git a/.github/workflows/ci.linux.x86.yml b/.github/workflows/ci.linux.x86.yml new file mode 100644 index 00000000..a946ace7 --- /dev/null +++ b/.github/workflows/ci.linux.x86.yml @@ -0,0 +1,73 @@ +name: Linux x86 + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + centos8-gcc921-epoll: + runs-on: [self-hosted, Linux, X64] + + container: + image: dokken/centos-stream-8:sha-40294ce + options: --cpus 4 + + steps: + - uses: actions/checkout@v3 + + - name: Install Dependencies + run: | + dnf install -y git gcc-c++ cmake + dnf install -y gcc-toolset-9-gcc-c++ + dnf install -y openssl-devel libcurl-devel libaio-devel + dnf install -y epel-release + dnf install -y fuse-devel libgsasl-devel + + - name: Build + run: | + source /opt/rh/gcc-toolset-9/enable + cmake -B build -D BUILD_TESTING=ON -D CMAKE_BUILD_TYPE=RelWithDebInfo \ + -D ENABLE_SASL=ON -D ENABLE_FUSE=ON \ + -D ENABLE_URING=OFF -D FETCH_GTEST_GFLAGS_SOURCE=ON + cmake --build build + + - name: Test + run: | + ulimit -l unlimited + cd build + ctest --timeout 3600 -V + + centos8-gcc921-iouring: + runs-on: [self-hosted, Linux, X64] + + container: + image: dokken/centos-stream-8:sha-40294ce + # In order to run io_uring, the docker daemon should add --default-ulimit memlock=-1:-1 + options: --cpus 4 + + steps: + - uses: actions/checkout@v3 + + - name: Install Dependencies + run: | + dnf install -y git gcc-c++ cmake + dnf install -y gcc-toolset-9-gcc-c++ + dnf install -y openssl-devel libcurl-devel libaio-devel + dnf install -y epel-release + dnf install -y fuse-devel libgsasl-devel + + - name: Build + run: | + source /opt/rh/gcc-toolset-9/enable + cmake -B build -D BUILD_TESTING=ON -D CMAKE_BUILD_TYPE=RelWithDebInfo \ + -D ENABLE_SASL=ON -D ENABLE_FUSE=ON \ + -D ENABLE_URING=ON -D FETCH_GTEST_GFLAGS_SOURCE=ON + cmake --build build + + - name: Test + run: | + ulimit -l unlimited + cd build + ctest --timeout 3600 -V diff --git a/.github/workflows/ci.linux.yml b/.github/workflows/ci.linux.yml deleted file mode 100644 index 6811c33b..00000000 --- a/.github/workflows/ci.linux.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: Linux - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -jobs: - Debug: - runs-on: ubuntu-20.04 - - steps: - - uses: actions/checkout@v3 - - - name: Install Dependencies - shell: bash - run: | - sudo apt update -y - sudo apt install -y git cmake libssl-dev libcurl4-openssl-dev libaio-dev libfuse-dev libgsasl7-dev libgtest-dev libgmock-dev libgflags-dev - - - name: Configure CMake - run: cmake -B ${{github.workspace}}/build -D BUILD_TESTING=1 -D ENABLE_SASL=1 -D ENABLE_FUSE=1 -D ENABLE_URING=1 -D CMAKE_BUILD_TYPE=Debug - - - name: Build - run: cmake --build ${{github.workspace}}/build -j - - - name: Test - working-directory: ${{github.workspace}}/build - run: sudo bash -c 'ulimit -l unlimited; ctest --timeout 3600 -V' - - Release: - runs-on: ubuntu-22.04 - - steps: - - uses: actions/checkout@v3 - - - name: Install Dependencies - shell: bash - run: | - sudo apt update -y - sudo apt install -y git cmake libssl-dev libcurl4-openssl-dev libaio-dev libfuse-dev libgsasl7-dev libgtest-dev libgmock-dev libgflags-dev - - - name: Configure CMake - run: cmake -B ${{github.workspace}}/build -D BUILD_TESTING=1 -D ENABLE_SASL=1 -D ENABLE_FUSE=1 -D ENABLE_URING=1 -D CMAKE_BUILD_TYPE=Release - - - name: Build - run: cmake --build ${{github.workspace}}/build -j - - - name: Test - working-directory: ${{github.workspace}}/build - run: sudo bash -c 'ulimit -l unlimited; ctest --timeout 3600 -V' diff --git a/.github/workflows/ci.macos.yml b/.github/workflows/ci.macos.yml index 8278dfd4..24099992 100644 --- a/.github/workflows/ci.macos.yml +++ b/.github/workflows/ci.macos.yml @@ -18,11 +18,11 @@ jobs: run: | brew install cmake openssl gflags googletest gsasl - - name: Configure CMake - run: cmake -B ${{github.workspace}}/build -D BUILD_TESTING=1 -D ENABLE_SASL=1 -D CMAKE_BUILD_TYPE=Debug -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl@3 - - name: Build - run: cmake --build ${{github.workspace}}/build -j + run: | + cmake -B ${{github.workspace}}/build -D BUILD_TESTING=ON -D CMAKE_BUILD_TYPE=RelWithDebInfo \ + -D ENABLE_SASL=ON -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl@3 + cmake --build ${{github.workspace}}/build - name: Test working-directory: ${{github.workspace}}/build diff --git a/CMakeLists.txt b/CMakeLists.txt index a0e1311d..4dc0e00a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ project( include(FindPackageHandleStandardArgs) include(CheckCXXCompilerFlag) include(FetchContent) +include(ProcessorCount) set(FETCHCONTENT_QUIET false) find_package(PkgConfig REQUIRED) @@ -23,24 +24,27 @@ option(FETCH_GTEST_GFLAGS_SOURCE "Fetch gtest, gmock and gflags source code. Lin option(ENABLE_FSTACK_DPDK "Use f-stack + DPDK as the event engine" OFF) option(ENABLE_EXTFS "enable extfs" OFF) -# Get CPU arch +# Get CPU arch and number execute_process(COMMAND uname -m OUTPUT_VARIABLE ARCH OUTPUT_STRIP_TRAILING_WHITESPACE) if (NOT (${ARCH} STREQUAL x86_64) AND NOT (${ARCH} STREQUAL aarch64) AND NOT (${ARCH} STREQUAL arm64)) message(FATAL_ERROR "Unknown CPU architecture ${ARCH}") endif () +ProcessorCount(NumCPU) # Compiler options add_compile_options(-Wall) # -Werror is not enable yet set(CMAKE_CXX_STANDARD 14) -set(CMAKE_CXX_STANDARD_REQUIRED on) -set(CMAKE_CXX_EXTENSIONS off) -set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") -set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG") -set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG") +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) +# CMake didn't provide an abstraction of optimization level for now. +set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") # For development +set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG") # For production +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g") # For CI test set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -set(CMAKE_BUILD_RPATH_USE_ORIGIN on) -set(CMAKE_POSITION_INDEPENDENT_CODE on) +set(CMAKE_BUILD_RPATH_USE_ORIGIN ON) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) +set(CMAKE_BUILD_PARALLEL_LEVEL ${NumCPU}) if (${ARCH} STREQUAL x86_64) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2") @@ -125,7 +129,8 @@ if (ENABLE_EXTFS) find_package(e2fs REQUIRED) endif() -if (FETCH_GTEST_GFLAGS_SOURCE) +function(do_fetch_gtest_gflags_src) + set(BUILD_TESTING OFF) # Only disable in this function FetchContent_Declare( gflags GIT_REPOSITORY https://github.com/gflags/gflags.git @@ -141,6 +146,10 @@ if (FETCH_GTEST_GFLAGS_SOURCE) GIT_TAG release-1.12.1 ) FetchContent_MakeAvailable(googletest) +endfunction() + +if (FETCH_GTEST_GFLAGS_SOURCE) + do_fetch_gtest_gflags_src() endif() # Compile photon objects @@ -274,15 +283,15 @@ target_link_libraries(photon_static ${static_link_libs}) if (BUILD_TESTING) include(CTest) -if (FETCH_GTEST_GFLAGS_SOURCE) - set(testing_libs gtest gmock gflags::gflags) -else() - find_package(GTest REQUIRED) - find_package(gmock REQUIRED) - find_package(gflags REQUIRED) - set(testing_libs ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARIES} ${GFLAGS_LIBRARIES}) - include_directories(${GTEST_INCLUDE_DIRS} ${GMOCK_INCLUDE_DIRS} ${GFLAGS_INCLUDE_DIRS}) -endif() + if (FETCH_GTEST_GFLAGS_SOURCE) + set(testing_libs gtest gmock gflags::gflags) + else () + find_package(GTest REQUIRED) + find_package(gmock REQUIRED) + find_package(gflags REQUIRED) + set(testing_libs ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARIES} ${GFLAGS_LIBRARIES}) + include_directories(${GTEST_INCLUDE_DIRS} ${GMOCK_INCLUDE_DIRS} ${GFLAGS_INCLUDE_DIRS}) + endif () add_subdirectory(examples) add_subdirectory(common/checksum/test) @@ -294,8 +303,8 @@ endif() add_subdirectory(rpc/test) add_subdirectory(thread/test) add_subdirectory(net/security-context/test) -if (ENABLE_EXTFS) - add_subdirectory(fs/extfs/test) -endif () + if (ENABLE_EXTFS) + add_subdirectory(fs/extfs/test) + endif () endif () diff --git a/doc/docs/introduction/how-to-build.md b/doc/docs/introduction/how-to-build.md index 9701a8b6..6ceec1a6 100644 --- a/doc/docs/introduction/how-to-build.md +++ b/doc/docs/introduction/how-to-build.md @@ -64,7 +64,7 @@ brew install cmake openssl pkg-config ```bash cd PhotonLibOS cmake -B build -cmake --build build -j +cmake --build build ``` ```mdx-code-block @@ -75,7 +75,7 @@ cmake --build build -j ```bash cd PhotonLibOS cmake -B build -cmake --build build -j +cmake --build build ``` ```mdx-code-block @@ -87,7 +87,7 @@ cmake --build build -j cd PhotonLibOS # Use `brew info openssl` to find openssl path cmake -B build -D OPENSSL_ROOT_DIR=/path/to/openssl/ -cmake --build build -j +cmake --build build ``` ```mdx-code-block @@ -110,11 +110,12 @@ The examples and test code are built together. ```bash # Install additional dependencies +dnf install epel-releaase dnf install gtest-devel gmock-devel gflags-devel fuse-devel libgsasl-devel # Build examples and test code -cmake -B build -D BUILD_TESTING=1 -D CMAKE_BUILD_TYPE=Debug -cmake --build build -j +cmake -B build -D BUILD_TESTING=ON +cmake --build build # Run all test cases cd build @@ -131,8 +132,8 @@ ctest apt install libgtest-dev libgmock-dev libgflags-dev libfuse-dev libgsasl7-dev # Build examples and test code -cmake -B build -D BUILD_TESTING=1 -D CMAKE_BUILD_TYPE=Debug -cmake --build build -j +cmake -B build -D BUILD_TESTING=ON +cmake --build build # Run all test cases cd build @@ -149,8 +150,8 @@ ctest brew install gflags googletest gsasl # Build examples and test code -cmake -B build -D BUILD_TESTING=1 -D CMAKE_BUILD_TYPE=Debug -cmake --build build -j +cmake -B build -D BUILD_TESTING=ON +cmake --build build # Run all test cases cd build @@ -173,4 +174,4 @@ ctest | ENABLE_FUSE | OFF | Enable fuse. Requires `libfuse` | | ENABLE_SASL | OFF | Enable SASL. Requires `libgsasl` | | ENABLE_FSTACK_DPDK | OFF | Enable F-Stack and DPDK. Requires both. | -| ENABLE_EXTFS | OFF | Enable extfs. Requires `libe2fs` | \ No newline at end of file +| ENABLE_EXTFS | OFF | Enable extfs. Requires `libe2fs` |