Conversation
Replace CppWinRTEnableLegacyCoroutines with CppWinRTEnableCpp17Coroutines Remove base_coroutine_system_winui.h, hasn't worked since PR 0.8 Support and test building with no coroutines Remove implementation selection machinery
Add error message for missing coroutine support in C++.
…ser/sylveon/modules
This is exciting, I'm going to give it a look. (Though I admit, I'm giving myself a crash-course in C++ modules - as in, I've heard about the goodness for years, but haven't actually kicked the tires until very recently) Just to be sure I understand, when you refer to the need to use the preview toolchain, are you saying that even though the C3779 issue is advertised as fixed in 18.4.0, there is a separate issue that is still blocking us? Is that a separate compiler bug that's being tracked somewhere? Based on some cursory research, I'm wondering if you are referring to the 14.51 preview toolset? And is it possibly related to this issue https://developercommunity.visualstudio.com/t/ICE-in-VS2026-Insiders-using-c-modules/10977663?sort=recent&viewtype=all? It might help us to coordinate, track, and test the working state while cutting down on duplicated effort if you could provide some specific toolset version numbers. |
|
For cppwinrt, the first step toward modularization is to extract all macros into a separate header file. cppwinrt has almost done this, but slim_source_location is placed in the wrong location. The second step is to fix all missing std qualifications and correct anything that is not part of the C++ standard. For example, memcpy_s is not part of the C++ standard and therefore will not be exported by std or std.compat. The third step is to make windows.numeric.impl.h an independent module on its own. This header file is not controlled by cppwinrt and indirectly introduces the standard library and Windows.h, so it must be isolated. The fourth step is to add appropriate macro guard so that the header file can be converted into a module implementation file while also being usable independently as a header file. You can refer to my blog post and the commit history in my repository to see how I achieved this. Additionally, it may be necessary to add inline and extern "C++" to allow both the module and the header file to be used simultaneously. I also recommend implementing at least different modules for different root namespaces, because third-party users, or even the WindowsAppSDK, might establish their own namespaces and should not be confused. I suggest that the module named winrt should only export the declarations in base.h. Finally, modules should not come from macro expansion and modules require that an entity declared in module A must be defined in module A (MSVC currently does not enforce this, but the standard and Clang require it.). Implementing modules in the way described above is actually not difficult. |
The issue is not fixed in the stable toolset on the latest release of VS. The minimum repro code from the developer community post is still broken. On the preview toolset, the minimum repro code works, however during compilation of the C++/WinRT ixx files, I get the following (which I do not see on stable), which is weird because we don't use
Which means I cannot confirm if the C3779 issue has been fixed for us. I've not been able to narrow that issue to a minimum repro either. I've pinged @cdacamar offline to see if he's seen this or can help figuring out the problem.
For this implementation, I moved the macros that are used by the implementation files to a new
Hilariously, I've not run into that
It pulls in a single header, So there is no pollution outside of
This has been done in my branch since 2021 :D
Some comments here:
|
|
I guess the reason you don't need to fix a large number of std qualifications and non-standard functions in your implementation is that windows.numeric.impl.h indirectly introduces them, which actually significantly slows down compilation and is also not ideal, see llvm/llvm-project#97239. |
|
If you create only one named module winrt, will compiler need to recompile the module after editing their own IDL? I haven’t looked into this, so I suggest verifying it. If different root namespaces use different modules, this issue can be directly avoided. Additionally, I’m not entirely sure how third-party WinRT libraries integrate into the user’s build process, as they may introduce more complex dependencies (they might create general C++ APIs on top of WinRT), which also requires further investigation. Therefore, I still recommend implementing separate modules for different root namespaces, as this has no drawbacks and avoids the aforementioned issues. |
It only rebuilds the affected ixx files. |
…ser/sylveon/modules
Obviously, modifying the user IDL will recompile the main module winrt, which means that code that only depends on the Windows namespace also needs to be recompiled. Only the unaffected module partitions of winrt do not require recompilation. |
|
We might have to do a bit of dancing to get the compiler to agree (e.g. if it only uses timestamp to determine if a rebuild has to be done, we might have to intelligently avoid stomping over unchanged files), but the theory is sound. A full E2E test (which we aren't quite close to yet) will determine if we have to do that. |
|
I mean, I have code that uses APIs from the Windows namespace, and it does not use APIs from the IDL I wrote. If you only implement a single module winrt, then this code indirectly depends on the IDL I wrote, even if it is not used. This dependency is established through the module winrt, not through module partition. Any modifications to the module partitions of winrt will result in the recompilation of the module winrt, even if it is merely exporting its module partitions. Modifying the IDL will cause this situation. Therefore, when I modify the IDL, any code imports winrt needs to be compiled because the module winrt depends on the modified IDL. The issue I am talking about is not related to recompiling a certain module partition. |


This picks back work from #953, bringing modular modules support to C++/WinRT.
This has several advantages over PCH:
winrt::impldoesn't even exist when you doimport winrt;Currently, this depends on this fix to build: https://developercommunity.visualstudio.com/t/Error-C3779-using-C20-modules-when-for/10879949
Unfortunately, I have not been able to make it work yet without bringing in the preview MSVC toolchain (which then causes issues with
import std;). This issue seems to have finally been fixed, but the above prevents me from fully testing.Basic usage of
winrt::hstringthroughimport winrt;does work though! (test_cpp20compiles if this is the only test activated)I've also included #1521 because it has some fixes that help modules (removal of definitions from base_includes, which aren't allowed in the global module fragment).
I'm still posting this as a WIP to let interested people try/look/comment on it.