From 00ef6eb9c88f01310053591c95cf8bb4eaf2a3b8 Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Fri, 30 May 2025 05:02:33 -0700 Subject: [PATCH 01/29] add module file for scope and modular example --- examples/scope-module.cpp | 47 ++++++++++++++++++++++++++++ include/beman/scope/beman.scope.cppm | 15 +++++++++ 2 files changed, 62 insertions(+) create mode 100644 examples/scope-module.cpp create mode 100644 include/beman/scope/beman.scope.cppm diff --git a/examples/scope-module.cpp b/examples/scope-module.cpp new file mode 100644 index 0000000..30c8512 --- /dev/null +++ b/examples/scope-module.cpp @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +// This example uses c++20 modules with beman.scope +// +// The following are by hand instructions for compiling with g++-15 +// first line generates gcm.cache file for standard headers - one time only +// g++-15 -std=c++26 -O2 -fmodules -fsearch-include-path -fmodule-only -c bits/std.cc +// g++-15 -std=c++26 -O2 -fmodules -fmodule-only -c ${scope_top}/include/beman/scope/beman.scope.cppm +// g++-15 -std=c++26 -fmodules scope-module.cpp +// +// prints: +// --> scope start +// construct noisy +// --> scope end +// destroy noisy +// scope exit: true success: true fail: false + +import std; +import beman.scope; + +struct noisy_resource +{ + noisy_resource() { std::print("construct noisy\n"); } + ~noisy_resource() { std::print("destroy noisy\n"); } +}; + +int main() +{ + + bool exit_ran, success_ran, fail_ran = false; + { + std::print( "--> scope start\n" ); + beman::scope::scope_exit _([&exit_ran] { exit_ran = true; }); + beman::scope::scope_success _([&success_ran]{ success_ran = true;}); + beman::scope::scope_fail _([&fail_ran] { fail_ran = true; }); + auto resource_ptr = beman::scope::unique_resource + ( + new noisy_resource(), + // Cleanup function + [](noisy_resource* ptr) { delete ptr; } + ); + std::print( "--> scope end\n"); + } // Normal scope exit + + std::print("scope exit: {} success: {} fail: {} \n", + exit_ran, success_ran, fail_ran); +} diff --git a/include/beman/scope/beman.scope.cppm b/include/beman/scope/beman.scope.cppm new file mode 100644 index 0000000..aa3c61f --- /dev/null +++ b/include/beman/scope/beman.scope.cppm @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// create the beman.scope.gcm in gcm.cache directory +// g++-15 -std=c++26 -O2 -fmodules -fmodule-only -c ${scopetop}/include/beman/scope/beman.scope.cppm +module; + +#include "scope.hpp" + +export module beman.scope; + +export namespace beman::scope { + using ::beman::scope::scope_exit; + using ::beman::scope::scope_fail; + using ::beman::scope::scope_success; + using ::beman::scope::unique_resource; +} From a9325806ad8ef586692022bde4bf643bb28bf13b Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Fri, 30 May 2025 05:10:39 -0700 Subject: [PATCH 02/29] run clang-format on new source --- examples/scope-module.cpp | 40 ++++++++++++---------------- include/beman/scope/beman.scope.cppm | 10 +++---- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/examples/scope-module.cpp b/examples/scope-module.cpp index 30c8512..15de96e 100644 --- a/examples/scope-module.cpp +++ b/examples/scope-module.cpp @@ -13,35 +13,29 @@ // construct noisy // --> scope end // destroy noisy -// scope exit: true success: true fail: false +// scope exit: true success: true fail: false import std; import beman.scope; -struct noisy_resource -{ - noisy_resource() { std::print("construct noisy\n"); } - ~noisy_resource() { std::print("destroy noisy\n"); } +struct noisy_resource { + noisy_resource() { std::print("construct noisy\n"); } + ~noisy_resource() { std::print("destroy noisy\n"); } }; -int main() -{ +int main() { - bool exit_ran, success_ran, fail_ran = false; - { - std::print( "--> scope start\n" ); - beman::scope::scope_exit _([&exit_ran] { exit_ran = true; }); - beman::scope::scope_success _([&success_ran]{ success_ran = true;}); - beman::scope::scope_fail _([&fail_ran] { fail_ran = true; }); - auto resource_ptr = beman::scope::unique_resource - ( - new noisy_resource(), - // Cleanup function - [](noisy_resource* ptr) { delete ptr; } - ); - std::print( "--> scope end\n"); - } // Normal scope exit + bool exit_ran, success_ran, fail_ran = false; + { + std::print("--> scope start\n"); + beman::scope::scope_exit _([&exit_ran] { exit_ran = true; }); + beman::scope::scope_success _([&success_ran] { success_ran = true; }); + beman::scope::scope_fail _([&fail_ran] { fail_ran = true; }); + auto resource_ptr = beman::scope::unique_resource(new noisy_resource(), + // Cleanup function + [](noisy_resource* ptr) { delete ptr; }); + std::print("--> scope end\n"); + } // Normal scope exit - std::print("scope exit: {} success: {} fail: {} \n", - exit_ran, success_ran, fail_ran); + std::print("scope exit: {} success: {} fail: {} \n", exit_ran, success_ran, fail_ran); } diff --git a/include/beman/scope/beman.scope.cppm b/include/beman/scope/beman.scope.cppm index aa3c61f..59ce381 100644 --- a/include/beman/scope/beman.scope.cppm +++ b/include/beman/scope/beman.scope.cppm @@ -8,8 +8,8 @@ module; export module beman.scope; export namespace beman::scope { - using ::beman::scope::scope_exit; - using ::beman::scope::scope_fail; - using ::beman::scope::scope_success; - using ::beman::scope::unique_resource; -} +using ::beman::scope::scope_exit; +using ::beman::scope::scope_fail; +using ::beman::scope::scope_success; +using ::beman::scope::unique_resource; +} // namespace beman::scope From a6ffc6e6b1191e0b4b113ad88c4bfe6ce2ad7250 Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Fri, 30 May 2025 05:17:23 -0700 Subject: [PATCH 03/29] formatting for humans in example --- examples/scope-module.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/scope-module.cpp b/examples/scope-module.cpp index 15de96e..c5f26e8 100644 --- a/examples/scope-module.cpp +++ b/examples/scope-module.cpp @@ -18,9 +18,10 @@ import std; import beman.scope; +// clang-format off struct noisy_resource { - noisy_resource() { std::print("construct noisy\n"); } - ~noisy_resource() { std::print("destroy noisy\n"); } + noisy_resource() { std::print( "construct noisy\n" ); } + ~noisy_resource() { std::print( "destroy noisy\n" ); } }; int main() { @@ -28,9 +29,9 @@ int main() { bool exit_ran, success_ran, fail_ran = false; { std::print("--> scope start\n"); - beman::scope::scope_exit _([&exit_ran] { exit_ran = true; }); + beman::scope::scope_exit _([&exit_ran] { exit_ran = true; }); beman::scope::scope_success _([&success_ran] { success_ran = true; }); - beman::scope::scope_fail _([&fail_ran] { fail_ran = true; }); + beman::scope::scope_fail _([&fail_ran] { fail_ran = true; }); auto resource_ptr = beman::scope::unique_resource(new noisy_resource(), // Cleanup function [](noisy_resource* ptr) { delete ptr; }); From 8000dfd99ea00e3e694845cf43bfe90bb21b9702 Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Fri, 30 May 2025 17:20:21 -0700 Subject: [PATCH 04/29] initial draft of module test even though cant cmake compile yet --- tests/module.test.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/module.test.cpp diff --git a/tests/module.test.cpp b/tests/module.test.cpp new file mode 100644 index 0000000..deaaa9f --- /dev/null +++ b/tests/module.test.cpp @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +import beman.scope; +// #include +// #include +#include + +// #define CATCH_CONFIG_MAIN +// #include + +// clang-format off +// struct noisy_resource { +// noisy_resource() { std::print( "construct noisy\n" ); } +// ~noisy_resource() { std::print( "destroy noisy\n" ); } +// }; + +//TEST_CASE("module-test", "[scope_module_test]") { +int main() +{ + bool exit_ran, success_ran, fail_ran = false; + { + beman::scope::scope_exit _([&exit_ran] { exit_ran = true; }); + beman::scope::scope_success _([&success_ran] { success_ran = true; }); + beman::scope::scope_fail _([&fail_ran] { fail_ran = true; }); + // auto resource_ptr = beman::scope::unique_resource(new noisy_resource(), + // // Cleanup function + // [](noisy_resource* ptr) { delete ptr; }); + } // Normal scope exit + + assert(exit_ran == true); + assert(success_ran == true); + assert(fail_ran == false); + + } From e619449d3e5bb5c34344ac7fabbce67a663a6b73 Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Fri, 30 May 2025 20:56:07 -0700 Subject: [PATCH 05/29] attempt to emulate exemplar modules PR --- CMakeLists.txt | 21 +++++++++++++++++---- tests/CMakeLists.txt | 12 ++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a3a79e..e56dfcc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,8 @@ project( VERSION 0.0.1 ) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + # [CMAKE.SKIP_TESTS] option( BEMAN_SCOPE_BUILD_TESTS @@ -29,10 +31,11 @@ option( ${PROJECT_IS_TOP_LEVEL} ) -add_library(beman.scope INTERFACE) +add_library(beman.scope) add_library(beman::scope ALIAS beman.scope) # gersemi: off + set_target_properties( beman.scope PROPERTIES @@ -42,22 +45,31 @@ set_target_properties( target_sources( beman.scope - INTERFACE + PUBLIC FILE_SET HEADERS BASE_DIRS include FILES include/beman/scope/scope.hpp + PUBLIC + FILE_SET CXX_MODULES + BASE_DIRS include + FILES include/beman/scope/beman.scope.cppm ) +include(GNUInstallDirs) + install( TARGETS beman.scope - EXPORT beman.scope-targets COMPONENT beman.scope + EXPORT beman.scope-targets + + FILE_SET CXX_MODULES + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILE_SET HEADERS ) + # gersemi: on if(BEMAN_SCOPE_INSTALL_CONFIG_FILE_PACKAGE) - include(GNUInstallDirs) include(CMakePackageConfigHelpers) write_basic_package_version_file( @@ -77,6 +89,7 @@ if(BEMAN_SCOPE_INSTALL_CONFIG_FILE_PACKAGE) EXPORT beman.scope-targets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/beman.scope NAMESPACE beman:: + CXX_MODULES_DIRECTORY cxx-modules COMPONENT beman.scope ) endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 55d7d48..54f0947 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -15,6 +15,18 @@ message("Tests to be built: ${ALL_TESTNAMES}") include(Catch) +add_executable(test.module) +target_sources(test.module PRIVATE module.test.cpp) +target_compile_features(test.module PRIVATE cxx_std_20) +target_compile_options(test.module PRIVATE "-fmodules") +# target_link_libraries( +# test.module +# PUBLIC FILE_SET TYPE CXX_MODULES include/beman/scope/beman.scope.cppm +# PRIVATE Catch2::Catch2WithMain beman::scope +# ) +# catch_discover_tests(test.module) + + foreach(testname ${ALL_TESTNAMES}) add_executable(test.${testname}) target_sources(test.${testname} PRIVATE ${testname}.test.cpp) From 7e7c3f4fc0fd6bf548bc140626a2227dd3b87601 Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Fri, 30 May 2025 20:57:13 -0700 Subject: [PATCH 06/29] Update CMakeLists.txt Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e56dfcc..d1bf843 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,7 +89,8 @@ if(BEMAN_SCOPE_INSTALL_CONFIG_FILE_PACKAGE) EXPORT beman.scope-targets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/beman.scope NAMESPACE beman:: - CXX_MODULES_DIRECTORY cxx-modules + CXX_MODULES_DIRECTORY + cxx-modules COMPONENT beman.scope ) endif() From 5f1d4996d6c47e802fdd68e6c57641921baee4b7 Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Fri, 30 May 2025 20:57:33 -0700 Subject: [PATCH 07/29] Update tests/CMakeLists.txt Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- tests/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 54f0947..bcb0bf6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -26,7 +26,6 @@ target_compile_options(test.module PRIVATE "-fmodules") # ) # catch_discover_tests(test.module) - foreach(testname ${ALL_TESTNAMES}) add_executable(test.${testname}) target_sources(test.${testname} PRIVATE ${testname}.test.cpp) From eb841050c5f8c4e994995f6afcaa5ed536f60566 Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Sat, 31 May 2025 06:03:39 -0700 Subject: [PATCH 08/29] working version of module.test - woohoo! --- CMakeLists.txt | 5 ++--- tests/CMakeLists.txt | 7 +++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d1bf843..0aa1188 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.25) +cmake_minimum_required(VERSION 3.28) project( beman.scope @@ -89,8 +89,7 @@ if(BEMAN_SCOPE_INSTALL_CONFIG_FILE_PACKAGE) EXPORT beman.scope-targets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/beman.scope NAMESPACE beman:: - CXX_MODULES_DIRECTORY - cxx-modules + CXX_MODULES_DIRECTORY cxx-modules COMPONENT beman.scope ) endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index bcb0bf6..d304ab0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -17,8 +17,10 @@ include(Catch) add_executable(test.module) target_sources(test.module PRIVATE module.test.cpp) -target_compile_features(test.module PRIVATE cxx_std_20) -target_compile_options(test.module PRIVATE "-fmodules") +target_link_libraries(test.module PRIVATE beman::scope) +add_test(NAME test.module COMMAND test.module) + +# todo: gc++15 module and catch incompatiblity? # target_link_libraries( # test.module # PUBLIC FILE_SET TYPE CXX_MODULES include/beman/scope/beman.scope.cppm @@ -26,6 +28,7 @@ target_compile_options(test.module PRIVATE "-fmodules") # ) # catch_discover_tests(test.module) + foreach(testname ${ALL_TESTNAMES}) add_executable(test.${testname}) target_sources(test.${testname} PRIVATE ${testname}.test.cpp) From 451ce8ed0f54d133d1d0544261e187c961e27463 Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Sat, 31 May 2025 06:07:55 -0700 Subject: [PATCH 09/29] Update tests/CMakeLists.txt Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- tests/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d304ab0..d41a412 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -28,7 +28,6 @@ add_test(NAME test.module COMMAND test.module) # ) # catch_discover_tests(test.module) - foreach(testname ${ALL_TESTNAMES}) add_executable(test.${testname}) target_sources(test.${testname} PRIVATE ${testname}.test.cpp) From aff35b1c2f974c4f89e6e345e2ce8730a5402f6b Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Sat, 31 May 2025 08:35:00 -0700 Subject: [PATCH 10/29] remove special case logic for module.test --- tests/CMakeLists.txt | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d41a412..46b54cc 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -9,25 +9,12 @@ FetchContent_Declare( ) FetchContent_MakeAvailable(Catch2) -set(ALL_TESTNAMES scope_success scope_exit scope_fail unique_resource) +set(ALL_TESTNAMES scope_success scope_exit scope_fail unique_resource module) message("Tests to be built: ${ALL_TESTNAMES}") include(Catch) -add_executable(test.module) -target_sources(test.module PRIVATE module.test.cpp) -target_link_libraries(test.module PRIVATE beman::scope) -add_test(NAME test.module COMMAND test.module) - -# todo: gc++15 module and catch incompatiblity? -# target_link_libraries( -# test.module -# PUBLIC FILE_SET TYPE CXX_MODULES include/beman/scope/beman.scope.cppm -# PRIVATE Catch2::Catch2WithMain beman::scope -# ) -# catch_discover_tests(test.module) - foreach(testname ${ALL_TESTNAMES}) add_executable(test.${testname}) target_sources(test.${testname} PRIVATE ${testname}.test.cpp) From 914483ddcab70297199a6111546e73fe97ba07bb Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Sat, 31 May 2025 08:35:54 -0700 Subject: [PATCH 11/29] reinstate catch2 into module test file, cleanup test --- tests/module.test.cpp | 56 ++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/tests/module.test.cpp b/tests/module.test.cpp index deaaa9f..b744d79 100644 --- a/tests/module.test.cpp +++ b/tests/module.test.cpp @@ -1,34 +1,36 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +#define CATCH_CONFIG_MAIN +#include + +// for g++-15 the order is important -- import after includes import beman.scope; -// #include -// #include -#include - -// #define CATCH_CONFIG_MAIN -// #include - -// clang-format off -// struct noisy_resource { -// noisy_resource() { std::print( "construct noisy\n" ); } -// ~noisy_resource() { std::print( "destroy noisy\n" ); } -// }; - -//TEST_CASE("module-test", "[scope_module_test]") { -int main() -{ - bool exit_ran, success_ran, fail_ran = false; + +struct DummyResource { + bool& cleaned; + + DummyResource(bool& flag) : cleaned(flag) { cleaned = false; } + + bool is_clean() const { return cleaned; } +}; + +TEST_CASE("module-test", "[scope_module_test]") { + bool exit_ran, success_ran, fail_ran, cleaned = true; { - beman::scope::scope_exit _([&exit_ran] { exit_ran = true; }); - beman::scope::scope_success _([&success_ran] { success_ran = true; }); - beman::scope::scope_fail _([&fail_ran] { fail_ran = true; }); - // auto resource_ptr = beman::scope::unique_resource(new noisy_resource(), - // // Cleanup function - // [](noisy_resource* ptr) { delete ptr; }); + // clang-format off + beman::scope::scope_exit _se([&exit_ran] { exit_ran = true; }); + beman::scope::scope_success _ss([&success_ran] { success_ran = true; }); + beman::scope::scope_fail _sf([&fail_ran] { fail_ran = true; }); + auto resource_ptr = beman::scope::unique_resource(new DummyResource(cleaned), + [](DummyResource* ptr) { ptr->cleaned =true; delete ptr; }); + REQUIRE(cleaned == false); + REQUIRE(resource_ptr->is_clean() == false); + // clang-format on } // Normal scope exit - assert(exit_ran == true); - assert(success_ran == true); - assert(fail_ran == false); + REQUIRE(exit_ran == true); + REQUIRE(success_ran == true); + REQUIRE(fail_ran == false); + REQUIRE(cleaned == true); - } +} From e1d97e9eee33abc05e6bca465d86d7ba7689c9d5 Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Sat, 31 May 2025 08:42:25 -0700 Subject: [PATCH 12/29] adopt ClausK's ci updates for cmake, compiler --- .github/workflows/ci_tests.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 348beba..cd94b3c 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -27,7 +27,7 @@ jobs: - name: Setup build environment uses: lukka/get-cmake@latest with: - cmakeVersion: "~3.25.0" + cmakeVersion: "~3.28.0" ninjaVersion: "^1.11.1" - name: Setup MSVC if: startsWith(matrix.presets.platform, 'windows') @@ -80,7 +80,7 @@ jobs: - name: Install Ninja uses: lukka/get-cmake@latest with: - cmakeVersion: "~3.25.0" + cmakeVersion: "~4.0.0" ninjaVersion: "^1.11.1" - name: Setup MSVC if: startsWith(matrix.platform.os, 'windows') @@ -139,7 +139,7 @@ jobs: - name: Setup build environment uses: lukka/get-cmake@latest with: - cmakeVersion: "~3.25.0" + cmakeVersion: "~3.28.0" ninjaVersion: "^1.11.1" - name: Print installed softwares run: | @@ -166,10 +166,10 @@ jobs: matrix: compilers: - class: GNU - version: 14 + version: 15 toolchain: "cmake/gnu-toolchain.cmake" - class: GNU - version: 13 + version: 14 toolchain: "cmake/gnu-toolchain.cmake" - class: LLVM version: 20 @@ -183,7 +183,7 @@ jobs: - name: Setup build environment uses: lukka/get-cmake@latest with: - cmakeVersion: "~3.25.0" + cmakeVersion: "~4.0.0" ninjaVersion: "^1.11.1" - name: Install Compiler id: install-compiler From f4f1f48d4290123ecbc5b77d10faa403c95efe97 Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Sat, 31 May 2025 09:17:20 -0700 Subject: [PATCH 13/29] adjust review-dog error level, maybe? --- .github/workflows/pre-commit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 029fa76..f3c4332 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -73,4 +73,4 @@ jobs: with: tool_name: pre-commit level: warning - reviewdog_flags: "-fail-level=none" + reviewdog_flags: "-fail-level=error" From 17694cd53902967c3540b36136075698bc51003d Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Sat, 31 May 2025 09:48:26 -0700 Subject: [PATCH 14/29] fix logic of module.test --- tests/module.test.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/module.test.cpp b/tests/module.test.cpp index b744d79..97ac643 100644 --- a/tests/module.test.cpp +++ b/tests/module.test.cpp @@ -6,6 +6,7 @@ // for g++-15 the order is important -- import after includes import beman.scope; + struct DummyResource { bool& cleaned; @@ -15,7 +16,8 @@ struct DummyResource { }; TEST_CASE("module-test", "[scope_module_test]") { - bool exit_ran, success_ran, fail_ran, cleaned = true; + bool exit_ran, success_ran, fail_ran = false; + bool cleaned = true; { // clang-format off beman::scope::scope_exit _se([&exit_ran] { exit_ran = true; }); From 99bb50fd744b3d656082109af289867a897def5f Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Sat, 31 May 2025 10:03:39 -0700 Subject: [PATCH 15/29] exclude compilers that dont support modules from compiling module.test --- tests/CMakeLists.txt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 46b54cc..6a5597e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -9,7 +9,16 @@ FetchContent_Declare( ) FetchContent_MakeAvailable(Catch2) -set(ALL_TESTNAMES scope_success scope_exit scope_fail unique_resource module) +message("Compiler is: ${CMAKE_CXX_COMPILER_ID} version: ${CMAKE_CXX_COMPILER_VERSION}") + +# module tests will only compile with gcc15 or clang20 and above +if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 20) + set(ALL_TESTNAMES scope_success scope_exit scope_fail unique_resource module) +elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15) + set(ALL_TESTNAMES scope_success scope_exit scope_fail unique_resource module) +else() + set(ALL_TESTNAMES scope_success scope_exit scope_fail unique_resource) +endif() message("Tests to be built: ${ALL_TESTNAMES}") From b1b04b110b520b1c62060e6f63a48f6a3fcf8c69 Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Sat, 31 May 2025 10:05:43 -0700 Subject: [PATCH 16/29] Update tests/CMakeLists.txt reviewdog Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- tests/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6a5597e..01ec649 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -9,7 +9,9 @@ FetchContent_Declare( ) FetchContent_MakeAvailable(Catch2) -message("Compiler is: ${CMAKE_CXX_COMPILER_ID} version: ${CMAKE_CXX_COMPILER_VERSION}") +message( + "Compiler is: ${CMAKE_CXX_COMPILER_ID} version: ${CMAKE_CXX_COMPILER_VERSION}" +) # module tests will only compile with gcc15 or clang20 and above if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 20) From ad6ccdf3d8ea7e43b04f49686488e630269448af Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Sat, 31 May 2025 10:06:45 -0700 Subject: [PATCH 17/29] Update tests/module.test.cpp Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- tests/module.test.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/module.test.cpp b/tests/module.test.cpp index 97ac643..a4b22fc 100644 --- a/tests/module.test.cpp +++ b/tests/module.test.cpp @@ -6,7 +6,6 @@ // for g++-15 the order is important -- import after includes import beman.scope; - struct DummyResource { bool& cleaned; From 618c04341a85bdecdc5e294d941211e0d7c9d147 Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Sat, 31 May 2025 10:12:56 -0700 Subject: [PATCH 18/29] minor spacing in cmake --- tests/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 01ec649..5b856db 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -15,11 +15,11 @@ message( # module tests will only compile with gcc15 or clang20 and above if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 20) - set(ALL_TESTNAMES scope_success scope_exit scope_fail unique_resource module) + set(ALL_TESTNAMES scope_success scope_exit scope_fail unique_resource module) elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15) - set(ALL_TESTNAMES scope_success scope_exit scope_fail unique_resource module) + set(ALL_TESTNAMES scope_success scope_exit scope_fail unique_resource module) else() - set(ALL_TESTNAMES scope_success scope_exit scope_fail unique_resource) + set(ALL_TESTNAMES scope_success scope_exit scope_fail unique_resource) endif() message("Tests to be built: ${ALL_TESTNAMES}") From 9639523f2de6d7cffbf0a521e8afff5e746972e9 Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Sat, 31 May 2025 10:25:02 -0700 Subject: [PATCH 19/29] revert the gnu workflow to 13 and 14 until 15 is available --- .github/workflows/ci_tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index cd94b3c..e005487 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -166,10 +166,10 @@ jobs: matrix: compilers: - class: GNU - version: 15 + version: 14 toolchain: "cmake/gnu-toolchain.cmake" - class: GNU - version: 14 + version: 13 toolchain: "cmake/gnu-toolchain.cmake" - class: LLVM version: 20 From c9f385d7f461e203094437c7e7430306f6648320 Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Sat, 31 May 2025 10:51:57 -0700 Subject: [PATCH 20/29] explicit changes to module support based on compiler versions --- CMakeLists.txt | 54 ++++++++++++++++++++++++++++++++------------ tests/CMakeLists.txt | 7 +----- 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0aa1188..072eeb7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,11 +31,47 @@ option( ${PROJECT_IS_TOP_LEVEL} ) -add_library(beman.scope) -add_library(beman::scope ALIAS beman.scope) - # gersemi: off +message( + "Compiler is: ${CMAKE_CXX_COMPILER_ID} version: ${CMAKE_CXX_COMPILER_VERSION}" +) + +# Modules opt in only on compilers that support g++-15 and clang-20 +if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 20) + set(CMAKE_CXX_SCAN_FOR_MODULES 1) +elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15) + set(CMAKE_CXX_SCAN_FOR_MODULES 1) +endif() + +if(CMAKE_CXX_SCAN_FOR_MODULES) + add_library(beman.scope) +# target_compile_features(beman.scope PRIVATE cxx_std_23) + target_sources( + beman.scope + PUBLIC + FILE_SET HEADERS + BASE_DIRS include + FILES include/beman/scope/scope.hpp + PUBLIC + FILE_SET CXX_MODULES + BASE_DIRS include + FILES include/beman/scope/beman.scope.cppm + ) +else() + add_library(beman.scope INTERFACE) +# target_compile_features(beman.scope INTERFACE cxx_std_20) + target_sources( + beman.scope + INTERFACE + FILE_SET HEADERS + BASE_DIRS include + FILES include/beman/scope/scope.hpp + ) +endif() + +add_library(beman::scope ALIAS beman.scope) + set_target_properties( beman.scope PROPERTIES @@ -43,18 +79,6 @@ set_target_properties( EXPORT_NAME scope ) -target_sources( - beman.scope - PUBLIC - FILE_SET HEADERS - BASE_DIRS include - FILES include/beman/scope/scope.hpp - PUBLIC - FILE_SET CXX_MODULES - BASE_DIRS include - FILES include/beman/scope/beman.scope.cppm -) - include(GNUInstallDirs) install( diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5b856db..df52186 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -9,14 +9,9 @@ FetchContent_Declare( ) FetchContent_MakeAvailable(Catch2) -message( - "Compiler is: ${CMAKE_CXX_COMPILER_ID} version: ${CMAKE_CXX_COMPILER_VERSION}" -) # module tests will only compile with gcc15 or clang20 and above -if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 20) - set(ALL_TESTNAMES scope_success scope_exit scope_fail unique_resource module) -elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15) +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) From 78afde7850c7875c6c92f8ecda1c14da61325691 Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Sat, 31 May 2025 11:00:23 -0700 Subject: [PATCH 21/29] more module scan tweaks --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 072eeb7..1e0faad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,8 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSIO set(CMAKE_CXX_SCAN_FOR_MODULES 1) elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15) set(CMAKE_CXX_SCAN_FOR_MODULES 1) +elseif() + set(CMAKE_CXX_SCAN_FOR_MODULES 0) endif() if(CMAKE_CXX_SCAN_FOR_MODULES) From ef85c4de7a866c621dddf1a94aabca5af9fb7f80 Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Sat, 31 May 2025 11:01:22 -0700 Subject: [PATCH 22/29] Update tests/CMakeLists.txt Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- tests/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index df52186..1444b00 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -9,7 +9,6 @@ FetchContent_Declare( ) FetchContent_MakeAvailable(Catch2) - # 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) From 4c77cca1140c1114454e830ada0efd155689f1ff Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Sat, 31 May 2025 11:01:50 -0700 Subject: [PATCH 23/29] Update CMakeLists.txt Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e0faad..cd57d97 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,7 +42,7 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSIO set(CMAKE_CXX_SCAN_FOR_MODULES 1) elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15) set(CMAKE_CXX_SCAN_FOR_MODULES 1) -elseif() +elseif() set(CMAKE_CXX_SCAN_FOR_MODULES 0) endif() From 4ed6f55079ac29c6d90f67baccf2bc8ec88ef8fc Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Sat, 31 May 2025 15:05:54 -0700 Subject: [PATCH 24/29] add cmake debugging for version --- CMakeLists.txt | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cd57d97..4cf938d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,17 @@ project( VERSION 0.0.1 ) +# gersemi: off + +# Modules opt in only on compilers that support g++-15 and clang-20 +if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 20) + set(CMAKE_CXX_SCAN_FOR_MODULES 1) +elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15) + set(CMAKE_CXX_SCAN_FOR_MODULES 1) +elseif() + set(CMAKE_CXX_SCAN_FOR_MODULES 0) +endif() + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # [CMAKE.SKIP_TESTS] @@ -31,24 +42,15 @@ option( ${PROJECT_IS_TOP_LEVEL} ) -# gersemi: off - message( "Compiler is: ${CMAKE_CXX_COMPILER_ID} version: ${CMAKE_CXX_COMPILER_VERSION}" ) - -# Modules opt in only on compilers that support g++-15 and clang-20 -if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 20) - set(CMAKE_CXX_SCAN_FOR_MODULES 1) -elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15) - set(CMAKE_CXX_SCAN_FOR_MODULES 1) -elseif() - set(CMAKE_CXX_SCAN_FOR_MODULES 0) -endif() +message( + "cmake is: ${CMAKE_VERSION} modules scan : ${CMAKE_CXX_SCAN_FOR_MODULES}" +) if(CMAKE_CXX_SCAN_FOR_MODULES) add_library(beman.scope) -# target_compile_features(beman.scope PRIVATE cxx_std_23) target_sources( beman.scope PUBLIC @@ -62,7 +64,6 @@ if(CMAKE_CXX_SCAN_FOR_MODULES) ) else() add_library(beman.scope INTERFACE) -# target_compile_features(beman.scope INTERFACE cxx_std_20) target_sources( beman.scope INTERFACE From 8a956059aada731e73db170b2b40d539a150b291 Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Sun, 1 Jun 2025 11:30:33 -0700 Subject: [PATCH 25/29] module test of clang-19 looks good, adding to supported --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4cf938d..9930901 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ project( # gersemi: off # Modules opt in only on compilers that support g++-15 and clang-20 -if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 20) +if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19) set(CMAKE_CXX_SCAN_FOR_MODULES 1) elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15) set(CMAKE_CXX_SCAN_FOR_MODULES 1) From d30afca1ef127bbb98f8f0b79f15e9ab85f28a20 Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Sun, 1 Jun 2025 15:59:41 -0700 Subject: [PATCH 26/29] update comment on modules support --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9930901..d7055ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ project( # gersemi: off -# Modules opt in only on compilers that support g++-15 and clang-20 +# Modules opt in only on compilers that support g++-15 and clang-19+ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19) set(CMAKE_CXX_SCAN_FOR_MODULES 1) elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15) From 6a6ee764a0e5c6f2d75ec05e6d2d38b2aa46756d Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Sun, 1 Jun 2025 17:07:37 -0700 Subject: [PATCH 27/29] update the readme.md for modules information. --- README.md | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ae6c14d..7eddf9d 100644 --- a/README.md +++ b/README.md @@ -85,23 +85,32 @@ Full runnable examples can be found in `examples/`. ## Integrate beman.scope into your project Beman.scope is a header-only library that currently relies on TS implementations -and is thus currently available only on GCC13 and up, or Clang 19 and up -- in C++20 mode. +and is thus currently available only on g++-13 and up, or clang 19 and up -- in C++20 mode. + +Note that modules support is currently tested only on clang++-19 and above and g++-15. As a header only library no building is required to use in a project -- simply make the `include` directory available add add the following to your source. ```cpp #include + +//modular version + +import beman.scope; ``` +With g++-15 modules is import needs to be after any includes to avoid compilation errors. ## Building beman.scope -Building is only required to run tests and examples. +Building is only required to run tests and examples. All compilers build and +run `include` based tests. Compilers known to support modules are automatically +detected added to tests. ### Build Dependencies -The library itself has no build dependencies other than Catch2 for testing -and cmake. +The library itself has no build dependencies other than Catch2 for testing. +And for building cmake and ninja. Makefiles are supported in non-modular builds. Build-time dependencies: @@ -110,14 +119,21 @@ Build-time dependencies: - CMake defaults to "Unix Makefiles" on POSIX systems - `catch2` for building tests -### How to build beman.scope +### How to build beman.scope tests and examples + +from root of repo: ```shell -cmake --workflow --preset gcc-debug +mkdir build; cd build; +cmake .. -DCMAKE_CXX_COMPILER=g++-15 -DCMAKE_CXX_STANDARD=26 -G=Ninja +ninja -j 5 -v; ctest +``` + +or using cmake presets +```shell cmake --workflow --preset gcc-release cmake --install build/gcc-release --prefix /opt/beman.scope ``` - # License Source is licensed with the Apache 2.0 license with LLVM exceptions From 54d2d7474a7de46ec6ad55009379eec854f7e06f Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Thu, 12 Jun 2025 17:45:15 -0700 Subject: [PATCH 28/29] minor doc tweak --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7eddf9d..55003db 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ the `include` directory available add add the following to your source. import beman.scope; ``` -With g++-15 modules is import needs to be after any includes to avoid compilation errors. +Withmodules import needs to be after any includes to avoid compilation errors. ## Building beman.scope From 0f4fd2eb55014dc0d1e76ccc624d96f74776820f Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Sat, 14 Jun 2025 09:58:50 -0700 Subject: [PATCH 29/29] revert modules back to clang-20 to see if CI cleans-up --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d7055ce..afdaf7d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,8 +11,8 @@ project( # gersemi: off -# Modules opt in only on compilers that support g++-15 and clang-19+ -if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19) +# Modules opt in only on compilers that support g++-15 and clang-20+ +if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 20) set(CMAKE_CXX_SCAN_FOR_MODULES 1) elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15) set(CMAKE_CXX_SCAN_FOR_MODULES 1)