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

sqlite_orm as a C++ named module #1336

Draft
wants to merge 32 commits into
base: dev
Choose a base branch
from
Draft

Conversation

trueqbit
Copy link
Collaborator

@trueqbit trueqbit commented Jul 18, 2024

sqlite_orm can be imported as a C++ named module now.

  • The named module is exported by the the module interface unit file modules/sqlite_orm.ixx [msvc], modules/sqlite_orm.cppm [clang], modules/sqlite_orm.cxx [gcc].
  • Currently the sqlite_orm module in turn consumes the STL as a module, too, via import std.compat;. This means that the C++23 standard named modules std and std.compat must be available.
  • The CMake scripts install modules/sqlite_orm.* into ${CMAKE_INSTALL_LIBDIR}/cmake/SqliteOrm/src (following Craig Scott's writeup).
  • There's a new test target named "modules_test". It builds the sqlite_orm module and simply imports it in a bare .cpp file, in order to test whether those steps work. Otherwise no specific tests are executed.
  • C++ named modules require support from build systems. At the time of writing, CMake only provides experimental support for the dependency on the standard library modules [see CMAKE_EXPERIMENTAL_CXX_IMPORT_STD].
    -> Therefore, the test target “modules_test” is only defined when testing with Visual C++.
    -> Therefore, the named module still has to be consumed manually in a CMake script.

To discuss:

  • Because C++ named modules don't export macros, I think we need to provide sqlite_orm feature test macros in a traditional dedicated header file. These macros are e.g. used in examples to decide whether an example should be built, which is a public facing part of sqlite_orm [e.g. SQLITE_ORM_WITH_CTE, SQLITE_ORM_OPTIONAL_SUPPORTED].

* Added missing includes of dependent internal headers
* Cleaned up amalgamation files to only include the public facing high-level headers
Same as in all other locations
We need to take into consideration that exporting a namespace (as a named module) is kind of greedy in the sense that also nested namespaces are exported.
When importing sqlite_orm as a named module, sqlite3 symbols are not exported.
The `cxx_universal.h` exists to provide symbols that sqlite_orm depends on everywhere.
It is easy to forget to include it. And more importantly there are decision macros used that need to be defined before certain files anyway, which is the reason that `cxx_universal.h` gets included by the files used for amalgamation.
Hence I decided to not include it anymore.
@kelteseth
Copy link

Nice! Please create a PR when this is done at https://arewemodulesyet.org/ :D

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.

3 participants