-
Notifications
You must be signed in to change notification settings - Fork 186
Separate macro definitions and add cppm files #293
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
Conversation
The reason modules reliably worked when manually declared is because manually declared targets are affected by Shipping the module in a separate CMake target with a different (preferably the highest currently supported) C++ standard doesn't work well either: It places a much stricter requirement on the consumer compiler version. Too old and it will not work (for example older Clang which doesn't recognize The best way to provide modules support today seems to be providing only the |
It seems I've implemented the module support correctly. It's just that CMake hasn't implemented forward compatibility support for C++ modules yet: https://gitlab.kitware.com/cmake/cmake/-/issues/25909#note_1525432 . For now the exported module requires that the consumer has lower standard mode than proxy. For example if I change proxy itself to build in C++26 mode (and then install it), then the consumer can freely use C++20/23/26 mode. |
and provide workarounds in the docs.
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.
Thank you for the PR! The direction looks promising. Except for the inline comments, I don't feel the existing build system is robust enough, specifically
- The CI pipeline did not pass. We should ensure this change won't break existing code. However, I manually tested with the latest MSVC with CMake, and the build passed.
- Integration with other modules could be challenging. For example, if a user's build system prefers
import std;
, the includes in theproxy
module may generate ODR violation at some point. It could be even more challenging if a user uses thefmt
library with their module interface. We should ensure these scenarios are covered by unit tests.
1. Removed details directory 2. Use 2 space indention 3. `.ixx` suffix for module 4. Merged `proxy_interface` into `proxy`
for stdlib it shouldn't be a problem (they implemented the for fmt they have the But yeah, I haven't written unit tests for it yet because |
I think the CIs are failing on non-Windows systems because CMake doesn't have module support for Unix Makefile. Could they be changed to Ninja instead? Alternatively I can disable the module CMake target by default so that CI will succeed (but I'm not sure what to do with the doc page that provides modules example). |
and change some "proxy.h" to <proxy/proxy.h>
GCC 14.2 works with the PR in my local environment. Except GCC seems to required |
I've changed the GitHub Actions to use |
... if it's consumed as subdirectory.
I think we should either detect unsupported compilers in |
The module test isn't hard to address (use a variable to control enabling/disabling the test case). The C++20 module example codes extracted from docs are a different story. Currently it's extracted with Python script and all sources are globbed. I don't think it can support declaring an example as "only enabled when XXX variable is defined". Changing them to not use glob would work though. |
I filed #296 to allow exclusions. Please help review |
The doc test is now capable of handling multiple sources in a doc, with template support for CMake target definition. The C++ module example is also updated to take advantage of the new doc test generator. GitHub Actions is tweaked: - The compatibility CI now has reversed order, sorting from latest to oldest. - Known-incompatible compilers now have module disabled.
The extract_example_code_from_docs.py is updated. With an actual markdown parser, it's now capable of resolving multiple code blocks within the You can also use the Also much of the complexity of the doc test generator is now moved into the Python script. (IMO Python is much more readable and maintainable than CMake when the control flow gets complex) |
... by deferring creating directory after checking if code_blocks is empty.
I forgot to actually use it to decide if module target should be declared. How careless.
This time I locally tested it rather than assuming it will work. And it compiles with -D=PROXY_BUILDING_WITH_MODULE=FALSE.
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.
Thank you for your effort to make the proxy
module pass CI build! This journey was really impressive.
1. Reverted `extract_example_code_from_docs.py`. 2. Added "Module definition:" and "Client:" to cpp20_modules_support.md, to exclude it from the doc test generator. 3. Minor formatting issues (trailing EOL, empty lines ...) are fixed.
f957093
to
09ea107
Compare
Note: do not merge yet. I'm testing locally if it works as expected for all the toolchain combinations I have access to. |
Testing locally with CPM uncovered this problem: apparently CPM prevents the variables set by subdirectory projects from propagating to parent project. On the other hand CPM automatically sets a Note this issue doesn't affect The issue is addressed in 62f6c4d . include(cmake/CPM.cmake)
CPMAddPackage(
NAME proxy
GIT_TAG 62f6c4d1370c76a2f6a00cb16babc0092beee019
GIT_REPOSITORY https://github.com/SidneyCogdill/proxy.git
) Since with CPM there's no downstream packager, the |
"proxy.h"
to<proxy/proxy.h>
, to match the installed location (Oh the chaotic amount of changed files). Now that both the installed version (vcpkg/conan) and theFetchContent_Declare
/add_subdirectory
has the same include hierarchy for consistency..cppm
files for modules (similar to vulkan.cppm)I'm still undecided whether to ship two separateThere's now only oneproxy
/proxy_interface
modules, or to merge both intoproxy
(causing implementation details to be exported inproxy
module).proxy
module.Fixes #295.
and ignore this thx
For historical reference, in previous commits the module support is shipped with
msft_proxy
target:For installed version (e.g. the one package manager does),import proxy
should worksort of work afterfind_package(proxy)
andtarget_link_libraries
as thecppm
files are exported by the target.(I haven't tested it yet.)Consumer target must set to C++20 mode. C++23/26 mode causes the following compile time error for Clang 21: