-
Notifications
You must be signed in to change notification settings - Fork 1
400 lines (344 loc) · 14.3 KB
/
cmake.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
name: C++ CI
on:
push:
branches: ['*'] # NOTE: replace/update with appropriate branch name(s)
tags: ['*']
pull_request:
branches: ['*'] # NOTE: replace/update with appropriate branch name(s)
workflow_dispatch:
inputs:
build_type:
description: Build type
required: false
default: 'Debug'
type: choice
options:
- Debug
- Release
- RelWithDebInfo
- MinSizeRel
env:
BUILD_TYPE: ${{ inputs.build_type || 'Debug' }}
# NOTE: update executable name if it is changed in CMakeLists.txt
EXECUTABLE_NAME: "doodle_jump"
INPUT_FILENAME: "tastatura.txt"
BUILD_DIR: "build"
EXT_DIR: "ext"
BIN_DIR: "bin"
APP_WINDOW: "My Window"
defaults:
run:
# Use a bash shell, so we can use the same syntax for environment variable
# access regardless of the host operating system
# https://github.com/saxbophone/CPP20-Cross-Platform-Template
shell: bash
jobs:
cppcheck:
name: "Cppcheck"
runs-on: ubuntu-22.04
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Install cppcheck
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends cppcheck
- name: Install Linux Dependencies
if: runner.os == 'Linux'
uses: ./.github/actions/install-linux-deps
# The flag CMAKE_EXPORT_COMPILE_COMMANDS generates compile_commands.json
# which is used by cppcheck and clang-tidy
- name: Configure CMake
uses: ./.github/actions/configure-cmake
with:
custom_flags: '-DCMAKE_EXPORT_COMPILE_COMMANDS=ON'
- name: Cppcheck
run: |
cppcheck --enable=all \
--inline-suppr \
--project="${BUILD_DIR}"/compile_commands.json \
-i"${BUILD_DIR}" --suppress='*:"${BUILD_DIR}"/*' \
-i"${EXT_DIR}" --suppress='*:"${EXT_DIR}"/*' \
--suppress=missingIncludeSystem \
--suppress=unmatchedSuppression \
--suppress=useStlAlgorithm \
--error-exitcode=1
clang-tidy:
name: "Clang-Tidy"
runs-on: ubuntu-22.04
env:
CC: clang-14
CXX: clang++-14
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Install clang-tidy
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends clang-tidy
- name: Install Linux Dependencies
if: runner.os == 'Linux'
uses: ./.github/actions/install-linux-deps
- name: Configure CMake
uses: ./.github/actions/configure-cmake
with:
custom_flags: '-DCMAKE_EXPORT_COMPILE_COMMANDS=ON'
- name: Clang-Tidy
continue-on-error: true
# clang-tidy is not able to follow symbolic links: https://bugs.llvm.org/show_bug.cgi?id=47460
# need to use | as sed separator because / is used in paths
run: |
sed -i "s|$(which ${CXX})|$(realpath $(which ${CXX}))|g" "${BUILD_DIR}"/compile_commands.json
cat "${BUILD_DIR}"/compile_commands.json |
jq -r '.[] | .file' | # select source file paths from CMake project; -r to strip quotes
grep -v "/${BUILD_DIR}/_deps/" | # ignore external dependencies
xargs clang-tidy -p "${BUILD_DIR}"
build:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
timeout-minutes: 10
permissions:
contents: write
env:
CC: ${{ matrix.c }}
CXX: ${{ matrix.cxx }}
# NOTE: also update in CMakeLists FetchContent
SFML_VERSION: "2023-06-21-2.6.0"
# NOTE: replace with another version if this one does not work
# For more versions, see https://winlibs.com or
# https://github.com/brechtsanders/winlibs_mingw/releases/
MINGW_CACHE_KEY: "gcc-12.3-msvcrt-r1"
MINGW_VER: "12.3.0-16.0.4-11.0.0-msvcrt-r1/winlibs-x86_64-posix-seh-gcc-12.3.0-mingw-w64msvcrt-11.0.0-r1.7z"
# Example:
# MINGW_CACHE_KEY: "gcc-13.2-msvcrt-r1"
# MINGW_VER: "13.2.0-16.0.6-11.0.1-msvcrt-r1/winlibs-x86_64-posix-seh-gcc-13.2.0-mingw-w64msvcrt-11.0.1-r1.7z"
strategy:
fail-fast: false
matrix:
include:
# - os: ubuntu-22.04
# c: clang-14
# cxx: clang++-14
# name: "MSan: Ubuntu 22.04 Clang 14"
# cmake_flags: -DBUILD_SHARED_LIBS=FALSE
# cmake_generator: Ninja
# # This env runs memory sanitizers
# runs_msan: false
- os: ubuntu-22.04
c: gcc-12
cxx: g++-12
name: "ASan: Ubuntu 22.04 GCC 12"
cmake_flags: -DBUILD_SHARED_LIBS=FALSE
cmake_generator: Ninja
# This env runs address sanitizers
runs_asan: true
- os: ubuntu-22.04
c: gcc-11
cxx: g++-11
name: "Valgrind: Ubuntu 22.04 GCC 11"
cmake_flags: -DBUILD_SHARED_LIBS=FALSE
cmake_generator: Ninja
# This env runs valgrind
runs_valgrind: true
- os: macos-12
c: clang
cxx: clang++
name: "ASan: macOS 12 Apple Clang 14"
cmake_flags: -DSFML_BUILD_FRAMEWORKS=FALSE -DSFML_DEPENDENCIES_INSTALL_PREFIX=$GITHUB_WORKSPACE/artifacts -DBUILD_SHARED_LIBS=FALSE
# cmake_generator:
# This env runs address sanitizers
# runs_asan: true
# - os: macos-12
# c: gcc-12
# cxx: g++-12
# name: "macOS 12 GCC 12"
# cmake_flags:
# cmake_generator: Ninja
- os: windows-2022
c: cl
cxx: cl
name: "ASan: Windows 2022 MSVC 19.35"
cmake_flags: -DBUILD_SHARED_LIBS=TRUE
# cmake_generator: Ninja
# This env runs address sanitizers
# runs_asan: true
- os: windows-2022
c: gcc
cxx: g++
name: "Windows 2022 MinGW GCC 12"
cmake_flags: -DBUILD_SHARED_LIBS=TRUE
cmake_generator: Ninja
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Prepare env
run: |
echo ${GITHUB_WORKSPACE}
mkdir ${GITHUB_WORKSPACE}/artifacts
- name: Set timestamp and zip name
run: |
echo "TIMESTAMP=$(date +%Y-%m-%d-%H-%M-%S)" >> ${GITHUB_ENV}
# use the full name as prefix: {user_name}_{repo_name} (replace / with _)
echo "ZIP_NAME=$(echo "${GITHUB_REPOSITORY}_${{ env.BUILD_TYPE }}_${{ matrix.os }}_${{ matrix.cxx }}" | sed 's|/|_|')" >> ${GITHUB_ENV}
# or use only the repo name (github does not have a predefined environment variable for this)
# the regex splits by / and keeps everything after / without the / character
# echo "ZIP_NAME=$(echo "${GITHUB_REPOSITORY}_${{ env.BUILD_TYPE }}_${{ matrix.os }}_${{ matrix.cxx }}" | sed -E 's|.+/(.+)|\1|')" >> ${GITHUB_ENV}
# Common Linux dependencies
- name: Install common Linux Dependencies
if: runner.os == 'Linux'
uses: ./.github/actions/install-linux-deps
- name: Install Linux Dependencies
if: runner.os == 'Linux'
run: |
# sudo apt-get update
sudo apt-get install --no-install-recommends ninja-build xdotool \
openbox \
libxkbcommon-x11-0 \
libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 libxcb-xfixes0
# - name: Install ninja and libc++ (Linux Clang 14)
# if: runner.os == 'Linux' && matrix.runs_msan == true
# run: |
# # sudo apt-get update
# sudo apt-get install --no-install-recommends ninja-build libc++-14-dev libc++abi-14-dev
- name: Install ninja (Windows)
if: runner.os == 'Windows'
run: |
choco install ninja
- name: Install valgrind
if: runner.os == 'Linux' && matrix.runs_valgrind == true
run: |
# sudo apt-get update
sudo apt-get install --no-install-recommends valgrind
# - name: Cache tools
# uses: actions/cache@v3
# if: runner.os == 'Linux' && matrix.runs_msan == true
# id: cache-tools
# with:
# path: tools
# key: tools-clang-stdlib-msan
- name: Configure CMake
uses: ./.github/actions/configure-cmake
with:
custom_flags: ${{ matrix.cmake_flags }}
warnings_as_errors: 'ON'
- name: Build
# Execute the build using N jobs (-jN)
run: cmake --build "${BUILD_DIR}" --config ${BUILD_TYPE} -j6
- name: Install
# Use CMake to "install" build artifacts (only interested in CMake registered targets) to our custom artifacts directory
run: cmake --install "${BUILD_DIR}" --config ${BUILD_TYPE} --prefix artifacts
- name: Move artifacts
run: |
mkdir ${{ env.ZIP_NAME }}
mv artifacts/${{ env.BIN_DIR }}/* ${{ env.ZIP_NAME }}
ls -la ${{ env.ZIP_NAME }}
cp "${INPUT_FILENAME}" ${{ env.ZIP_NAME }}
- name: Copy missing dylibs
if: runner.os == 'macOS' && matrix.cxx == 'clang++'
run: |
mkdir lib
cp /Library/Developer/CommandLineTools/usr/lib/clang/14.0.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib lib
install_name_tool -change @rpath/libclang_rt.asan_osx_dynamic.dylib @executable_path/lib/libclang_rt.asan_osx_dynamic.dylib ${{ env.ZIP_NAME }}/${{ env.EXECUTABLE_NAME }}
ls -1 artifacts/lib | grep framework | xargs -I% ls artifacts/lib/%/Versions/A | grep -v "Resources" | xargs -I% cp artifacts/lib/%.framework/% lib
ls -1 artifacts/lib | grep framework | xargs -I% ls artifacts/lib/%/Versions/A | grep -v "Resources" | xargs -I% install_name_tool -change @rpath/../Frameworks/%.framework/Versions/A/% @executable_path/lib/% ${{ env.ZIP_NAME }}/${{ env.EXECUTABLE_NAME }}
mv lib ${{ env.ZIP_NAME }}/
- name: Copy missing dlls
if: runner.os == 'Windows' && matrix.cxx == 'cl'
run: |
if [[ "${BUILD_TYPE}" =~ "Deb" ]]; then
# runtime debug DLLs
cp "$(which ucrtbased.dll)" \
"$(which VCRUNTIME140_1D.dll)" \
"$(which MSVCP140D.dll)" \
"$(which VCRUNTIME140D.dll)" \
${GITHUB_WORKSPACE}/${{ env.ZIP_NAME }}
# sanitizers DLLs
vcver=$(cat "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/Microsoft.VCToolsVersion.default.txt")
vcbindir="C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/${vcver}/bin/Hostx64/x64/"
cp "${vcbindir}/clang_rt.asan_dynamic-x86_64.dll" \
"${vcbindir}/clang_rt.asan_dbg_dynamic-x86_64.dll" \
${GITHUB_WORKSPACE}/${{ env.ZIP_NAME }}
fi
# runtime release DLLs
if [[ "${BUILD_TYPE}" =~ "Rel" ]]; then
cp "$(which ucrtbase.dll)" \
"$(which VCRUNTIME140_1.dll)" \
"$(which MSVCP140.dll)" \
"$(which VCRUNTIME140.dll)" \
${GITHUB_WORKSPACE}/${{ env.ZIP_NAME }}
fi
- name: Copy stdlib (MinGW)
if: runner.os == 'Windows' && matrix.cxx == 'g++'
# static linking might not work with MinGW, might be easier this way
run: |
cp $(which libstdc++-6.dll) \
$(which libgcc_s_seh-1.dll) \
$(which libwinpthread-1.dll) \
${GITHUB_WORKSPACE}/${{ env.ZIP_NAME }}
- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ env.ZIP_NAME }}_${{ env.TIMESTAMP }}
path: ${{ env.ZIP_NAME }}
retention-days: 30
# - name: Setup memory sanitizer
# if: runner.os == 'Linux' && matrix.runs_msan == true && steps.cache-tools.outputs.cache-hit != 'true'
# run: |
# mkdir -p tools
# cd tools
# git clone --depth=1 --branch=llvmorg-14.0.6 https://github.com/llvm/llvm-project
# cd llvm-project
# mkdir build; cd build
# sudo ln -s -f /usr/bin/$CC /usr/bin/clang
# sudo ln -s -f /usr/bin/$CXX /usr/bin/clang++
# cmake -GNinja ../llvm \
# -DCMAKE_BUILD_TYPE=Release \
# -DLLVM_ENABLE_PROJECTS="libcxx;libcxxabi" \
# -DCMAKE_C_COMPILER=clang \
# -DCMAKE_CXX_COMPILER=clang++ \
# -DLLVM_USE_SANITIZER=MemoryWithOrigins \
# -DCMAKE_BUILD_WITH_INSTALL_RPATH=true
# cmake --build . -j6 -- cxx cxxabi
- name: Make scripts executable
if: runner.os == 'Linux'
run: |
chmod +x scripts/*
# chmod +x scripts/run_sanitizers.sh scripts/run_valgrind.sh
- name: Sanitizers
if: runner.os == 'Linux' && matrix.runs_asan == true
continue-on-error: true
env:
ASAN_OPTIONS: halt_on_error=0
EXECUTABLE_NAME: ${{ env.EXECUTABLE_NAME }}
run: |
xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" ./scripts/run_sanitizers.sh || true
working-directory: ${{github.workspace}}
- name: Valgrind
if: runner.os == 'Linux' && matrix.runs_valgrind == true
continue-on-error: true
env:
EXECUTABLE_NAME: ${{ env.EXECUTABLE_NAME }}
run: |
xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" ./scripts/run_valgrind.sh || true
working-directory: ${{github.workspace}}
- name: Set Tag Name
if: startsWith(github.ref, 'refs/tags/')
# trim prefix from ref to get tag name
run: echo "TAG_NAME=${GITHUB_REF#'refs/tags/'}" >> ${GITHUB_ENV}
- name: Add tag to folder name
if: startsWith(github.ref, 'refs/tags/')
run: |
mv ${{ env.ZIP_NAME }} ${{ env.ZIP_NAME }}_${{ env.TAG_NAME }}
- name: Archive Release
uses: thedoctor0/zip-release@master
if: startsWith(github.ref, 'refs/tags/')
with:
type: 'zip'
path: ${{ env.ZIP_NAME }}_${{ env.TAG_NAME }}
filename: ${{ env.ZIP_NAME }}_${{ env.TAG_NAME }}.zip
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
${{ env.ZIP_NAME }}_${{ env.TAG_NAME }}.zip