Repository navigation
Implement support for C++20 modules - #1523
silvanshade wants to merge 45 commits into
Conversation
0f17eae to
898bb40
Compare
a402abe to
f868826
Compare
|
Thanks for working on this. |
f868826 to
7f6cd7b
Compare
04b3c64 to
d26b8d6
Compare
d0e58f3 to
0971a23
Compare
0971a23 to
19191d7
Compare
19191d7 to
c1e6209
Compare
|
I know this WIP, but how can this be tested? I compiled this branch with the feature enabled, but touching a file results in a cascade of recompilations. I tried it with GCC 14.2.1 and clang 21. |
|
@koplas the best way to understand what is currently working is to keep an eye on the cxx_modules test. That test will continue to be updated as the rest of the support is built out. Currently only GCC 14 is supported with regard to the caching of module artifacts. Support for MSVC is also almost ready. Most of the pieces are in place for that, I just need to implement some additional processing for the Clang support will arrive after that. It's not particularly difficult but does require some extra steps since the need to use As for how to test with GCC 14, you can take a look at the example here: ccache/test/suites/cxx_modules.bash Lines 91 to 93 in 11d614d Replace Direct mode and depend mode need to be enabled for You can also set the environment variable |
|
Thank you for your response! Enabling depend mode solved the issue, and I no longer experience recompilation cascades. |
This fixes the errors related to deprecation warnings about <ciso646>.
This change modifies the parsing of Makefile depend files to properly handle the additional output GCC >= 14 produces when compiling with the -fmodules[-ts] flag.
This commit combines multiple processing phases into a single phase: - path rewriting for `base_dir` - collecting includes from MSVC /showIncludes The motivation for combining these is because for MSVC C++20 module support, we also need to be able to process /sourceDependencies which prints a JSON object to stdout. Without this change, adding support for /sourceDependencies as a separate phase would mean potentially processing stdout up to three times per compilation.
This change is to allow modifying the context on deserialization of certain special file types related to C++20 modules (such as DDI files or similar). We sometimes need to use the data from these files to reconstruct information about the compilation context which cannot be obtained solely through the command-line arguments and which would otherwise require running the compiler and observing the output. Specifically this is a problem when trying to determine the correct output name for the BMI file. GCC does not allow to specify the BMI file-name, and the compiler chosen BMI name depends on the name (identifier) of the C++20 module in the translation unit. Clang and MSVC allow the output BMI file-name to be optionally specified but if it is not specified there is no guarantee or fixed schema for how the name will be chosen.
|
Was the work here abandoned? I was looking forward to using modules (although, without the distcc equivalent, it will still be difficult). |
It hasn't been abandoned but I don't know when it will be completed. What isn't visible in this PR is additional work I've done on preparing patches for both Clang and GCC which fill in most of the missing information for the p1689 files, in order to avoid having to rely on messy and error-prone heuristics to try and reconstruct or infer that information. The Clang work in particular is somewhat substantial because it replaces the need for I tried to avoid needing to go this route because obviously getting PRs upstream to facilitate this has its own challenges. But the reality is that the current state of module support and p1689 support is not sufficient for a good implementation of this feature. I am hoping I will have the chance to revisit this sometime early next year, and get those PRs submitted upstream, but I can't promise anything. |
|
Do you have anything written up on what needs to change in P1689 support? (My interest is that I authored P1689.) As for having |
I don't have anything concrete written up but that would be helpful. From what I remember of the last time I worked on this, it wasn't so much that the p1689 format itself was the issue as it was that Clang and GCC just didn't tend to fill in many of the fields that could have been used when constructing the manifests for caching. I don't remember the specifics, but things like knowing which input source file was compiled, what the corresponding object file was, what the other inputs/headers were, etc., basically all of the same kind of info that is reconstructed from the depfiles.
I see. I did in fact manage to get a single-pass front-end implementation to work, which emits the p1689 data during compilation (like with Makefile depfiles), but the implementation purposely lacks a lot of the functionality of That, and the fact that It wasn't clear to me how the project would react to that, although my impression was that Both the PRs for Clang and for GCC were actually in a usable state though, populating all of the fields specified in the p1689 spec (with the option for extra vendor specific data), but they needed some refactoring and commentary and justification before submission. Since people seem to be interested, I'll see if I can make those implementations available and link them here. |
|
Just out of curiosity, I noticed mozilla/sccache#2516 I think sccache are more complex than ccache, but that PR is 10x smaller than this. Would you like to tell the difference? Sorry if you feel uncomfortable, I am just interested. |
At a glance, that PR is doing far less than what this PR is doing, feature-wise. That PR appears to only partially support Clang (not GCC nor MSVC) based solely on specific command-line arguments. They don't parse the P1689 JSON files at all, nor the MSVC custom JSON format, nor process the Make depfiles for module artifacts (in GCC's case). It's a starting point but I wouldn't expect that approach to be a complete solution as far as C++20 module support goes. EDIT: Another difference, which isn't directly related to the feature support, but does make this PR larger, is that in some cases I've included updated documentation, bug-fixes, refactorings, substantial tests, and introduced some new abstractions (e.g., for the compiler) in order to make the code more maintainable and to help offset the additional complexity of module support. |
I'm the author of the other PR, maybe im missing something but in the context of sccache I dont think we would ever need to parse the P1689 output at all since we are not a build system so we dont need to decide how & what order to compile the modules, we rely on the build system (cmake or any other c++20 modules supported build system) to generate the correct compile commands and then we use those to correctly cache. This approach should work for both MSVC and Clang. The gcc approach is a bit annoying since it requires a bit more work, however cmake seems to use clang's dep scanner and then generates similar compile commands to clang. Maybe im missing something but why do you need to do all the extra work specifically for ccache? |
It's been a while since I've thought about thought deeply about this so I probably don't remember all of the exact details. The problem though is that if you don't parse the P1689 files, which I really think should be the closest thing to the source of truth from the perspective of external tooling, then you require on some other tool making all of the exact dependency details explicit through a big collection of command line flags. Currently this does work if you're compiling using a build system that provides this (like CMake) and everything is fully explicit on the command line. But it doesn't work if you're compiling with GCC where some of this information is implicit or potentially contained in non-standard entries in the Make depfiles (which I either was parsing or ignoring here depending on the exact context). It's also reasonable to assume I think that at some point the compiler frontends, particularly Clang's, might move more in the direction of providing a very lightweight interface for compiling a project with modules where almost all of the necessary information is implicit. The patches I worked on for the Clang frontend (which merged the clang-scan-deps functionality into the main frontend) worked more like this. There's also the fact that Theoretically, the P1689 provide a much more precise format for communicating the same information and more, so as long as ccache continues to function the way it does, it makes sense to also use the information from there. The problem is that (without the patches I mentioned working on), Clang and GCC leave a lot of the optional fields unpopulated. From a design perspective, I think it's also better in the long run for maintenance if the caching tools could rely more on the P1689 format, and less on parsing the compiler flags. The latter is a lot messier, because flags are different between compilers and between versions, and also just due to the nature of having to parse and normalize all of that into something usable. I don't know much about how sccache works so hard to say much beyond that. I would be curious to see how well the approach your considering seems to work in practice. I suspect getting a nice solution for GCC may be a bit involved. I'm not sure that relying on |
This is a PR intended to implement support for C++20 modules. The relevant issue is #1252.
I've submitted this early as a draft PR in case there is important feedback that might influence how this should be designed.
Implemented:
clang,gcc, andcl-fmodulesis used without-fdeps-formatRemaining:
clang-scan-depsThis is currently enough to get GCC to be able to cache and restore module artifacts for some simple compilations.
Some additional work remains to enable support for Clang and MSVC.