Skip to content

Implement modules support#15

Open
yesmanchyk wants to merge 23 commits into
bemanproject:mainfrom
yesmanchyk:yesmanchyk_modules
Open

Implement modules support#15
yesmanchyk wants to merge 23 commits into
bemanproject:mainfrom
yesmanchyk:yesmanchyk_modules

Conversation

@yesmanchyk
Copy link
Copy Markdown

@yesmanchyk yesmanchyk commented May 10, 2026

This implementation is based on bemanproject/exemplar#380

There are some key differences, however:

  1. I use import beman.scan_view; instead of #include <beman/scan_view/scan.hpp> in tests and examples.
  2. I had to include all dependencies as headers into global module fragment because import std; resulted in compilation errors when I tried gcc 16 and clang 21.
  3. Due to above 2 reasons I extracted the beman::scan_view implementation into scan_view.hpp without any changes.

@yesmanchyk yesmanchyk requested a review from Mick235711 as a code owner May 10, 2026 20:13
Comment thread examples/complex_example.cpp
yesmanchyk and others added 2 commits May 10, 2026 16:22
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Comment thread tests/beman/scan_view/basic.test.cpp Outdated
Comment thread .github/workflows/ci_tests.yml
Comment thread examples/basic_example.cpp Outdated
Comment thread include/beman/scan_view/scan.hpp
Comment thread infra/cmake/enable-experimental-import-std.cmake
Comment thread infra/cmake/enable-experimental-import-std.cmake Outdated
Comment thread include/beman/scan_view/scan_view.cppm Outdated
#include <optional>
#include <ranges>
#include <type_traits>
#include <utility>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting standard library includes in the global module fragment is not the approved modules mechanism for this project. To merge this, you'll need to figure out how to get import std building. The best approach would be to do so by building with a supported container or with beman-local-ci.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I solved it in yesmanchyk@f196c4b. However, the line 7 looks like a hack to me even though CI is passing. Maybe it's worth restoring the global module fragment with a single #include <version> inside? I don't know a way to export library feature-test macros with import std;.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One way is import <version>, but I'm not sure header units are an approved mechanism, nor am I sure all targets support header units well enough...

As mentioned below, it seems that #include <version> (and things like <cstdarg>, <cassert>) is now allowed as a special exception in the GMF.

Copy link
Copy Markdown
Member

@ednolan ednolan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! Just a few more small comments. By the way, you can use pre-commit run --all-files as a convenient way to apply clang-tidy and ensure that the lint check passes.


import std;

using size_t = std::size_t;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of doing this, change all the instances of non-namespaced size_t to std::size_t.


using size_t = std::size_t;

#define __cpp_lib_ranges 202207L
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I should have mentioned, but if a C++ standard library header just defines macros, you can put it in the global module fragment, so <version> is fine here, as is <cassert>

#include <gtest/gtest.h>
#if BEMAN_SCAN_VIEW_USE_MODULES()

#include <gtest/gtest.h>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're including <gtest/gtest.h> in both branches, so just move it to before the #if BEMAN_SCAN_VIEW_USE_MODULES().

Copy link
Copy Markdown
Collaborator

@Mick235711 Mick235711 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for working on this!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this file be committed? If it is just an temporary intermediate file, please put it in .gitignore.


#else

#if !BEMAN_SCAN_VIEW_USE_MODULES()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should probably use #elif here

Comment thread CMakeLists.txt
Comment on lines +29 to +33
option(
BEMAN_SCAN_VIEW_USE_MODULES
"Provide beman.scan_view as a C++ module"
OFF
)
Copy link
Copy Markdown
Collaborator

@Mick235711 Mick235711 May 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should mention this new flag somewhere in README (or CONTRIBUTING.md)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants