From 0857eac8532ccb11a7660552e8b2cecaee7bacfc Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Mon, 24 Nov 2025 21:31:18 +0100 Subject: [PATCH 1/6] Feat: apply precommit autoupdate --- .pre-commit-config.yaml | 4 ++-- CMakeLists.txt | 2 +- infra/cmake/use-fetch-content.cmake | 30 ++++++++++------------------- tests/CMakeLists.txt | 16 ++++++--------- 4 files changed, 19 insertions(+), 33 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8da575f..8128f65 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,14 +13,14 @@ repos: # This brings in a portable version of clang-format. # See also: https://github.com/ssciwr/clang-format-wheel - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v21.1.2 + rev: v21.1.6 hooks: - id: clang-format types_or: [c++, c] # CMake linting and formatting - repo: https://github.com/BlankSpruce/gersemi - rev: 0.22.3 + rev: 0.23.1 hooks: - id: gersemi name: CMake linting diff --git a/CMakeLists.txt b/CMakeLists.txt index 6cd404a..4c1ab56 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -cmake_minimum_required(VERSION 3.28...4.1) +cmake_minimum_required(VERSION 3.28...4.2) project( beman.scope diff --git a/infra/cmake/use-fetch-content.cmake b/infra/cmake/use-fetch-content.cmake index 4ed4839..9ac69d3 100644 --- a/infra/cmake/use-fetch-content.cmake +++ b/infra/cmake/use-fetch-content.cmake @@ -15,8 +15,7 @@ message(TRACE "BemanExemplar_projectDir=\"${BemanExemplar_projectDir}\"") message(TRACE "BEMAN_EXEMPLAR_LOCKFILE=\"${BEMAN_EXEMPLAR_LOCKFILE}\"") file( - REAL_PATH - "${BEMAN_EXEMPLAR_LOCKFILE}" + REAL_PATH "${BEMAN_EXEMPLAR_LOCKFILE}" BemanExemplar_lockfile BASE_DIRECTORY "${BemanExemplar_projectDir}" EXPAND_TILDE @@ -38,8 +37,7 @@ function(BemanExemplar_provideDependency method package_name) # Get the "dependencies" field and store it in BemanExemplar_dependenciesObj string( - JSON - BemanExemplar_dependenciesObj + JSON BemanExemplar_dependenciesObj ERROR_VARIABLE BemanExemplar_error GET "${BemanExemplar_rootObj}" "dependencies" @@ -50,8 +48,7 @@ function(BemanExemplar_provideDependency method package_name) # Get the length of the libraries array and store it in BemanExemplar_dependenciesObj string( - JSON - BemanExemplar_numDependencies + JSON BemanExemplar_numDependencies ERROR_VARIABLE BemanExemplar_error LENGTH "${BemanExemplar_dependenciesObj}" ) @@ -73,8 +70,7 @@ function(BemanExemplar_provideDependency method package_name) # Get the dependency object at BemanExemplar_index # and store it in BemanExemplar_depObj string( - JSON - BemanExemplar_depObj + JSON BemanExemplar_depObj ERROR_VARIABLE BemanExemplar_error GET "${BemanExemplar_dependenciesObj}" "${BemanExemplar_index}" @@ -88,8 +84,7 @@ function(BemanExemplar_provideDependency method package_name) # Get the "name" field and store it in BemanExemplar_name string( - JSON - BemanExemplar_name + JSON BemanExemplar_name ERROR_VARIABLE BemanExemplar_error GET "${BemanExemplar_depObj}" "name" @@ -103,8 +98,7 @@ function(BemanExemplar_provideDependency method package_name) # Get the "package_name" field and store it in BemanExemplar_pkgName string( - JSON - BemanExemplar_pkgName + JSON BemanExemplar_pkgName ERROR_VARIABLE BemanExemplar_error GET "${BemanExemplar_depObj}" "package_name" @@ -118,8 +112,7 @@ function(BemanExemplar_provideDependency method package_name) # Get the "git_repository" field and store it in BemanExemplar_repo string( - JSON - BemanExemplar_repo + JSON BemanExemplar_repo ERROR_VARIABLE BemanExemplar_error GET "${BemanExemplar_depObj}" "git_repository" @@ -133,8 +126,7 @@ function(BemanExemplar_provideDependency method package_name) # Get the "git_tag" field and store it in BemanExemplar_tag string( - JSON - BemanExemplar_tag + JSON BemanExemplar_tag ERROR_VARIABLE BemanExemplar_error GET "${BemanExemplar_depObj}" "git_tag" @@ -149,14 +141,12 @@ function(BemanExemplar_provideDependency method package_name) if(method STREQUAL "FIND_PACKAGE") if(package_name STREQUAL BemanExemplar_pkgName) string( - APPEND - BemanExemplar_debug + APPEND BemanExemplar_debug "Redirecting find_package calls for ${BemanExemplar_pkgName} " "to FetchContent logic.\n" ) string( - APPEND - BemanExemplar_debug + APPEND BemanExemplar_debug "Fetching ${BemanExemplar_repo} at " "${BemanExemplar_tag} according to ${BemanExemplar_lockfile}." ) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 537f620..a7cbcfc 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -5,21 +5,17 @@ include(FetchContent) FetchContent_Declare( Catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v3.8.0 + GIT_TAG v3.11.0 + EXCLUDE_FROM_ALL + # FIND_PACKAGE_ARGS 3.11 ) FetchContent_MakeAvailable(Catch2) +set(ALL_TESTNAMES scope_success scope_exit scope_fail unique_resource) + # module tests will only compile with gcc15 or clang20 and above if(CMAKE_CXX_SCAN_FOR_MODULES) - set(ALL_TESTNAMES - scope_success - scope_exit - scope_fail - unique_resource - module - ) -else() - set(ALL_TESTNAMES scope_success scope_exit scope_fail unique_resource) + list(APPEND ALL_TESTNAMES module) endif() message("Tests to be built: ${ALL_TESTNAMES}") From ad5c639c0ee955fabfcc65c2a5109b65cf9c92f4 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Fri, 28 Nov 2025 21:23:26 +0100 Subject: [PATCH 2/6] Fix: exclude infra from pre-commt hooks --- .clang-format | 4 ++-- .devcontainer/devcontainer.json | 30 ++++++++++++++--------------- .gitignore | 1 + .pre-commit-config.yaml | 6 +++--- infra/cmake/use-fetch-content.cmake | 30 +++++++++++++++++++---------- 5 files changed, 41 insertions(+), 30 deletions(-) diff --git a/.clang-format b/.clang-format index 05baf03..ec5c0e1 100644 --- a/.clang-format +++ b/.clang-format @@ -106,11 +106,11 @@ IfMacros: - KJ_IF_MAYBE IncludeBlocks: Preserve IncludeCategories: - - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + - Regex: '^"(beman|llvm|llvm-c|clang|clang-c)/' Priority: 2 SortPriority: 0 CaseSensitive: false - - Regex: '^(<|"(gtest|isl|json)/)' + - Regex: '^(<|"(catch2|gtest|gmock|isl|json)/)' Priority: 3 SortPriority: 0 CaseSensitive: false diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index b0909de..42b3df1 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,16 +1,16 @@ -// For format details, see https://aka.ms/devcontainer.json. For config options, see the -// README at: https://github.com/devcontainers/templates/tree/main/src/cpp + // For format details, see https://aka.ms/devcontainer.json. For config options, see the + // README at: https://github.com/devcontainers/templates/tree/main/src/cpp -{ - "name": "Beman Project Generic Devcontainer", - "image": "ghcr.io/bemanproject/infra-containers-devcontainer-gcc:14", - "postCreateCommand": "pre-commit", - "customizations": { - "vscode": { - "extensions": [ - "ms-vscode.cpptools", - "ms-vscode.cmake-tools" - ] - } - } -} + { + "name": "Beman Project Generic Devcontainer", + "image": "ghcr.io/bemanproject/infra-containers-devcontainer-gcc:14", + "postCreateCommand": "pre-commit", + "customizations": { + "vscode": { + "extensions": [ + "ms-vscode.cpptools", + "ms-vscode.cmake-tools" + ] + } + } + } diff --git a/.gitignore b/.gitignore index 0cb4a66..baadefc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.cache /compile_commands.json /build diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8128f65..60643a7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: rev: v21.1.6 hooks: - id: clang-format - types_or: [c++, c] + types_or: [c++, c, json] # CMake linting and formatting - repo: https://github.com/BlankSpruce/gersemi @@ -30,7 +30,7 @@ repos: # Config file: .markdownlint.yaml # Commented out to disable this by default. Uncomment to enable markdown linting. # - repo: https://github.com/igorshubovych/markdownlint-cli - # rev: v0.42.0 + # rev: v0.46.0 # hooks: # - id: markdownlint @@ -40,4 +40,4 @@ repos: - id: codespell args: ["--ignore-words-list=wil"] -exclude: 'cookiecutter/' +exclude: 'infra/' diff --git a/infra/cmake/use-fetch-content.cmake b/infra/cmake/use-fetch-content.cmake index 9ac69d3..4ed4839 100644 --- a/infra/cmake/use-fetch-content.cmake +++ b/infra/cmake/use-fetch-content.cmake @@ -15,7 +15,8 @@ message(TRACE "BemanExemplar_projectDir=\"${BemanExemplar_projectDir}\"") message(TRACE "BEMAN_EXEMPLAR_LOCKFILE=\"${BEMAN_EXEMPLAR_LOCKFILE}\"") file( - REAL_PATH "${BEMAN_EXEMPLAR_LOCKFILE}" + REAL_PATH + "${BEMAN_EXEMPLAR_LOCKFILE}" BemanExemplar_lockfile BASE_DIRECTORY "${BemanExemplar_projectDir}" EXPAND_TILDE @@ -37,7 +38,8 @@ function(BemanExemplar_provideDependency method package_name) # Get the "dependencies" field and store it in BemanExemplar_dependenciesObj string( - JSON BemanExemplar_dependenciesObj + JSON + BemanExemplar_dependenciesObj ERROR_VARIABLE BemanExemplar_error GET "${BemanExemplar_rootObj}" "dependencies" @@ -48,7 +50,8 @@ function(BemanExemplar_provideDependency method package_name) # Get the length of the libraries array and store it in BemanExemplar_dependenciesObj string( - JSON BemanExemplar_numDependencies + JSON + BemanExemplar_numDependencies ERROR_VARIABLE BemanExemplar_error LENGTH "${BemanExemplar_dependenciesObj}" ) @@ -70,7 +73,8 @@ function(BemanExemplar_provideDependency method package_name) # Get the dependency object at BemanExemplar_index # and store it in BemanExemplar_depObj string( - JSON BemanExemplar_depObj + JSON + BemanExemplar_depObj ERROR_VARIABLE BemanExemplar_error GET "${BemanExemplar_dependenciesObj}" "${BemanExemplar_index}" @@ -84,7 +88,8 @@ function(BemanExemplar_provideDependency method package_name) # Get the "name" field and store it in BemanExemplar_name string( - JSON BemanExemplar_name + JSON + BemanExemplar_name ERROR_VARIABLE BemanExemplar_error GET "${BemanExemplar_depObj}" "name" @@ -98,7 +103,8 @@ function(BemanExemplar_provideDependency method package_name) # Get the "package_name" field and store it in BemanExemplar_pkgName string( - JSON BemanExemplar_pkgName + JSON + BemanExemplar_pkgName ERROR_VARIABLE BemanExemplar_error GET "${BemanExemplar_depObj}" "package_name" @@ -112,7 +118,8 @@ function(BemanExemplar_provideDependency method package_name) # Get the "git_repository" field and store it in BemanExemplar_repo string( - JSON BemanExemplar_repo + JSON + BemanExemplar_repo ERROR_VARIABLE BemanExemplar_error GET "${BemanExemplar_depObj}" "git_repository" @@ -126,7 +133,8 @@ function(BemanExemplar_provideDependency method package_name) # Get the "git_tag" field and store it in BemanExemplar_tag string( - JSON BemanExemplar_tag + JSON + BemanExemplar_tag ERROR_VARIABLE BemanExemplar_error GET "${BemanExemplar_depObj}" "git_tag" @@ -141,12 +149,14 @@ function(BemanExemplar_provideDependency method package_name) if(method STREQUAL "FIND_PACKAGE") if(package_name STREQUAL BemanExemplar_pkgName) string( - APPEND BemanExemplar_debug + APPEND + BemanExemplar_debug "Redirecting find_package calls for ${BemanExemplar_pkgName} " "to FetchContent logic.\n" ) string( - APPEND BemanExemplar_debug + APPEND + BemanExemplar_debug "Fetching ${BemanExemplar_repo} at " "${BemanExemplar_tag} according to ${BemanExemplar_lockfile}." ) From c71ac3e518b1c80fe3ee685fc3565b2d8d7f305c Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Fri, 28 Nov 2025 22:02:21 +0100 Subject: [PATCH 3/6] Feat: add example/scope-module if possible --- examples/CMakeLists.txt | 5 +++++ examples/scope-module.cpp | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index bfe8ef5..3517043 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -2,6 +2,11 @@ set(ALL_EXAMPLES scope_example unique_resource unique_resource-file) +# module tests will only compile with gcc15 or clang20 and above +if(CMAKE_CXX_SCAN_FOR_MODULES AND CMAKE_CXX_STANDARD GREATER 20) + list(APPEND ALL_EXAMPLES scope-module) +endif() + message("Examples to be built: ${ALL_EXAMPLES}") foreach(example ${ALL_EXAMPLES}) diff --git a/examples/scope-module.cpp b/examples/scope-module.cpp index c5f26e8..5cacd30 100644 --- a/examples/scope-module.cpp +++ b/examples/scope-module.cpp @@ -15,7 +15,12 @@ // destroy noisy // scope exit: true success: true fail: false +#ifdef HAS_MODULE_STD import std; +#else +#include +#endif + import beman.scope; // clang-format off From 62ef47f14eeac1f47e924215ffecb15f46aa43f0 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Fri, 28 Nov 2025 22:11:47 +0100 Subject: [PATCH 4/6] Feat: clang-format json files too --- .clang-format | 3 +++ .devcontainer/devcontainer.json | 2 +- .pre-commit-config.yaml | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.clang-format b/.clang-format index ec5c0e1..d256b10 100644 --- a/.clang-format +++ b/.clang-format @@ -1,4 +1,7 @@ --- +BasedOnStyle: LLVM +IndentWidth: 2 +--- Language: Cpp AccessModifierOffset: -2 AlignAfterOpenBracket: Align diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 42b3df1..d0f5a17 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,4 +1,4 @@ - // For format details, see https://aka.ms/devcontainer.json. For config options, see the +// For format details, see https://aka.ms/devcontainer.json. For config options, see the // README at: https://github.com/devcontainers/templates/tree/main/src/cpp { diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 60643a7..a4daacd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,6 +7,7 @@ repos: - id: trailing-whitespace - id: end-of-file-fixer - id: check-yaml + exclude: ^\.clang-(format|tidy)$ - id: check-added-large-files # Clang-format for C++ From 03af50fed7aad3f0a653077c242b0bdacc7e53c5 Mon Sep 17 00:00:00 2001 From: Claus Klein Date: Wed, 3 Dec 2025 04:14:01 +0100 Subject: [PATCH 5/6] CMakeLists.txt aktualisieren Co-authored-by: Jeff Garland --- examples/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 3517043..306ef6b 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -3,7 +3,7 @@ set(ALL_EXAMPLES scope_example unique_resource unique_resource-file) # module tests will only compile with gcc15 or clang20 and above -if(CMAKE_CXX_SCAN_FOR_MODULES AND CMAKE_CXX_STANDARD GREATER 20) +if(CMAKE_CXX_SCAN_FOR_MODULES) list(APPEND ALL_EXAMPLES scope-module) endif() From d62d6c4ec3de37bba9e63eab77bc093aff5e5309 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Wed, 3 Dec 2025 20:06:53 +0100 Subject: [PATCH 6/6] Respect review comments --- CMakeLists.txt | 2 ++ examples/CMakeLists.txt | 2 +- examples/scope-module.cpp | 9 +++++---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c1ab56..7b36f29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,6 +91,8 @@ install( FILE_SET CXX_MODULES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + CXX_MODULES_BMI + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/beman.scope/bmi-${CMAKE_CXX_COMPILER_ID}_$ FILE_SET HEADERS ) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 306ef6b..23ffaf7 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -3,7 +3,7 @@ set(ALL_EXAMPLES scope_example unique_resource unique_resource-file) # module tests will only compile with gcc15 or clang20 and above -if(CMAKE_CXX_SCAN_FOR_MODULES) +if(CMAKE_CXX_SCAN_FOR_MODULES AND CMAKE_CXX_MODULE_STD) list(APPEND ALL_EXAMPLES scope-module) endif() diff --git a/examples/scope-module.cpp b/examples/scope-module.cpp index 5cacd30..22dd6d3 100644 --- a/examples/scope-module.cpp +++ b/examples/scope-module.cpp @@ -15,11 +15,12 @@ // destroy noisy // scope exit: true success: true fail: false -#ifdef HAS_MODULE_STD +// #ifdef HAS_MODULE_STD import std; -#else -#include -#endif +// #else +// NOTE: this needs C++23! +// #include +// #endif import beman.scope;