-
Notifications
You must be signed in to change notification settings - Fork 5
Add support for C++ modules #205
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
base: main
Are you sure you want to change the base?
Conversation
|
Per the discussions recently, in order to avoid diamond dependency issues when packaging for vcpkg/conan, I may be moving away from any precompilation, and making the entire library header-only. Apologies for the noob questions - I haven't investigated modules at all, having spent all my time on coroutines and concepts instead. I've done some reading and it appears that modules offer a way to do the precompilation that's currently gated behind the TMC_IMPL macro, but in a more elegant fashion? If I just define a normal function as inline (necessary to prevent ODR violation in a header-only library), will modules prevent that from being recompiled in every translation unit, and instead provide a single compilation which can be reused? What is the impact of P1498R1 and P1779R3 on this library? Is there a recommendation that I should make member functions inline or not-inline? There is a typo on line 47: tmc::cpuexecutor Is there a more reliable method to export all of the symbols necessary so that I don't have to remember to update this file while I'm adding a header? In order to ensure that nothing else has been missed, mind forking the examples repo and adding a module build option there? To test there, |
|
Fixed the missing symbols and decided to alphabetise the |
|
Okay, so as you are probably aware, one notable advantage of modules is that modular translation units are compiled once and I believe that modules do not make all functions non-recompiled, but importers only have to compile against the already built module interface to get its definitions. Also, in modules, member functions are not implicitly |
|
@tzcnt Hi, is there anything else you want me to answer? |
|
I won't merge without compiling the full examples suite and tests using the module API. That's why I requested you open a PR into the examples repo. Otherwise I'll do it myself after I work through removing the IMPL macro requirement and review the package manager PRs |
Do you want me to duplicate all of the tests or do you want me to make it conditional on whether |
|
@tzcnt I do have a CMake working in my PR, and I have made several changes (such as using external linkage when building modules, and moving anonymous namespaces to detail namespaces). I'm just not really sure how to change your tmc-examples repo so that it can build with modules. |
|
Good enough would be a preprocessor macro used only in the tests (TMC_IMPORT_MODULE) that is used to swap between defines and includes in every file that needs them. #ifdef TMC_IMPORT_MODULE
import tmc::foo;
#else
#include "tmc/foo.hpp"
#endifIt's OK to do this for the main Thanks for your time and effort on this. |
|
The problem with this is that these are all in headers, where we have the following problems:
|
|
The tests are in .cpp files. There are some .ipp files that get included at the end of multiple .cpp files ,with different macro bases so I can test the same behavior on different executors. There are only a few .hpp files with some common behaviors. What's wrong with importing a module from a header? Is module like a viral thing so the consuming code also has to be 100% module-ified? |
|
The problem with importing a module into a header is that the module gets imported into every file that includes that header, which is risky and unstable. Also, you are right, the code is in .cpp files. However, the problem is that a lot of those files |
This PR adds support for C++ modules, which currently must be manually compiled (no
CMakeLists.txtexists).