Skip to content

Add C++20 modules support and format btw.#669

Open
Perdixky wants to merge 2 commits into
getml:mainfrom
Perdixky:main
Open

Add C++20 modules support and format btw.#669
Perdixky wants to merge 2 commits into
getml:mainfrom
Perdixky:main

Conversation

@Perdixky

Copy link
Copy Markdown

As the library depends on C++20, I think the support for modules is definitely important 😊
So I’ve added this.
If this change is approved, I’ll add the corresponding documentation later.
By the way, should we convert all the test files to use modules? This would prevent errors caused by missing exported entities, but it might be a bit aggressive.

Perdixky and others added 2 commits May 17, 2026 22:42
Add an opt-in REFLECTCPP_BUILD_MODULES path that registers CMake CXX_MODULES file sets for rfl, generic, cli, JSON, and each optional serialization format when its existing feature option is enabled.

The module interfaces include the existing public headers in the global module fragment, then explicitly re-export reflect-cpp public names with using declarations. That keeps the include headers as the source of truth while avoiding attaching standard-library and C headers directly to named modules.

Change namespace-scope public constants and module-visible helpers from internal-linkage static objects/functions to inline constexpr/inline forms. Exported templates can otherwise refer to entities owned by one module interface translation unit, which makes the imported API depend on unstable TU-local addresses and can diverge from include mode.

Signed-off-by: Perdixky <3293789706@qq.com>

Co-authored-by: Codex <codex@openai.com>
Apply clang-format to include/rfl/cli/Reader.hpp only.

Signed-off-by: Perdixky <3293789706@qq.com>

Co-authored-by: Codex <codex@openai.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces experimental support for C++20 modules, adding module interface files and updating the CMake build system to support module compilation and installation. It also refactors internal headers to use inline and constexpr for improved linkage. Feedback highlights that changes to the third-party yyjson.h header break C compatibility by using C++-specific keywords; these macros should be guarded with preprocessor checks to maintain support for C users.

Comment thread include/rfl/thirdparty/yyjson.h
@liuzicheng1987

Copy link
Copy Markdown
Contributor

Hi @Perdixky , thanks for your contribution. To be honest, we have tried adding module support a while ago and back then there were so many problems that we decided modules are not yet ready for prime time. But I'd be happy to give them another try.

@liuzicheng1987

Copy link
Copy Markdown
Contributor

@Perdixky , could you also add the module tests that you have written to the automated Github Actions testing pipeline? It does not appear that your tests are actually compiled or executed.

@liuzicheng1987

Copy link
Copy Markdown
Contributor

@Perdixky, are you planning to continue working on this? Otherwise I will have to close this due to inactivity?

@Perdixky

Copy link
Copy Markdown
Author

@Perdixky, are you planning to continue working on this? Otherwise I will have to close this due to inactivity?

@liuzicheng1987 , I'm a bit busy at this moment, but I'll follow up on this work! Please bear with me for a few weeks!

@liuzicheng1987

Copy link
Copy Markdown
Contributor

@Perdixky no problem!

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.

2 participants