Skip to content

Commit 14fb365

Browse files
authored
Merge pull request #15 from lefticus/cleanups_add_missing_features
Cleanups add missing features
2 parents 8bfa3ba + 75230a5 commit 14fb365

Some content is hidden

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

44 files changed

+5826
-812
lines changed

.clang-tidy

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
---
2+
3+
# Unfortunately const-correctness seems to be almost completely broken
4+
# (clang 19)
25
Checks: "*,
36
-abseil-*,
47
-altera-*,
@@ -11,18 +14,29 @@ Checks: "*,
1114
-readability-else-after-return,
1215
-readability-static-accessed-through-instance,
1316
-readability-avoid-const-params-in-decls,
17+
-readability-simplify-boolean-expr,
1418
-cppcoreguidelines-non-private-member-variables-in-classes,
1519
-misc-non-private-member-variables-in-classes,
20+
-misc-const-correctness,
1621
"
1722
WarningsAsErrors: ''
18-
HeaderFilterRegex: ''
23+
HeaderFilterRegex: '^(src|include)/.*'
1924
FormatStyle: none
2025

21-
CheckOptions:
22-
readability-identifier-length.IgnoredVariableNames: 'x|y|z|id|ch'
23-
readability-identifier-length.IgnoredParameterNames: 'x|y|z|id|ch'
24-
2526

27+
# Command line options
28+
ExtraArgs: [
29+
'-Wno-unknown-warning-option',
30+
'-Wno-ignored-optimization-argument',
31+
'-Wno-unused-command-line-argument',
32+
'-Wno-unknown-argument',
33+
'-Wno-gcc-compat'
34+
]
2635

36+
# Quiet mode is set via command line with --quiet
37+
# It doesn't have a YAML equivalent
2738

39+
CheckOptions:
40+
readability-identifier-length.IgnoredVariableNames: 'x|y|z|id|ch|to'
41+
readability-identifier-length.IgnoredParameterNames: 'x|y|z|id|ch|to'
2842

.github/workflows/ci.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
- develop
1111

1212
env:
13-
CLANG_TIDY_VERSION: "16.0.0"
13+
CLANG_TIDY_VERSION: "19.1.1"
1414
VERBOSE: 1
1515

1616

@@ -29,10 +29,11 @@ jobs:
2929
# and your own projects needs
3030
matrix:
3131
os:
32-
- ubuntu-22.04
32+
- ubuntu-latest
3333
compiler:
3434
# you can specify the version after `-` like "llvm-16.0.0".
35-
- gcc-13
35+
- gcc-14
36+
- llvm-19.1.1
3637
generator:
3738
- "Ninja Multi-Config"
3839
build_type:
@@ -45,8 +46,8 @@ jobs:
4546
include:
4647
# Add appropriate variables for gcov version required. This will intentionally break
4748
# if you try to use a compiler that does not have gcov set
48-
- compiler: gcc-13
49-
gcov_executable: gcov
49+
- compiler: gcc-14
50+
gcov_executable: gcov-14
5051
enable_ipo: On
5152

5253

@@ -55,6 +56,10 @@ jobs:
5556
packaging_maintainer_mode: OFF
5657
package_generator: TBZ2
5758

59+
- compiler: llvm-19.1.1
60+
enable_ip: Off
61+
gcov_executable: "llvm-cov gcov"
62+
5863

5964
steps:
6065
- name: Check for llvm version mismatches
@@ -114,7 +119,7 @@ jobs:
114119
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
115120
run: |
116121
ctest -C ${{matrix.build_type}}
117-
gcovr -j ${{env.nproc}} --delete --root ../ --print-summary --xml-pretty --xml coverage.xml . --gcov-executable '${{ matrix.gcov_executable }}'
122+
gcovr -j ${{env.nproc}} --root ../ --print-summary --xml-pretty --xml coverage.xml . --gcov-executable '${{ matrix.gcov_executable }}'
118123
119124
- name: Windows - Test and coverage
120125
if: runner.os == 'Windows'
@@ -139,6 +144,8 @@ jobs:
139144
- name: Publish to codecov
140145
uses: codecov/codecov-action@v2
141146
with:
147+
fail_ci_if_error: true
142148
flags: ${{ runner.os }}
143149
name: ${{ runner.os }}-coverage
150+
token: ${{ secrets.CODECOV_TOKEN }}
144151
files: ./build/coverage.xml

.github/workflows/wasm.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Build Intro WASM and Deploy to GitHub Pages
2+
3+
on:
4+
pull_request:
5+
release:
6+
types: [published]
7+
push:
8+
branches: [main, develop]
9+
tags: ['**']
10+
11+
permissions:
12+
contents: write
13+
14+
jobs:
15+
build-and-deploy:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Setup Emscripten
21+
uses: mymindstorm/setup-emsdk@v14
22+
with:
23+
version: 'latest'
24+
25+
- name: Install Ninja
26+
run: sudo apt-get install -y ninja-build
27+
28+
- name: Configure CMake
29+
run: emcmake cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
30+
31+
- name: Build all WASM targets
32+
run: emmake cmake --build build --target web-dist
33+
34+
- name: Prepare deployment
35+
run: |
36+
# web-dist target already created build/web-dist/
37+
# Just copy it to dist/ for GitHub Pages action
38+
cp -r build/web-dist dist
39+
40+
- name: Determine deploy path
41+
id: deploy-path
42+
if: github.event_name != 'pull_request' && github.event_name != 'release'
43+
run: |
44+
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
45+
echo "path=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
46+
elif [[ "$GITHUB_REF" == refs/heads/main ]]; then
47+
echo "path=." >> $GITHUB_OUTPUT
48+
elif [[ "$GITHUB_REF" == refs/heads/develop ]]; then
49+
echo "path=develop" >> $GITHUB_OUTPUT
50+
fi
51+
52+
- name: Deploy to GitHub Pages
53+
if: github.event_name != 'pull_request' && github.event_name != 'release'
54+
uses: peaceiris/actions-gh-pages@v4
55+
with:
56+
github_token: ${{ secrets.GITHUB_TOKEN }}
57+
publish_dir: ./dist
58+
destination_dir: ${{ steps.deploy-path.outputs.path }}
59+
keep_files: true

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,5 @@ $RECYCLE.BIN/
3232
.TemporaryItems
3333
ehthumbs.db
3434
Thumbs.db
35+
36+
**/.claude/settings.local.json

CLAUDE.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
44

5+
You are an expert in C++. You use C++23 and prefer to use constexpr wherever possible. You always apply C++ Best Practices as taught by Jason Turner.
6+
7+
You are also an expert in scheme-like languages and know the pros and cons of various design decisions.
8+
9+
10+
511
## Build Commands
612
- Configure: `cmake -S . -B ./build`
713
- Build: `cmake --build ./build`
@@ -16,6 +22,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
1622
- `constexpr_tests` target compiles tests with static assertions
1723
- Will fail to compile if tests fail since they use static assertions
1824
- Makes debugging difficult as you won't see which specific test failed
25+
- Will always fail to compile if there's a fail test; use relaxed_constexpr_tests or directly execute the tests with cons_expr command line tool for debugging
1926
- `relaxed_constexpr_tests` target compiles with runtime assertions
2027
- Preferred for debugging since it shows which specific tests fail
2128
- Use this target when developing/debugging:
@@ -57,6 +64,10 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
5764
- Header files follow #ifndef/#define guard pattern
5865
- Entire system is `constexpr` capable unless it uses IO
5966
- Use modern C++ style casts over C-style casts
67+
- Avoid macros completely except for header guards
68+
- Prefer templates, constexpr functions or concepts over macros
69+
- Use `static constexpr` for compile-time known constants
70+
- Prefer local constants within functions over function variables for readability
6071
6172
## Naming and Structure
6273
- Namespace: lefticus

CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,19 @@ project(
2323
LANGUAGES CXX C)
2424

2525
include(cmake/PreventInSourceBuilds.cmake)
26+
include(cmake/Emscripten.cmake)
2627
include(ProjectOptions.cmake)
2728

29+
if(MSVC)
30+
31+
elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
32+
add_compile_options(-fconstexpr-steps=12712420)
33+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
34+
35+
else()
36+
37+
# TODO support Intel compiler
38+
endif()
2839

2940
cons_expr_setup_options()
3041

@@ -67,6 +78,11 @@ add_subdirectory(src)
6778

6879
add_subdirectory(examples)
6980

81+
# Create unified web deployment directory (for WASM builds)
82+
if(EMSCRIPTEN)
83+
cons_expr_create_web_dist()
84+
endif()
85+
7086
# Don't even look at tests if we're not top level
7187
if(NOT PROJECT_IS_TOP_LEVEL)
7288
return()

Dependencies.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function(cons_expr_setup_dependencies)
2121
endif()
2222

2323
if(NOT TARGET Catch2::Catch2WithMain)
24-
cpmaddpackage("gh:catchorg/Catch2@3.7.0")
24+
cpmaddpackage("gh:catchorg/Catch2@3.8.1")
2525
endif()
2626

2727
if(NOT TARGET CLI11::CLI11)

ProjectOptions.cmake

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,57 @@ include(CMakeDependentOption)
44
include(CheckCXXCompilerFlag)
55

66

7+
include(CheckCXXSourceCompiles)
8+
9+
710
macro(cons_expr_supports_sanitizers)
8-
if((CMAKE_CXX_COMPILER_ID MATCHES ".*Clang.*" OR CMAKE_CXX_COMPILER_ID MATCHES ".*GNU.*") AND NOT WIN32)
9-
set(SUPPORTS_UBSAN ON)
11+
# Emscripten doesn't support sanitizers
12+
if(EMSCRIPTEN)
13+
set(SUPPORTS_UBSAN OFF)
14+
set(SUPPORTS_ASAN OFF)
15+
elseif((CMAKE_CXX_COMPILER_ID MATCHES ".*Clang.*" OR CMAKE_CXX_COMPILER_ID MATCHES ".*GNU.*") AND NOT WIN32)
16+
17+
message(STATUS "Sanity checking UndefinedBehaviorSanitizer, it should be supported on this platform")
18+
set(TEST_PROGRAM "int main() { return 0; }")
19+
20+
# Check if UndefinedBehaviorSanitizer works at link time
21+
set(CMAKE_REQUIRED_FLAGS "-fsanitize=undefined")
22+
set(CMAKE_REQUIRED_LINK_OPTIONS "-fsanitize=undefined")
23+
check_cxx_source_compiles("${TEST_PROGRAM}" HAS_UBSAN_LINK_SUPPORT)
24+
25+
if(HAS_UBSAN_LINK_SUPPORT)
26+
message(STATUS "UndefinedBehaviorSanitizer is supported at both compile and link time.")
27+
set(SUPPORTS_UBSAN ON)
28+
else()
29+
message(WARNING "UndefinedBehaviorSanitizer is NOT supported at link time.")
30+
set(SUPPORTS_UBSAN OFF)
31+
endif()
1032
else()
1133
set(SUPPORTS_UBSAN OFF)
1234
endif()
1335

1436
if((CMAKE_CXX_COMPILER_ID MATCHES ".*Clang.*" OR CMAKE_CXX_COMPILER_ID MATCHES ".*GNU.*") AND WIN32)
1537
set(SUPPORTS_ASAN OFF)
1638
else()
17-
set(SUPPORTS_ASAN ON)
39+
if (NOT WIN32)
40+
message(STATUS "Sanity checking AddressSanitizer, it should be supported on this platform")
41+
set(TEST_PROGRAM "int main() { return 0; }")
42+
43+
# Check if AddressSanitizer works at link time
44+
set(CMAKE_REQUIRED_FLAGS "-fsanitize=address")
45+
set(CMAKE_REQUIRED_LINK_OPTIONS "-fsanitize=address")
46+
check_cxx_source_compiles("${TEST_PROGRAM}" HAS_ASAN_LINK_SUPPORT)
47+
48+
if(HAS_ASAN_LINK_SUPPORT)
49+
message(STATUS "AddressSanitizer is supported at both compile and link time.")
50+
set(SUPPORTS_ASAN ON)
51+
else()
52+
message(WARNING "AddressSanitizer is NOT supported at link time.")
53+
set(SUPPORTS_ASAN OFF)
54+
endif()
55+
else()
56+
set(SUPPORTS_ASAN ON)
57+
endif()
1858
endif()
1959
endmacro()
2060

@@ -54,8 +94,8 @@ macro(cons_expr_setup_options)
5494
option(cons_expr_ENABLE_SANITIZER_THREAD "Enable thread sanitizer" OFF)
5595
option(cons_expr_ENABLE_SANITIZER_MEMORY "Enable memory sanitizer" OFF)
5696
option(cons_expr_ENABLE_UNITY_BUILD "Enable unity builds" OFF)
57-
option(cons_expr_ENABLE_CLANG_TIDY "Enable clang-tidy" OFF)
58-
option(cons_expr_ENABLE_CPPCHECK "Enable cpp-check analysis" OFF)
97+
option(cons_expr_ENABLE_CLANG_TIDY "Enable clang-tidy" ON)
98+
option(cons_expr_ENABLE_CPPCHECK "Enable cpp-check analysis" ON)
5999
option(cons_expr_ENABLE_PCH "Enable precompiled headers" OFF)
60100
option(cons_expr_ENABLE_CACHE "Enable ccache" ON)
61101
endif()
@@ -130,19 +170,22 @@ macro(cons_expr_local_options)
130170
""
131171
"")
132172

133-
if(cons_expr_ENABLE_USER_LINKER)
134-
include(cmake/Linker.cmake)
135-
configure_linker(cons_expr_options)
136-
endif()
173+
# Linker and sanitizers not supported in Emscripten
174+
if(NOT EMSCRIPTEN)
175+
if(cons_expr_ENABLE_USER_LINKER)
176+
include(cmake/Linker.cmake)
177+
cons_expr_configure_linker(cons_expr_options)
178+
endif()
137179

138-
include(cmake/Sanitizers.cmake)
139-
cons_expr_enable_sanitizers(
140-
cons_expr_options
141-
${cons_expr_ENABLE_SANITIZER_ADDRESS}
142-
${cons_expr_ENABLE_SANITIZER_LEAK}
143-
${cons_expr_ENABLE_SANITIZER_UNDEFINED}
144-
${cons_expr_ENABLE_SANITIZER_THREAD}
145-
${cons_expr_ENABLE_SANITIZER_MEMORY})
180+
include(cmake/Sanitizers.cmake)
181+
cons_expr_enable_sanitizers(
182+
cons_expr_options
183+
${cons_expr_ENABLE_SANITIZER_ADDRESS}
184+
${cons_expr_ENABLE_SANITIZER_LEAK}
185+
${cons_expr_ENABLE_SANITIZER_UNDEFINED}
186+
${cons_expr_ENABLE_SANITIZER_THREAD}
187+
${cons_expr_ENABLE_SANITIZER_MEMORY})
188+
endif()
146189

147190
set_target_properties(cons_expr_options PROPERTIES UNITY_BUILD ${cons_expr_ENABLE_UNITY_BUILD})
148191

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,15 @@
3232
* For C++23
3333
* Currently only known to work with GCC 13.1.
3434

35+
* WebAssembly build support with automatic GitHub Pages deployment
3536

37+
**Live Demo:** If you enable GitHub Pages in your project created from this template, you'll have a working example like this:
38+
39+
- Main: [https://cpp-best-practices.github.io/cmake_template/](https://cpp-best-practices.github.io/cmake_template/)
40+
- Develop: [https://cpp-best-practices.github.io/cmake_template/develop/](https://cpp-best-practices.github.io/cmake_template/develop/)
41+
42+
The `main` branch deploys to the root, `develop` to `/develop/`, and tags to `/tagname/`.
43+
3644
## Command Line Inspection Tool
3745

3846
`ccons_expr` can be used to execute scripts and inspect the state of the runtime system live

0 commit comments

Comments
 (0)