Skip to content

Commit

Permalink
Add CI (#1)
Browse files Browse the repository at this point in the history
Run cmake and build for multiple platforms and compilers, show ccache statistics (no checks yet)
  • Loading branch information
mradugin authored Jul 14, 2024
1 parent 2027e4a commit 47c2044
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 1 deletion.
104 changes: 104 additions & 0 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@

name: CMake with ccache on multiple platforms and compilers

on:
push:
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ${{ matrix.sys.os }}

strategy:
fail-fast: false

matrix:
sys:
# Compilation failes with the following error: ccache: error: Could not find compiler "D:\a\_temp\msys64\clang64\bin\clang++.exe" in PATH
# - { os: windows-latest, shell: 'msys2 {0}', generator: Ninja }
- { os: windows-latest, shell: 'msys2 {0}', generator: Unix Makefiles }

- { os: ubuntu-latest, shell: bash, generator: Ninja }
- { os: ubuntu-latest, shell: bash, generator: Unix Makefiles }

- { os: macos-latest, shell: bash, generator: Ninja }
- { os: macos-latest, shell: bash, generator: Unix Makefiles }

compiler:
- { c: gcc, cpp: g++, msys: mingw64 }
- { c: clang, cpp: clang++, msys: clang64 }
build_type: [Debug]

include:
# Behaves weird on github runner, either because of Windows Server, VS Enterprise, or sources being on D:\ drive, i.e.
# Objects from first build get into cache, but second build compiler calls do not get into hits or miss statistics, while
# it can be seen that ccache is being called. On the other hand this configuration has been tested on multiple machines
# with Windows 10 Pro, VS Community edition and source stored on C:\ drive.
- sys: { os: windows-latest, shell: bash, generator: Visual Studio 17 2022 }
compiler: { c: cl, cpp: cl }
build_type: Debug
- sys: { os: macos-latest, shell: bash, generator: Xcode }
compiler: { c: clang, cpp: clang++ }
build_type: Debug

defaults:
run:
shell: ${{ matrix.sys.shell }}

steps:
- uses: actions/checkout@v4

- name: ccache
uses: hendrikmuhs/ccache-action@v1.2.13
with:
restore: false
save: false
verbose: 2
variant: ccache

- name: Install ninja (ubuntu)
if: ${{ matrix.sys.os == 'ubuntu-latest' && matrix.sys.generator == 'Ninja' }}
run: |
sudo apt update
sudo apt -y install ninja-build
- name: Install ninja (macos)
if: ${{ matrix.sys.os == 'macos-latest' && matrix.sys.generator == 'Ninja' }}
run: |
brew install ninja
- name: Install MSYS2 (windows)
if: ${{ matrix.sys.shell == 'msys2 {0}' }}
uses: msys2/setup-msys2@v2
with:
msystem: ${{ matrix.compiler.msys }}
update: true
install: >-
make
ccache
pacboy: >-
toolchain:p
cmake:p
ninja:p
- name: Set reusable strings
id: strings
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
echo "source-dir=${{ github.workspace }}/example" >> "$GITHUB_OUTPUT"
- name: Configure CMake
run: |
cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_CXX_COMPILER=${{ matrix.compiler.cpp }} -DCMAKE_C_COMPILER=${{ matrix.compiler.c }} -S "${{ steps.strings.outputs.source-dir }}" -B "${{ steps.strings.outputs.build-output-dir }}" -G "${{matrix.sys.generator}}"
- name: Build (empty cache)
run: |
cmake --build "${{ steps.strings.outputs.build-output-dir }}" --config ${{ matrix.build_type }} --verbose
ccache --show-stats
- name: Build (cached)
run: |
cmake --build "${{ steps.strings.outputs.build-output-dir }}" --config ${{ matrix.build_type }} --target clean --verbose
cmake --build "${{ steps.strings.outputs.build-output-dir }}" --config ${{ matrix.build_type }} --verbose
ccache --show-stats
1 change: 1 addition & 0 deletions Findccache.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ if (CCACHE_FOUND)
"CLToolExe=cl.exe"
"CLToolPath=${CMAKE_BINARY_DIR}"
"UseMultiToolTask=true"
"UseStructuredOutput=false"
)
elseif(CMAKE_GENERATOR MATCHES "Ninja" OR CMAKE_GENERATOR MATCHES "Unix Makefiles")
# Support Unix Makefiles and Ninja
Expand Down
2 changes: 1 addition & 1 deletion example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ set(CCACHE_PROGRAMS "ccache;sccache;buildcache" CACHE STRING _ FORCE)

find_package(ccache)

add_executable(${PROJECT_NAME} main.cpp)
add_executable(${PROJECT_NAME} main.cpp module.cpp)
2 changes: 2 additions & 0 deletions example/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

int main(int argc, char* argv[])
{
(void)argc;
(void)argv;
return 0;
}
4 changes: 4 additions & 0 deletions example/module.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
void module(int a)
{
(void)a;
}

0 comments on commit 47c2044

Please sign in to comment.