-
-
Notifications
You must be signed in to change notification settings - Fork 452
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
C++20 module support #1317
Comments
After looking at |
I tried a couple of things and:
Othewise, this simple file does actually work for quite a few usage cases: module;
#define FLECS_CPP_ENUM_REFLECTION_SUPPORT 0
#include "flecs.h"
export module flecs;
export
namespace flecs
{
using ::flecs::world;
using ::flecs::entity;
using ::flecs::component;
[... other symbols etc.]
}
|
It seems possible to work around the issue a little by using 2 modules: module;
#define FLECS_CPP_ENUM_REFLECTION_SUPPORT 0
#include "flecs.h"
export module flecs_reexport;
export
namespace flecs
{
using ::flecs::world;
using ::flecs::entity;
using ::flecs::component;
[...]
// Export C symbols
using ::EcsPhase;
using ::EcsDependsOn;
} And then reexport the module in another module, in which we redefine the static symbols to make them accessible: export module flecs;
export import flecs_reexport;
export
namespace flecs
{
const flecs::entity_t Phase = EcsPhase;
const flecs::entity_t DependsOn = EcsDependsOn;
} This is of course far too hacky to be used within the library, but if any one else wants flecs in a module, this seems to be usable workaround in the meantime to be able to |
That does seem a bit hacky. Does this mean that the module'd version of Flecs won't be able to use enum reflection? What other benefits do modules provide besides being able to do |
With this version yes, I haven't really dug into the issue to know what's the reason behind it though. It's possible a simple change could fix this. There's also always the possibility of a compiler bug since modules aren't widespread yet. I think that a cleaner solution might also avoid this problem. I have to admit I'm still learning about what the proper ways to use modules are., but I suspect the proper approach is probably something along the lines of using a define to not use includes in
Nothing else I guess. Using modules does mean that no symbols except the exported ones are visible (so for example, we wouldn't expose the Anecdotally I went from around 4 seconds to compile a file including flecs to 2.5 seconds when importing flecs, but my machine is particularly old. |
I didn't think about the fact that maybe flux is header only, which makes it possible for them to define everything in modules directly when needed. Maintenance would amount to adding new types and functions when they are added to the C++ API. I don't know the exact capabilities of |
That is unfortunately a non-starter, since it'd be way too error prone and difficult to test. If it's something that can be done with just |
Noted - I'll try to think for another solution, but for now it doesn't seem to be possible to tackle this issue easily :/ |
Describe the problem you are trying to solve.
flecs.h
isn't small, and can slow down compilation of a file about 1-2 seconds on my machine.This can add up over multiple files.
C++ modules allow to reduce this by only exposing relevant symbols and pre-compiling the module so that it can be reused.
I tried wrapping
flecs.h
into a module manually, but it seems due to hownew
is used within the library this does not work.Maybe I'm missing something though.
Describe the solution you'd like
Add C++20 module support directly into flecs, allowing something like
import flecs;
.From what I checked in flux, C++ module support boils down to adding a define (something like
FLECS_EXPORT
) which expands toexport
or nothing depending on another define.Then, a module file is provided by the library which exports a module, enables this define and then includes the header to export the symbols.
The text was updated successfully, but these errors were encountered: