Skip to content

Commit 18b00c5

Browse files
authored
Merge pull request #17 from elbeno/update-ci
Update CI infrastructure
2 parents 1fcea8c + d57fb31 commit 18b00c5

File tree

119 files changed

+4277
-4954
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+4277
-4954
lines changed

.clang-format

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
BasedOnStyle: LLVM
2+
IndentWidth: 4
3+
4+
IncludeBlocks: Regroup
5+
IncludeCategories:
6+
- Regex: '^".*'
7+
Priority: 1
8+
- Regex: '^<(safe)/.*'
9+
Priority: 2
10+
- Regex: '^<(boost|catch2|fmt|gmock|gtest|rapidcheck)/.*'
11+
Priority: 3
12+
- Regex: '<.*'
13+
Priority: 4
14+
15+
QualifierAlignment: Custom
16+
QualifierOrder: ['constexpr', 'static', 'inline', 'type', 'const', 'volatile']

.clang-tidy

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
Checks: >
3+
boost-use-to-string,
4+
bugprone-*,
5+
-bugprone-easily-swappable-parameters,
6+
clang-diagnostic-*,
7+
clang-analyzer-*,
8+
cppcoreguidelines-*,
9+
-cppcoreguidelines-avoid-magic-numbers,
10+
-cppcoreguidelines-avoid-non-const-global-variables,
11+
-cppcoreguidelines-macro-usage,
12+
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
13+
google-build-explicit-make-pair,
14+
google-default-arguments,
15+
google-explicit-constructor,
16+
google-readability-casting,
17+
google-runtime-int,
18+
hicpp-signed-bitwise,
19+
misc-misplaced-const,
20+
misc-non-copyable-objects,
21+
misc-redundant-expression,
22+
misc-static-assert,
23+
misc-throw-by-value-catch-by-reference,
24+
misc-uniqueptr-reset-release,
25+
modernize-*,
26+
performance-*,
27+
portability-*,
28+
readability-*,
29+
-readability-identifier-length,
30+
-readability-identifier-naming,
31+
-readability-magic-numbers,
32+
-readability-named-parameter,
33+
-readability-qualified-auto,
34+
-readability-uppercase-literal-suffix
35+
WarningsAsErrors: '*'
36+
HeaderFilterRegex: ''
37+
AnalyzeTemporaryDtors: false
38+
FormatStyle: file
39+
...

.cmake-format.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
format:
2+
tab_size: 4
3+
line_width: 80

.github/workflows/unit_tests.yml

Lines changed: 184 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,214 @@
11
name: Unit Tests
22

33
on:
4+
workflow_dispatch:
5+
merge_group:
46
push:
57
branches: [ main ]
68
pull_request:
79
branches: [ main ]
810

911
env:
10-
BUILD_TYPE: Debug
12+
DEBIAN_FRONTEND: noninteractive
13+
CMAKE_GENERATOR: Ninja
14+
15+
concurrency:
16+
group: ${{ github.head_ref || github.run_id }}
17+
cancel-in-progress: true
1118

1219
jobs:
1320
build_and_test:
1421
runs-on: ubuntu-22.04
1522
strategy:
1623
fail-fast: false
1724
matrix:
18-
compiler:
19-
- name: clang-16
25+
compiler: [clang, gcc]
26+
version: [12, 13, 14, 15, 16]
27+
cxx_standard: [20]
28+
stdlib: [libstdc++, libc++]
29+
build_type: [Debug]
30+
include:
31+
- compiler: clang
32+
cc: "clang"
33+
cxx: "clang++"
34+
- version: 16
35+
compiler: clang
2036
install: wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && sudo ./llvm.sh 16
21-
cc: " /usr/lib/llvm-16/bin/clang"
22-
cxx: "/usr/lib/llvm-16/bin/clang++"
23-
- name: clang-15
24-
install: wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && sudo ./llvm.sh 15
25-
cc: " /usr/lib/llvm-15/bin/clang"
26-
cxx: "/usr/lib/llvm-15/bin/clang++"
27-
- name: clang-14
28-
install: wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && sudo ./llvm.sh 14
29-
cc: " /usr/lib/llvm-14/bin/clang"
30-
cxx: "/usr/lib/llvm-14/bin/clang++"
31-
- name: clang-13
32-
install: wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && sudo ./llvm.sh 13
33-
cc: " /usr/lib/llvm-13/bin/clang"
34-
cxx: "/usr/lib/llvm-13/bin/clang++"
35-
- name: clang-12
36-
install: sudo apt update && sudo apt-get install -y clang-12
37-
cc: " /usr/lib/llvm-12/bin/clang"
38-
cxx: "/usr/lib/llvm-12/bin/clang++"
39-
- name: gcc-13
37+
toolchain_root: "/usr/lib/llvm-16"
38+
- version: 16
39+
compiler: clang
40+
stdlib: libc++
41+
install: wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && sudo ./llvm.sh 16 && sudo apt install -y libc++-16-dev libc++abi-16-dev
42+
- version: 15
43+
compiler: clang
44+
install: sudo apt update && sudo apt install -y clang-15
45+
toolchain_root: "/usr/lib/llvm-15"
46+
- version: 15
47+
compiler: clang
48+
stdlib: libc++
49+
install: sudo apt update && sudo apt install -y clang-15 libc++-15-dev libc++abi-15-dev
50+
- version: 14
51+
compiler: clang
52+
install: sudo apt update && sudo apt install -y clang-14
53+
toolchain_root: "/usr/lib/llvm-14"
54+
- version: 14
55+
compiler: clang
56+
stdlib: libc++
57+
install: sudo apt update && sudo apt install -y clang-14 libc++-14-dev libc++abi-14-dev
58+
- version: 13
59+
compiler: gcc
4060
install: sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test && sudo apt update && sudo apt-get install -y gcc-13 g++-13
41-
cc: "/usr/bin/gcc-13"
42-
cxx: "/usr/bin/g++-13"
43-
- name: gcc-12
44-
install: sudo apt update && sudo apt-get install -y gcc-12 g++-12
45-
cc: "/usr/bin/gcc-12"
46-
cxx: "/usr/bin/g++-12"
47-
- name: gcc-11
48-
install: sudo apt update && sudo apt-get install -y gcc-11 g++-11
49-
cc: "/usr/bin/gcc-11"
50-
cxx: "/usr/bin/g++-11"
51-
- name: gcc-10
52-
install: sudo apt update && sudo apt-get install -y gcc-10 g++-10
53-
cc: "/usr/bin/gcc-10"
54-
cxx: "/usr/bin/g++-10"
55-
56-
61+
toolchain_root: "/usr"
62+
cc: "gcc-13"
63+
cxx: "g++-13"
64+
- version: 12
65+
compiler: gcc
66+
install: sudo apt update && sudo apt install -y gcc-12
67+
toolchain_root: "/usr"
68+
cc: "gcc-12"
69+
cxx: "g++-12"
70+
exclude:
71+
- compiler: gcc
72+
version: 16
73+
- compiler: gcc
74+
version: 15
75+
- compiler: gcc
76+
version: 14
77+
- compiler: clang
78+
version: 13
79+
- compiler: clang
80+
version: 12
81+
- compiler: gcc
82+
stdlib: libc++
83+
5784
steps:
58-
- name: install support tools
59-
run: sudo apt update && DEBIAN_FRONTEND=noninteractive TZ=America/Los_Angeles sudo apt-get install -y git wget software-properties-common gnupg cmake lsb-release libstdc++-10-dev ninja-build
85+
- uses: actions/checkout@v3
86+
87+
- name: Install build tools
88+
run: |
89+
${{ matrix.install }}
90+
sudo apt install -y ninja-build
91+
92+
- name: Configure CMake
93+
env:
94+
CC: ${{matrix.toolchain_root}}/bin/${{matrix.cc}}
95+
CXX: ${{matrix.toolchain_root}}/bin/${{matrix.cxx}}
96+
CXX_STANDARD: ${{matrix.cxx_standard}}
97+
CXX_STDLIB: ${{matrix.stdlib}}
98+
run: cmake -B ${{github.workspace}}/build -DCMAKE_TOOLCHAIN_FILE=${{github.workspace}}/toolchains/${{matrix.compiler}}.cmake -DCMAKE_BUILD_TYPE=${{matrix.build_type}}
99+
100+
- name: Build Unit Tests
101+
run: cmake --build ${{github.workspace}}/build --config ${{matrix.build_type}} -v -t build_unit_tests
60102

61-
- name: install compiler
62-
run: ${{ matrix.compiler.install }}
103+
- name: Test
104+
working-directory: ${{github.workspace}}/build
105+
run: ctest -j $(nproc) -C ${{matrix.build_type}}
63106

107+
quality_checks_pass:
108+
runs-on: ubuntu-22.04
109+
steps:
64110
- uses: actions/checkout@v3
65111

112+
- name: Install build tools
113+
run: |
114+
wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && sudo ./llvm.sh 16
115+
sudo apt install -y ninja-build clang-tidy-16 clang-format-16
116+
117+
- name: Install cmake-format
118+
run: |
119+
pip3 install --upgrade pip
120+
pip3 install pyyaml cmake-format
121+
66122
- name: Configure CMake
67123
env:
68-
CC: ${{ matrix.compiler.cc }}
69-
CXX: ${{ matrix.compiler.cxx }}
70-
CXX_STANDARD: ${{ matrix.compiler.cxx_standard }}
71-
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
124+
CC: "/usr/lib/llvm-16/bin/clang"
125+
CXX: "/usr/lib/llvm-16/bin/clang++"
126+
CXX_STANDARD: 20
127+
run: cmake -B ${{github.workspace}}/build
72128

73-
- name: Build and Run Unit Tests
74-
run: cmake --build ${{github.workspace}}/build --target unit_tests
129+
- name: Run quality checks
130+
run: cmake --build ${{github.workspace}}/build -t quality
75131

132+
sanitize:
133+
runs-on: ubuntu-22.04
134+
strategy:
135+
fail-fast: false
136+
matrix:
137+
sanitizer: [undefined, address, thread]
76138

139+
steps:
140+
- uses: actions/checkout@v3
77141

78-
quality_checks_pass:
79-
runs-on: ubuntu-20.04
80-
needs: build_and_test
142+
- name: Install build tools
143+
run: |
144+
wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && sudo ./llvm.sh 16
145+
sudo apt install -y ninja-build
146+
147+
- name: Configure CMake
148+
env:
149+
CC: "/usr/lib/llvm-16/bin/clang"
150+
CXX: "/usr/lib/llvm-16/bin/clang++"
151+
CXX_STANDARD: 20
152+
SANITIZERS: ${{matrix.sanitizer}}
153+
run: cmake -B ${{github.workspace}}/build
154+
155+
- name: Build Unit Tests
156+
run: cmake --build ${{github.workspace}}/build -t unit_tests
157+
158+
valgrind:
159+
runs-on: ubuntu-22.04
160+
steps:
161+
- uses: actions/checkout@v3
162+
163+
- name: Install build tools
164+
run: sudo apt update && sudo apt install -y gcc-12 ninja-build valgrind
165+
166+
- name: Configure CMake
167+
env:
168+
CC: "/usr/bin/gcc-12"
169+
CXX: "/usr/bin/g++-12"
170+
CXX_STANDARD: 20
171+
run: cmake -B ${{github.workspace}}/build
172+
173+
- name: Build Unit Tests
174+
run: cmake --build ${{github.workspace}}/build -t build_unit_tests
175+
176+
- name: Test
177+
working-directory: ${{github.workspace}}/build
178+
run: |
179+
ctest -j $(nproc) -E EXPECT_FAIL -T memcheck
180+
181+
LOGFILE=$(ls ./Testing/Temporary/LastDynamicAnalysis_*.log)
182+
FAILSIZE=$(du -c ./Testing/Temporary/MemoryChecker.* | tail -1 | cut -f1)
183+
echo "<details>" >> $GITHUB_STEP_SUMMARY
184+
185+
echo "<summary>" >> $GITHUB_STEP_SUMMARY
186+
if [ $FAILSIZE != "0" ]; then
187+
echo "Failing tests:" | tee -a $GITHUB_STEP_SUMMARY
188+
else
189+
echo "No failing tests" >> $GITHUB_STEP_SUMMARY
190+
fi
191+
echo "</summary>" >> $GITHUB_STEP_SUMMARY
192+
193+
for f in ./Testing/Temporary/MemoryChecker.*
194+
do
195+
if [ -s $f ]; then
196+
FILENAME=$(cd $(dirname $f) && pwd)/$(basename $f)
197+
TEST_COMMAND=$(grep $FILENAME $LOGFILE)
198+
echo "" | tee -a $GITHUB_STEP_SUMMARY
199+
echo "========================================"
200+
echo $TEST_COMMAND | tee -a $GITHUB_STEP_SUMMARY
201+
echo "--------------------"
202+
cat $f
203+
fi
204+
done
205+
206+
echo "</details>" >> $GITHUB_STEP_SUMMARY
207+
test $FAILSIZE = "0"
208+
209+
merge_ok:
210+
runs-on: ubuntu-22.04
211+
needs: [build_and_test, quality_checks_pass, sanitize, valgrind]
81212
steps:
82-
- name: Say Hello
83-
run: echo "Hello!"
213+
- name: Enable merge
214+
run: echo "OK to merge!"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
/cmake-build-*
77
.idea
88
.vscode
9+
.cache

.gitmodules

Whitespace-only changes.

CMakeLists.txt

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
1-
cmake_minimum_required(VERSION 3.16)
2-
project(safe_arithmetic LANGUAGES CXX)
1+
cmake_minimum_required(VERSION 3.25)
32

4-
set(CMAKE_CXX_STANDARD 20)
3+
project(safe_arithmetic LANGUAGES CXX)
54

6-
include(cmake/CPM.cmake)
5+
if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
6+
message(
7+
FATAL_ERROR
8+
"In-source builds are a bad idea. Please make a build directory instead."
9+
)
10+
endif()
711

8-
include(cmake/libraries.cmake)
912
include(cmake/dependencies.cmake)
10-
include(cmake/test.cmake)
11-
include(cmake/sanitizers.cmake)
12-
include(CTest)
13-
enable_testing()
14-
15-
add_versioned_package("gh:boostorg/mp11#boost-1.80.0")
13+
include(cmake/libraries.cmake)
14+
include(cmake/quality.cmake)
1615

17-
add_subdirectory(include)
18-
add_subdirectory(test)
16+
add_versioned_package("gh:boostorg/mp11#boost-1.83.0")
1917

18+
add_library(safe_arithmetic INTERFACE)
19+
target_compile_features(safe_arithmetic INTERFACE cxx_std_20)
20+
target_include_directories(safe_arithmetic INTERFACE include)
21+
target_link_libraries(safe_arithmetic INTERFACE boost_mp11)
2022

23+
if(PROJECT_IS_TOP_LEVEL)
24+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
25+
# clang_tidy_interface(safe_arithmetic)
26+
add_subdirectory(test)
27+
endif()

0 commit comments

Comments
 (0)