Skip to content

Commit

Permalink
Some small improvements to gha (#363)
Browse files Browse the repository at this point in the history
* Improves the GHA overall performance

- Disable ccache for Windows as it doesn't work
- Add sscache for Windows
- Adjust some cmake flags to work with sscache

Signed-off-by: Renato Foot <[email protected]>
  • Loading branch information
Costallat authored May 3, 2022
1 parent 9da46a7 commit 44c8e82
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 77 deletions.
1 change: 0 additions & 1 deletion .github/workflows/analysis-codacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
name: Analysis - Codacy Security Scan

on:
pull_request:
push:
branches:
- main
Expand Down
22 changes: 11 additions & 11 deletions .github/workflows/analysis-codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@ on:
- '**.py'

env:
VCPKG_BUILD_TYPE: release
CMAKE_BUILD_PARALLEL_LEVEL: 2
MAKEFLAGS: '-j 2'
NODE_OPTIONS: ' --max-old-space-size=8192 '

jobs:
codeql:
name: CodeQL
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04]
language: ['cpp', 'python']
include:
- language: cpp
buildtype: linux-release

steps:
- name: Checkout repository
Expand All @@ -46,15 +49,12 @@ jobs:
sudo update-alternatives --set gcc /usr/bin/gcc-11
- name: CCache
if: ${{ matrix.language == 'cpp' }}
id: ccache
uses: actions/cache@v3
uses: hendrikmuhs/[email protected]
with:
path: $HOME/.ccache
key: ccache-${{ runner.os }}-RelWithDebInfo-${{ hashFiles('**/src') }}
max-size: "1G"
key: ccache-${{ matrix.os }}-${{ matrix.buildtype }}
restore-keys: |
ccache-${{ runner.os }}-RelWithDebInfo-
ccache-${{ runner.os }}-
ccache-${{ matrix.os }}
- name: Restore artifacts, or setup vcpkg (do not install any package)
if: ${{ matrix.language == 'cpp' }}
Expand All @@ -70,8 +70,8 @@ jobs:
if: ${{ matrix.language == 'cpp' }}
uses: lukka/run-cmake@v10
with:
configurePreset: linux-debug
buildPreset: linux-debug
configurePreset: ${{ matrix.buildtype }}
buildPreset: ${{ matrix.buildtype }}

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
27 changes: 11 additions & 16 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ on:
branches:
- main

env:
VCPKG_BUILD_TYPE: release
CMAKE_BUILD_PARALLEL_LEVEL: 2
MAKEFLAGS: '-j 2'

jobs:
docker:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -57,8 +52,8 @@ jobs:
with:
file: docker/server/Dockerfile
tags: ghcr.io/${{ github.repository }}:${{ steps.gitversion.outputs.semVer }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
cache-from: type=gha, scope=${{ github.workflow }}
cache-to: type=gha, scope=${{ github.workflow }}

- name: Build and push
id: docker_build
Expand All @@ -68,17 +63,17 @@ jobs:
file: docker/server/Dockerfile
push: true
tags: ghcr.io/${{ github.repository }}:${{ steps.gitversion.outputs.semVer }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
cache-from: type=gha, scope=${{ github.workflow }}
cache-to: type=gha, scope=${{ github.workflow }}

- name: Image digest
if: ${{ github.event_name == 'push' }}
run: echo ${{ steps.docker_build.outputs.digest }}

# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
# # Temp fix
# # https://github.com/docker/build-push-action/issues/252
# # https://github.com/moby/buildkit/issues/1896
# - name: Move cache
# run: |
# rm -rf /tmp/.buildx-cache
# mv /tmp/.buildx-cache-new /tmp/.buildx-cache
11 changes: 4 additions & 7 deletions .github/workflows/build-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ on:
- main

env:
VCPKG_BUILD_TYPE: release
CMAKE_BUILD_PARALLEL_LEVEL: 2
MAKEFLAGS: '-j 2'

Expand Down Expand Up @@ -45,14 +44,12 @@ jobs:
sudo update-alternatives --set gcc /usr/bin/gcc-11
- name: CCache
id: ccache
uses: actions/cache@v3
uses: hendrikmuhs/[email protected]
with:
path: $HOME/.ccache
key: ccache-${{ matrix.os }}-${{ matrix.buildtype }}-${{ hashFiles('**/src') }}
max-size: "1G"
key: ccache-${{ matrix.os }}-${{ matrix.buildtype }}
restore-keys: |
ccache-${{ matrix.os }}-${{ matrix.buildtype }}-
ccache-${{ matrix.os }}-
ccache-${{ matrix.os }}
- name: Restore artifacts and install vcpkg
uses: lukka/run-vcpkg@v10
Expand Down
16 changes: 12 additions & 4 deletions .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ on:
- main

env:
VCPKG_BUILD_TYPE: release
CMAKE_BUILD_PARALLEL_LEVEL: 2
MAKEFLAGS: '-j 2'

Expand All @@ -27,21 +26,30 @@ jobs:
packages: >
boost-asio boost-iostreams boost-system boost-filesystem
boost-variant boost-lockfree cryptopp curl jsoncpp
luajit libmariadb pugixml spdlog libzippp
luajit libmariadb pugixml spdlog libzippp sccache
- os: windows-2022
triplet: x64-windows
packages: >
boost-asio boost-iostreams boost-system boost-filesystem
boost-variant boost-lockfree cryptopp curl jsoncpp
luajit libmariadb pugixml spdlog libzippp
luajit libmariadb pugixml spdlog libzippp sccache
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: CCache
uses: hendrikmuhs/[email protected]
with:
max-size: "1G"
variant: "sccache"
key: ccache-${{ matrix.os }}-${{ matrix.buildtype }}
restore-keys: |
ccache-${{ matrix.os }}
- name: Remove Windows pre-installed MySQL
run: rm -r -fo C:/mysql*
if: contains( matrix.os, 'windows')
run: rm -r -fo C:/mysql*

- name: Restore artifacts and install vcpkg
uses: lukka/run-vcpkg@v10
Expand Down
17 changes: 16 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ include(LoggingHelper)
# *****************************************************************************
# Options
# *****************************************************************************
option(OPTIONS_ENABLE_CCACHE "Enable ccache" ON)
option(OPTIONS_ENABLE_CCACHE "Enable ccache" OFF)
option(OPTIONS_ENABLE_SCCACHE "Use sccache to speed up compilation process" OFF)
option(OPTIONS_ENABLE_IPO "Check and Enable interprocedural optimization (IPO/LTO)" ON)



# *****************************************************************************
# Options Code
# *****************************************************************************
Expand All @@ -62,6 +64,19 @@ if(OPTIONS_ENABLE_CCACHE)
endif()


# === SCCACHE ===
if(OPTIONS_ENABLE_SCCACHE)
find_program(SCCACHE_PATH sccache)
if(SCCACHE_PATH)
log_option_enabled("sccache")
set(CMAKE_C_COMPILER_LAUNCHER ${SCCACHE_PATH})
set(CMAKE_CXX_COMPILER_LAUNCHER ${SCCACHE_PATH})
else()
log_option_disabled("sccache")
endif()
endif()


# === IPO ===
option(OPTIONS_ENABLE_IPO "Check and Enable interprocedural optimization (IPO/LTO)" ON)
if(OPTIONS_ENABLE_IPO)
Expand Down
6 changes: 4 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"value": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"type": "FILEPATH"
},
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"OPTIONS_ENABLE_SCCACHE": "ON"
},
"architecture": {
"value": "x64",
Expand Down Expand Up @@ -45,7 +46,8 @@
"value": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"type": "FILEPATH"
},
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"OPTIONS_ENABLE_CCACHE": "ON"
},
"condition": {
"type": "equals",
Expand Down
86 changes: 51 additions & 35 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ if(ASAN_ENABLED)
log_option_enabled("asan")

if(MSVC)
target_compile_options(${PROJECT_NAME} PUBLIC /fsanitize=address)
target_compile_options(${PROJECT_NAME} PUBLIC /fsanitize=address)
else()
target_compile_options(${PROJECT_NAME} PUBLIC -fsanitize=address)
target_link_options(${PROJECT_NAME} PUBLIC -fsanitize=address)
target_compile_options(${PROJECT_NAME} PUBLIC -fsanitize=address)
target_link_options(${PROJECT_NAME} PUBLIC -fsanitize=address)
endif()
else()
log_option_disabled("asan")
Expand All @@ -100,7 +100,8 @@ if(CMAKE_BUILD_TYPE MATCHES Debug)
log_option_disabled("DEBUG LOG")
endif(CMAKE_BUILD_TYPE MATCHES Debug)

# Set for supress deprecated declarations (for GCC/GNU)

# Set for suppress deprecated declarations (for GCC/GNU)
# If not is GNUCXX_MINIMUM_VERSION, return message of error
if (CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
Expand All @@ -118,16 +119,17 @@ find_package(Threads REQUIRED)
find_package(libzippp REQUIRED)
find_package(cryptopp CONFIG REQUIRED)
find_package(Protobuf REQUIRED)

if (MSVC)
find_package(Boost 1.53.0 COMPONENTS system filesystem iostreams date_time REQUIRED)
find_package(Boost 1.53.0 COMPONENTS system filesystem iostreams date_time REQUIRED)
set(CRYPTOPP_LIBRARIES "cryptopp-static")
find_package(CURL REQUIRED)
find_package(jsoncpp REQUIRED)
find_package(MySQL REQUIRED)
find_package(PugiXML REQUIRED)
find_package(Threads REQUIRED)
else()
find_package(Boost REQUIRED COMPONENTS system filesystem iostreams date_time)
find_package(Boost REQUIRED COMPONENTS system filesystem iostreams date_time)
find_package(CURL CONFIG REQUIRED)
find_package(jsoncpp CONFIG REQUIRED)
find_package(pugixml CONFIG REQUIRED)
Expand Down Expand Up @@ -284,35 +286,49 @@ target_sources(${PROJECT_NAME}

if (MSVC)

target_include_directories(${PROJECT_NAME}
PRIVATE
${Boost_LIBRARY_DIRS}
${CMAKE_SOURCE_DIR}/src
${MYSQL_INCLUDE_DIR}
${LUA_INCLUDE_DIR}
${Boost_INCLUDE_DIRS}
${PUGIXML_INCLUDE_DIR}
${CRYPTOPP_INCLUDE_DIR}
${CURL_INCLUDE_DIRS}
${Protobuf_INCLUDE_DIRS}
${SPDLOG_INCLUDE_DIR}
$<TARGET_PROPERTY:jsoncpp_lib,INTERFACE_INCLUDE_DIRECTORIES>)

target_link_libraries(${PROJECT_NAME}
PRIVATE
${MYSQL_CLIENT_LIBS}
${LUA_LIBRARIES}
${Boost_LIBRARIES}
${PUGIXML_LIBRARIES}
${CRYPTOPP_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${CURL_LIBRARIES}
${Protobuf_LIBRARIES}
${SPDLOG_LIBRARY}
fmt::fmt
jsoncpp_lib
libzippp::libzippp
)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
endif()

target_compile_options(${PROJECT_NAME} PUBLIC /MP /FS /Zf )

target_include_directories(${PROJECT_NAME}
PRIVATE
${Boost_LIBRARY_DIRS}
${CMAKE_SOURCE_DIR}/src
${MYSQL_INCLUDE_DIR}
${LUA_INCLUDE_DIR}
${Boost_INCLUDE_DIRS}
${PUGIXML_INCLUDE_DIR}
${CRYPTOPP_INCLUDE_DIR}
${CURL_INCLUDE_DIRS}
${Protobuf_INCLUDE_DIRS}
${SPDLOG_INCLUDE_DIR}
$<TARGET_PROPERTY:jsoncpp_lib,INTERFACE_INCLUDE_DIRECTORIES>
)

target_link_libraries(${PROJECT_NAME}
PRIVATE
${MYSQL_CLIENT_LIBS}
${LUA_LIBRARIES}
${Boost_LIBRARIES}
${PUGIXML_LIBRARIES}
${CRYPTOPP_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${CURL_LIBRARIES}
${Protobuf_LIBRARIES}
${SPDLOG_LIBRARY}
fmt::fmt
jsoncpp_lib
libzippp::libzippp
)

else()

Expand Down

0 comments on commit 44c8e82

Please sign in to comment.