Skip to content

Commit

Permalink
Set CMAKE_BUILD_PARALLEL_LEVEL to the num of CPU
Browse files Browse the repository at this point in the history
  • Loading branch information
beef9999 committed Aug 5, 2023
1 parent eba8ee0 commit ab2ad5a
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 87 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/ci.linux.arm.yml
Original file line number Diff line number Diff line change
@@ -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
73 changes: 73 additions & 0 deletions .github/workflows/ci.linux.x86.yml
Original file line number Diff line number Diff line change
@@ -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
52 changes: 0 additions & 52 deletions .github/workflows/ci.linux.yml

This file was deleted.

8 changes: 4 additions & 4 deletions .github/workflows/ci.macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 30 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ project(
include(FindPackageHandleStandardArgs)
include(CheckCXXCompilerFlag)
include(FetchContent)
include(ProcessorCount)
set(FETCHCONTENT_QUIET false)
find_package(PkgConfig REQUIRED)

Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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 ()
21 changes: 11 additions & 10 deletions doc/docs/introduction/how-to-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -75,7 +75,7 @@ cmake --build build -j
```bash
cd PhotonLibOS
cmake -B build
cmake --build build -j
cmake --build build
```

```mdx-code-block
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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` |
| ENABLE_EXTFS | OFF | Enable extfs. Requires `libe2fs` |

0 comments on commit ab2ad5a

Please sign in to comment.