Skip to content
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

Add C++20 module build target #1364

Closed
wants to merge 4 commits into from

Conversation

Gaspard--
Copy link
Contributor

@Gaspard-- Gaspard-- commented Sep 19, 2024

Usage in client cmake:

set(FLECS_M0DULE ON CACHE BOOL "Build flecs module" FORCE)
add_subdirectory(path/to/flecs)
# If the c++ version of the project isn't c++20, the matching version must be set manually
target_compile_features(flecs-module PUBLIC cxx_std_23)
target_link_libraries(
  someProjectName
  PRIVATE
  flecs-module
)

In the code, it is then possible to use import flecs; to import all the flecs symbols.

Still investigating why reflection seems to break, disabled in the module for now. Fixed.

Maintainance:

  • structs exposed by flecs must be tagged with FLECS_API_STRUCT
  • code within the c++ addon tagged with FLECS_API are exposed
  • globals must be tagged with FLECS_API_GLOBAL, which becomes static in headers, and export in the module.

Closes #1317

@Gaspard--
Copy link
Contributor Author

This is a first working version, I don't know flecs enough for what approaches might be preferred for the define names and usage.

@Gaspard--
Copy link
Contributor Author

Ah, seems my fix for the modularised version of flecs on windows broke the normal build.
I guess this means we need another define for the specific case of operator new.
Currently testing gcc, clang++ and msvc work with the modularized version.

@Gaspard--
Copy link
Contributor Author

g++'s module support is incomplete, and the work around seems to big to be worth it right now.

@Gaspard--
Copy link
Contributor Author

@SanderMertens can I have your thoughts on this approach ?
Also, if this is not mergeable, I could just maintain the fork until C++ modules mature a little more.

Usage in client cmake:
```cmake
set(FLECS_M0DULE ON CACHE BOOL "Build flecs module" FORCE)
add_subdirectory(path/to/flecs)
target_compile_features(flecs-module PUBLIC cxx_std_23)
target_link_libraries(
  someProjectName
  PRIVATE
  flecs-module
)
```

In the code, it is then possible to use `import flecs;` to import all the flecs symbols.

Still investigating why reflection seems to break, disabled in the module for now.

Maintainance:
- structs exposed by flecs must be tagged with `FLECS_API_STRUCT`
- code within the c++ addon tagged with `FLECS_API` are exposed
- globals must be tagged with `FLECS_API_GLOBAL`, which becomes `static` in headers, and export in the module.
Not having it visible breaks compilation on msvc
- Improve define names
- Split FLECS_GLOBAL_API in two because `export` comes before template delcarations and `static` afterwards
- Fix enum reflection
@Gaspard--
Copy link
Contributor Author

Closing this PR since #1410 supersedes it.

@Gaspard-- Gaspard-- closed this Oct 22, 2024
@Gaspard-- Gaspard-- deleted the flecs_cpp20_module branch October 23, 2024 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

C++20 module support
1 participant