-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Add entt as C++ module #1290
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: master
Are you sure you want to change the base?
Add entt as C++ module #1290
Conversation
* Make EnTT consumable as C++ module * Added `ENTT_MODULE` CMake option enabling EnTT compilation as C++ module * Added `ENTT_USER_CONFIG` CMake option to be able to specify C++ config defines
|
I've added free operators into exports as unlike member operators they're not reachable just by aliasing the according class. Also declaring unqualified |
|
This looks interesting. Quite a lot actually. Thanks for contributing! |
|
I was going to test this PR myself but I noticed that when |
|
@skypjack Hi, I see several benefits in this approach compared to the other one. I'll start right away with the one I see as the most important. There is an important difference between where all the definitions are located. In the other PR all the symbols are defined inside global module fragment (GMF 10.4). This fragment is meant for preprocessor directives, including includes of legacy code. When the module is built all symbols that are not decl-reachable (10.4.3) are dumped. This might lead to a situation described in the 2nd example (10.4.6), where a such defined symbol, might be "incorrectly" marked as unreachable and thus dumped away, resulting in compilation error. Due to this I'm highly concerned about You can see similar behavior even with STL being used in entt. When using It doesn't mean this approach is bad, for me it just seems more challenging to maintain (and thus error-prone) as you have to follow extra set of rules to ensure all symbols are decl-reachable. In this PR, all the entt symbols are defined in the module itself and are not dumped by the compiler the same way. All the intenal symbols are still reachable (but not visible) for the caller without the need to include the internals in another way. Another benefit I see is potentially less boilerplate (but that's somewhat questionable) as you don't need to re-export all the symbols again as in On the other hand, with the other approach you have nice concise list of all exported symbols at hand, but you have to manage it more carefully (when adding new symbol you need to think about adding it to an extra file). Also with the other PR's approach you don't have to care about dependencies again. As you just include the Also all the includes inside all the source files has to be suppressed to avoid linking unwanted symbols (like STL ones) to the module (as it will result in symbol ambiguity if STL and entt is included in some project). Technically, one can suppress only non-entt headers (+ few of the config headers) in modules and it might be possible to also include just And last thing to mention is that the GMF approach is meant mostly for the transition to modules and is more fit to wrap external library if one wants to use it in own project and doesn't have much control over the library's source. For the actual implementation the symbol definitions directly inside module seems more fit. I would really love to hear @elvisdukaj's opinion as I'm still not absolutely sure about everything personally. Even though modules are there for a few years already, they're still kinda new and niche and hard to put into existing codebases at work so hard to get to first hand experience with them still :) |
|
@theoparis installation should be fixed now. |
ENTT_MODULECMake option enabling EnTT compilation as C++ moduleENTT_USER_CONFIGCMake option to be able to specify C++ config definesI've noticed that similar pull rq is already ongoing but seems to be dead for a few months.
Instead of exporting symbols in separate files, export macros are used (similar to how fmt does it).
By setting
ENTT_MODULECMakeoption toONtheEnTT::EnTTtarget becomes module library allowingEnTTto be consumed asimport entt;.Another option
ENTT_USER_CONFIGis added toCMake. It can be used to configure entt as on can't simply #define all configurations inside source with modules.Usage example:
entt_config.hpp
CMakeLists.txt
Some explanation of this would be nice to put in wiki, unfortunately I can't pull request changes to wiki AFAIK.