generated from bemanproject/exemplar
-
Notifications
You must be signed in to change notification settings - Fork 7
add module file for scope and modular example #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
00ef6eb
add module file for scope and modular example
JeffGarland a932580
run clang-format on new source
JeffGarland a6ffc6e
formatting for humans in example
JeffGarland 8000dfd
initial draft of module test even though cant cmake compile yet
JeffGarland e619449
attempt to emulate exemplar modules PR
JeffGarland 7e7c3f4
Update CMakeLists.txt
JeffGarland 5f1d499
Update tests/CMakeLists.txt
JeffGarland eb84105
working version of module.test - woohoo!
JeffGarland 451ce8e
Update tests/CMakeLists.txt
JeffGarland aff35b1
remove special case logic for module.test
JeffGarland 914483d
reinstate catch2 into module test file, cleanup test
JeffGarland e1d97e9
adopt ClausK's ci updates for cmake, compiler
JeffGarland f4f1f48
adjust review-dog error level, maybe?
JeffGarland 17694cd
fix logic of module.test
JeffGarland 99bb50f
exclude compilers that dont support modules from compiling module.test
JeffGarland b1b04b1
Update tests/CMakeLists.txt reviewdog
JeffGarland ad6ccdf
Update tests/module.test.cpp
JeffGarland 618c043
minor spacing in cmake
JeffGarland 9639523
revert the gnu workflow to 13 and 14 until 15 is available
JeffGarland c9f385d
explicit changes to module support based on compiler versions
JeffGarland 78afde7
more module scan tweaks
JeffGarland ef85c4d
Update tests/CMakeLists.txt
JeffGarland 4c77cca
Update CMakeLists.txt
JeffGarland 4ed6f55
add cmake debugging for version
JeffGarland 8a95605
module test of clang-19 looks good, adding to supported
JeffGarland d30afca
update comment on modules support
JeffGarland 6a6ee76
update the readme.md for modules information.
JeffGarland 54d2d74
minor doc tweak
JeffGarland 0f4fd2e
revert modules back to clang-20 to see if CI cleans-up
JeffGarland File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // 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; | ||
|
|
||
| // clang-format off | ||
| 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); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
JeffGarland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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; | ||
| } // namespace beman::scope | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #define CATCH_CONFIG_MAIN | ||
| #include <catch2/catch_all.hpp> | ||
|
|
||
| // for g++-15 the order is important -- import after includes | ||
| import beman.scope; | ||
|
|
||
| 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 = false; | ||
| bool cleaned = true; | ||
| { | ||
| // 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 | ||
|
|
||
| REQUIRE(exit_ran == true); | ||
| REQUIRE(success_ran == true); | ||
| REQUIRE(fail_ran == false); | ||
| REQUIRE(cleaned == true); | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If more than 60% of the CMake file is ignored, we might as well remove the cmake formatter.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are other cmake files. I have a bunch of clang-format exclusions as well -- that doesn't mean I want it all turned off.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pro removing the formatter, it's too wrong too often to really be useful