diff --git a/.clang-format b/.clang-format index 05baf03..d256b10 100644 --- a/.clang-format +++ b/.clang-format @@ -1,4 +1,7 @@ --- +BasedOnStyle: LLVM +IndentWidth: 2 +--- Language: Cpp AccessModifierOffset: -2 AlignAfterOpenBracket: Align @@ -106,11 +109,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..d0f5a17 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 + // 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 8da575f..a4daacd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,20 +7,21 @@ 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++ # 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] + types_or: [c++, c, json] # CMake linting and formatting - repo: https://github.com/BlankSpruce/gersemi - rev: 0.22.3 + rev: 0.23.1 hooks: - id: gersemi name: CMake linting @@ -30,7 +31,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 +41,4 @@ repos: - id: codespell args: ["--ignore-words-list=wil"] -exclude: 'cookiecutter/' +exclude: 'infra/' diff --git a/CMakeLists.txt b/CMakeLists.txt index 6cd404a..7b36f29 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 @@ -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 bfe8ef5..23ffaf7 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_MODULE_STD) + 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..22dd6d3 100644 --- a/examples/scope-module.cpp +++ b/examples/scope-module.cpp @@ -15,7 +15,13 @@ // destroy noisy // scope exit: true success: true fail: false +// #ifdef HAS_MODULE_STD import std; +// #else +// NOTE: this needs C++23! +// #include +// #endif + import beman.scope; // clang-format off 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}")