Repository navigation
510 lines (478 loc) · 19.7 KB
/
Copy pathc-cpp.yml
File metadata and controls
510 lines (478 loc) · 19.7 KB
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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
name: C/C++ CI
on:
push:
branches: ["main"]
# Release tags run the full matrix on the exact tagged commit, which may
# not be the branch head the last main push validated.
tags: ["v*"]
pull_request:
branches: ["main"]
jobs:
# Every step after the first carries `if: !cancelled()`: steps stop at the
# first failure by default, so dropping it hides a second independent
# problem until the next round-trip.
source-hygiene:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
# Every build job but the MSVC one uses libstdc++, whose <ranges> pulls
# in std::move, std::pair and every type trait, so a header missing
# <utility> or <type_traits> compiles across the whole matrix and breaks
# only in a consumer's translation unit.
- name: "Every header includes what provides the std:: symbols it names"
run: python3 misc/tools/check_std_includes.py include
# A Release build defines NDEBUG, and melon's preconditions are asserts.
# <cassert> re-reads the macro at every inclusion, so a test file's
# leading `#undef NDEBUG` re-arms them in every melon header it includes;
# a file without the line still passes while testing no precondition.
- name: Every test file either undefines NDEBUG or opts out explicitly
if: ${{ !cancelled() }}
run: |
missing=$(for f in test/*.cpp; do
head -8 "$f" \
| grep -qE '#undef NDEBUG|NDEBUG-INDEPENDENT' || echo "$f"
done)
if [ -n "$missing" ]; then
echo "These test files neither '#undef NDEBUG' nor carry the"
echo "'NDEBUG-INDEPENDENT' marker, so their assertions vanish in a"
echo "Release build:"
echo "$missing"
exit 1
fi
# Pinned to the version the tree is formatted with: another major
# version flags different lines.
- name: Install clang-format
if: ${{ !cancelled() }}
run: pipx install clang-format==18.1.8
- name: Check formatting
if: ${{ !cancelled() }}
run: |
find include test -name "*.hpp" -o -name "*.cpp" \
| xargs clang-format --dry-run -Werror
linux-gcc15-build:
runs-on: ubuntu-latest
container:
image: ubuntu:25.04
steps:
- uses: actions/checkout@v7
- name: Update APT
run: apt-get update && apt-get upgrade -y
- name: Install GCC-15 and CMake
run: apt-get install -y gcc-15 g++-15 cmake
- name: Install Conan 2.0
run: |
apt install -y pipx
pipx install conan
echo "/github/home/.local/bin" >> $GITHUB_PATH
- name: Build and run unit tests
run: |
conan profile detect --name=default
make CONAN_PROFILE=.github/conan-profiles/gcc15_c++26
linux-gcc14-build:
runs-on: ubuntu-latest
container:
image: ubuntu:24.04
steps:
- uses: actions/checkout@v7
- name: Update APT
run: apt-get update && apt-get upgrade -y
- name: Install GCC-14 and CMake
run: apt-get install -y gcc-14 g++-14 cmake
- name: Install Conan 2.0
run: |
apt-get install -y pipx
pipx install conan
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Build and run unit tests
run: |
conan profile detect --name=default
make CONAN_PROFILE=.github/conan-profiles/gcc14_c++23
linux-clang18-build:
runs-on: ubuntu-latest
container:
image: ubuntu:24.04
steps:
- uses: actions/checkout@v7
- name: Update APT
run: apt-get update && apt-get upgrade -y
- name: Install Clang-18, libstdc++-14 and CMake
run: apt-get install -y clang-18 libstdc++-14-dev cmake
- name: Install Conan 2.0
run: |
apt-get install -y pipx
pipx install conan
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Build and run unit tests
run: |
conan profile detect --name=default
make CONAN_PROFILE=.github/conan-profiles/clang18_c++23
# Pure CMake rather than `make CONAN_PROFILE`: this is the only job that
# exercises the FetchContent GTest fallback. Debug, not Release: at -O2 the
# optimiser elides the very UB being hunted and ASan's reports lose their
# line precision.
linux-gcc15-sanitize:
runs-on: ubuntu-latest
container:
image: ubuntu:25.04
env:
CC: gcc-15
CXX: g++-15
steps:
- uses: actions/checkout@v7
- name: Update APT
run: apt-get update && apt-get upgrade -y
- name: Install GCC-15 and CMake
run: apt-get install -y gcc-15 g++-15 cmake
# -std=c++26 with MELON_PORTABLE_RANGE_SHAPES=ON is the only sanitized
# run of the C++23 concat fallback on a library that has
# std::views::concat; dropping either leaves that path unsanitized.
- name: Configure with ASan and UBSan
run: |
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_STANDARD=26 \
-DMELON_PORTABLE_RANGE_SHAPES=ON \
-DMELON_SANITIZE=address,undefined
# A bare -j is unlimited for make: 64 sanitized test TUs at ~1 GB each
# OOM-kill the whole step (exit 137) on the 16 GB runner.
- name: Build
run: cmake --build build -j"$(nproc)"
- name: Run unit tests
run: ctest --test-dir build --output-on-failure
linux-cmake-submodule:
runs-on: ubuntu-latest
container:
image: ubuntu:25.04
steps:
- name: Update APT
run: apt-get update && apt-get upgrade -y
- name: Install GCC-15 and CMake
run: apt-get install -y gcc-15 g++-15 cmake
- uses: actions/checkout@v7
with:
path: consumer/external/melon
- name: Create a consumer project using melon as a submodule
run: |
cat > consumer/CMakeLists.txt << 'EOF'
cmake_minimum_required(VERSION 3.12)
project(MelonSubmoduleConsumer LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_subdirectory(external/melon)
add_executable(melon_consumer main.cpp)
target_link_libraries(melon_consumer PRIVATE melon)
EOF
cat > consumer/main.cpp << 'EOF'
#include <iostream>
#include "melon/algorithm/dijkstra.hpp"
#include "melon/container/static_digraph.hpp"
#include "melon/utility/static_digraph_builder.hpp"
int main() {
using namespace melon;
static_digraph_builder<static_digraph, int> builder(6);
builder.add_arc({0, 1}, 7)
.add_arc({0, 2}, 9)
.add_arc({0, 5}, 14)
.add_arc({1, 2}, 10)
.add_arc({1, 3}, 15)
.add_arc({2, 3}, 12)
.add_arc({2, 5}, 2)
.add_arc({3, 4}, 6)
.add_arc({4, 5}, 9);
auto [graph, length_map] = builder.build();
dijkstra alg(graph, length_map);
alg.add_source(0u);
for(const auto & [v, dist] : alg) {
std::cout << "vertex " << v << " at distance " << dist
<< '\n';
}
return 0;
}
EOF
- name: Configure, build and run the consumer project
env:
CC: gcc-15
CXX: g++-15
run: |
cmake -S consumer -B consumer/build -DCMAKE_BUILD_TYPE=Release -DMELON_BUILD_TESTS=OFF
cmake --build consumer/build
./consumer/build/melon_consumer
linux-cmake-install:
runs-on: ubuntu-latest
container:
image: ubuntu:25.04
env:
CC: gcc-15
CXX: g++-15
steps:
- uses: actions/checkout@v7
- name: Update APT
run: apt-get update && apt-get upgrade -y
- name: Install GCC-15 and CMake
run: apt-get install -y gcc-15 g++-15 cmake
# MELON_BUILD_TESTS defaults to ON when melon is the top-level project;
# without OFF the configure downloads GTest through FetchContent for
# nothing.
- name: Install melon into a prefix
run: |
cmake -S . -B build \
-DCMAKE_BUILD_TYPE=Release \
-DMELON_BUILD_TESTS=OFF \
-DCMAKE_INSTALL_PREFIX="$GITHUB_WORKSPACE/prefix"
cmake --install build
- name: Check the installed layout
run: |
test -f "$GITHUB_WORKSPACE/prefix/include/melon/version.hpp"
test -f "$GITHUB_WORKSPACE/prefix/include/melon/all.hpp"
test -f "$GITHUB_WORKSPACE/prefix/lib/cmake/melon/melonConfig.cmake"
test -f "$GITHUB_WORKSPACE/prefix/lib/cmake/melon/melonConfigVersion.cmake"
test -f "$GITHUB_WORKSPACE/prefix/lib/cmake/melon/melonTargets.cmake"
test -f "$GITHUB_WORKSPACE/prefix/share/licenses/melon/LICENSE"
# The two unfinished experimental headers must not ship.
test ! -e "$GITHUB_WORKSPACE/prefix/include/melon/experimental/scapegoat_tree.hpp"
test ! -e "$GITHUB_WORKSPACE/prefix/include/melon/experimental/doubly_connected_digraph.hpp"
- name: Create an out-of-tree consumer using find_package(melon)
run: |
mkdir -p consumer
cat > consumer/CMakeLists.txt << 'EOF'
cmake_minimum_required(VERSION 3.24)
project(MelonInstallConsumer LANGUAGES CXX)
find_package(melon 1.0 CONFIG REQUIRED)
add_executable(app main.cpp)
target_link_libraries(app PRIVATE melon::melon)
EOF
cat > consumer/main.cpp << 'EOF'
#include <iostream>
#include "melon/algorithm/dijkstra.hpp"
#include "melon/container/static_digraph.hpp"
#include "melon/utility/static_digraph_builder.hpp"
#include "melon/version.hpp"
static_assert(MELON_VERSION_MAJOR == 1);
int main() {
using namespace melon;
static_digraph_builder<static_digraph, int> builder(6);
builder.add_arc({0, 1}, 7)
.add_arc({0, 2}, 9)
.add_arc({0, 5}, 14)
.add_arc({1, 2}, 10)
.add_arc({1, 3}, 15)
.add_arc({2, 3}, 12)
.add_arc({2, 5}, 2)
.add_arc({3, 4}, 6)
.add_arc({4, 5}, 9);
auto [graph, length_map] = builder.build();
for(const auto & [v, dist] : dijkstra(graph, length_map, 0u)) {
std::cout << "vertex " << v << " at distance " << dist
<< '\n';
}
return 0;
}
EOF
- name: Build the consumer against the installed package
run: |
cmake -S consumer -B consumer/build \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH="$GITHUB_WORKSPACE/prefix"
cmake --build consumer/build -j"$(nproc)"
# The whole output is diffed, not one line: the settle order is the
# distance order, so a traversal-order regression shows here too.
- name: Run the consumer and check its output
run: |
cat > expected.txt << 'EOF'
vertex 0 at distance 0
vertex 1 at distance 7
vertex 2 at distance 9
vertex 5 at distance 11
vertex 3 at distance 21
vertex 4 at distance 27
EOF
./consumer/build/app | tee output.txt
diff -u expected.txt output.txt
# `conan create`, not the `make CONAN_PROFILE` the build jobs use: `conan
# build` never runs package() or package_info(), so the recipe's packaging
# half is checked only here, by consuming the created package.
linux-conan-create:
runs-on: ubuntu-latest
container:
image: ubuntu:25.04
env:
CC: gcc-15
CXX: g++-15
steps:
- uses: actions/checkout@v7
- name: Update APT
run: apt-get update && apt-get upgrade -y
- name: Install GCC-15 and CMake
run: apt-get install -y gcc-15 g++-15 cmake
- name: Install Conan 2.0
run: |
apt-get install -y pipx
pipx install conan
echo "/github/home/.local/bin" >> $GITHUB_PATH
- name: Create the package
run: |
conan profile detect --name=default
conan create . -u -b=missing -pr=.github/conan-profiles/gcc15_c++26
- name: Create a consumer project requiring the created package
run: |
mkdir -p consumer
# Version range rather than a pinned 1.0.0, so the job keeps working
# across patch bumps of version.hpp.
cat > consumer/conanfile.txt << 'EOF'
[requires]
melon/[>=1.0 <2]
[generators]
CMakeDeps
CMakeToolchain
EOF
cat > consumer/CMakeLists.txt << 'EOF'
cmake_minimum_required(VERSION 3.24)
project(MelonConanConsumer LANGUAGES CXX)
find_package(melon CONFIG REQUIRED)
add_executable(app main.cpp)
target_link_libraries(app PRIVATE melon::melon)
EOF
cat > consumer/main.cpp << 'EOF'
#include <iostream>
#include "melon/algorithm/dijkstra.hpp"
#include "melon/container/static_digraph.hpp"
#include "melon/utility/static_digraph_builder.hpp"
#include "melon/version.hpp"
static_assert(MELON_VERSION_MAJOR == 1);
// package() in conanfile.py carries its own exclude list, separate
// from the install() rules in CMakeLists.txt; the install job checks
// only the latter, so dropping these lets the two lists drift.
#if __has_include("melon/experimental/scapegoat_tree.hpp")
#error "scapegoat_tree.hpp is unfinished and must not be packaged"
#endif
#if __has_include("melon/experimental/doubly_connected_digraph.hpp")
#error "doubly_connected_digraph.hpp is unfinished and must not be packaged"
#endif
#if !__has_include("melon/experimental/planar_map.hpp")
#error "planar_map.hpp is expected to ship"
#endif
int main() {
using namespace melon;
static_digraph_builder<static_digraph, int> builder(6);
builder.add_arc({0, 1}, 7)
.add_arc({0, 2}, 9)
.add_arc({0, 5}, 14)
.add_arc({1, 2}, 10)
.add_arc({1, 3}, 15)
.add_arc({2, 3}, 12)
.add_arc({2, 5}, 2)
.add_arc({3, 4}, 6)
.add_arc({4, 5}, 9);
auto [graph, length_map] = builder.build();
for(const auto & [v, dist] : dijkstra(graph, length_map, 0u)) {
std::cout << "vertex " << v << " at distance " << dist
<< '\n';
}
return 0;
}
EOF
- name: Build the consumer against the created package
run: |
conan install consumer -pr=.github/conan-profiles/gcc15_c++26 \
-of=consumer/deps -b=missing
cmake -S consumer -B consumer/build \
-DCMAKE_TOOLCHAIN_FILE="$GITHUB_WORKSPACE/consumer/deps/conan_toolchain.cmake" \
-DCMAKE_BUILD_TYPE=Release
cmake --build consumer/build -j"$(nproc)"
- name: Run the consumer and check its output
run: |
cat > expected.txt << 'EOF'
vertex 0 at distance 0
vertex 1 at distance 7
vertex 2 at distance 9
vertex 5 at distance 11
vertex 3 at distance 21
vertex 4 at distance 27
EOF
./consumer/build/app | tee output.txt
diff -u expected.txt output.txt
# Xcode 26.4.1 rather than the image default: the oldest Apple clang 21.
# Whether the Apple clang 17 line (Xcode 16.3 to 26.3) meets the libc++ 20
# floor stdlib_check.hpp asserts is untested, and Apple publishes no libc++
# release per Xcode, so the survey step is the only evidence for moving the
# pin down.
macos-appleclang21-build:
runs-on: macos-26
steps:
- uses: actions/checkout@v7
- name: Select Xcode 26.4.1
run: sudo xcode-select -s /Applications/Xcode_26.4.1.app
- name: Survey the libc++ release of every installed Xcode
run: |
for x in /Applications/Xcode_*.app; do
v=$(printf '#include <version>\nLIBCPP _LIBCPP_VERSION\n' \
| DEVELOPER_DIR="$x" clang++ -x c++ -std=c++23 -E - 2>/dev/null \
| grep '^LIBCPP' || echo 'LIBCPP unavailable')
echo "$(basename "$x"): $v"
done
clang++ --version
# pipx's bin dir is not on later steps' PATH unless appended here, and
# the image may set PIPX_BIN_DIR to somewhere other than ~/.local/bin.
- name: Install Conan 2.0
run: |
pipx install conan
echo "${PIPX_BIN_DIR:-$HOME/.local/bin}" >> "$GITHUB_PATH"
- name: Build and run unit tests
run: |
conan profile detect --name=default
make CONAN_PROFILE=.github/conan-profiles/appleclang21_c++23
windows-mingw15-build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v7
- name: Install Conan 2.0
run: pip install conan
- name: Autodetect a default conan profile
run: conan profile detect --name=default
- name: Build and run unit tests
run: make CONAN_PROFILE=.github/conan-profiles/mingw15_c++26
windows-msvc1711-build:
# Not windows-latest: that image carries only Visual Studio 2026, and
# both the "Visual Studio 17 2022" generator conan derives from
# compiler.version=194 and the 14.41 toolset need a VS 2022 instance.
runs-on: windows-2022
steps:
- uses: actions/checkout@v7
- name: Install the MSVC 14.41 (VS 17.11) toolset
# The image ships only the newest 14.4x toolset and the profile pins
# 14.41, melon's MSVC floor. Exit code 3010 is success-needs-reboot,
# not a failure.
shell: pwsh
run: |
$installer = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer"
$vs = & "$installer\vswhere.exe" -latest -products * -property installationPath
$proc = Start-Process -Wait -PassThru -FilePath "$installer\setup.exe" `
-ArgumentList ('modify --installPath "' + $vs + '" ' +
'--add Microsoft.VisualStudio.Component.VC.14.41.17.11.x86.x64 ' +
'--quiet --norestart --nocache')
if (($proc.ExitCode -ne 0) -and ($proc.ExitCode -ne 3010)) {
throw "VS installer exited with $($proc.ExitCode)"
}
- name: Install Conan 2.0
run: pip install conan
- name: Autodetect a default conan profile
run: conan profile detect --name=default
- name: Build and run unit tests
run: make CONAN_PROFILE=.github/conan-profiles/msvc17.11_c++23
windows-msvc1811-build:
# The VS 2026 image. Image updates move its VS minor without notice, so
# the job name follows it by hand; the profile pins the toolset instead.
# Unlike the 17.11 job, no toolset is installed: the 14.51 pin is met by
# the image's default MSVC, so once an image update makes 14.52 the
# default, configure fails to find 14.51 and the job needs a side-by-side
# install step like the one above. The x86.x64 component ID for 14.51 is
# undocumented; its ARM64 sibling is
# Microsoft.VisualStudio.Component.VC.14.51.ARM64, with no 18.x infix.
runs-on: windows-2025
steps:
- uses: actions/checkout@v7
- name: Install Conan 2.0
run: pip install conan
- name: Autodetect a default conan profile
run: conan profile detect --name=default
- name: Build and run unit tests
run: make CONAN_PROFILE=.github/conan-profiles/msvc18.11_c++23