Add C++20 modules support and format btw.#669
Conversation
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>
There was a problem hiding this comment.
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.
|
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. |
|
@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. |
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.