Modules: Add C++20 modules component#4999
Modules: Add C++20 modules component#4999matejk merged 20 commits intopocoproject:mainfrom mikomikotaishi:main
Conversation
aleks-f
left a comment
There was a problem hiding this comment.
There should be some test and CI to verify it actually works
|
Just checked: *Impl classes must be exported unconditionally. |
|
Awesome. I tried this several times myself over the last few years. I actually found some ICEs in GCC trying to make Poco modules, which I believe are fixed in GCC 15. |
|
The only problem I am having now is determining which header inclusions need to be determined by platform. Modules should add all symbols, but because some symbols are platform-specific there must be conditional compilation over the operating system. Is there a list of what classes and what headers are platform specific? |
Headers without a suffix are generic for all platforms. Platform-specific headers have suffixes like _WIN32, _WIN32U, _POSIX. See also cmake/PocoMacros.cmake. Macros are used to prepare a list of headers during build process. Perhaps they could be reused to prepare modules and generate cppm files during build? |
|
I also wonder if there are single-include headers to include entire sections of the Poco library? I initially thought that was what some like |
There are no such headers. |
Then I guess the modules will solve this problem for those who can use them |
I have no experience writing CI tests but I tried writing one, hopefully it is sufficient to test building the modules |
|
OK, I have made my best attempt to address all the comments and suggestions made to this PR. Please let me know what else can be fixed before this can be merged. |
I will take some time to build and use it on different platforms however I can't promise that it will happen this week. |
|
In my opinion the modules should not be enabled by default, even with C++20 enabled. The user should have to explicitly enable them for now. I've done some research and can't find any evidence of a good/direct way to detect whether the current compiler and generator support C++ modules. This appears to be why so many of the CI steps are failing right now. C++20 is enabled, modules are enabled by default, and the Unix Makefiles generator is used. |
|
I agree with that, while modules are a standard feature of the language compilers still have unreliable support for them, and mostly bleeding-edge codebases are using them right now rather than widespread adoption replacing headers. To my understanding only GCC 14+, Clang 17+, and MSVC 2022 version 17.6+ support modules, and module support is dependent on build system too. I will make it opt-in for now, Makefiles with CMake do not support modules which is what the CI tests use |
|
I apologise for the silence/inactivity on this pull request, I have been busy with some other obligations. I will continue progress on this task soon. |
|
No problem. There is no deadline. |
|
I added the samples as requested which tests basic functionality with importing. |
|
@matejk Sorry about the delays. I tried to get some work on this task the other day, let me know at your own availability if there are any other concerns to address. I just test sample files and tested one or two classes ( |
|
Thank you very much for your effort. I tried this on Ubuntu 25.04, clang++ 20. Everything compiles and installs fine. I noticed in the installed file See I was not able to find out where these come from. Can you investigate this? |
|
I managed to merge cmake install macros into one. You can merge the changes from this branch: https://github.com/pocoproject/poco/tree/4999-cpp-modules |
Thanks! |
I'm a little confused, should that file not be included? Is this an extraneous file to the compilation process that is not needed? |
After running
When you install on your computer, cmake file probably contains paths to your source directory, however that is not OK. Only directories that are inside the installation directory shall be referenced. |
|
I think this should address the problem with the installation-relative paths. |
|
Seeing as the tests (are probably going to) pass, is this everything in line to merging the PR? |
|
Anything else before we can merge this? |
|
We did it! 🎉 |
Yes, we did! Thank you again for your cooperation. |
This pull request adds support for C++20 modules, which aggregate all header files. Modules must be built after the rest of the library is built, and modules match the namespace name (
Poco.*matchesPoco::*), and also has a single modulePocofor importing all modules. It is enabled usingENABLE_MODULES. A CI test has also been added to test compiling the module. I am sure many users of C++20 and future would be interested in using the Poco libraries as a module, so this library hopefully satisfies this.This exports all documented classes in https://docs.pocoproject.org/, and also the libraries
Poco::PDFandPoco::SevenZip. Modules also match the activatedENABLE_*options configured inCMakeLists.txt.