Skip to content

Modules support#6

Merged
stephenberry merged 22 commits intoopenalgz:mainfrom
DockedFerret800:main
Mar 7, 2026
Merged

Modules support#6
stephenberry merged 22 commits intoopenalgz:mainfrom
DockedFerret800:main

Conversation

@DockedFerret800
Copy link
Contributor

@DockedFerret800 DockedFerret800 commented Feb 28, 2026

This PR adds optional native-modules support. Since the library is small, I decided to just create separate files with native modules, without wrappers. This will also mean that in the future, in case you decide to drop header support, this would be easier. Modules integration was tested on MSVC (14.51) and Clang 21 in Ubuntu WSL, with all tests passing.

This adds two new CMake options:

  • UT_ENABLE_MODULES: to enable modules.
  • UT_COMPILE_TIME: to enable compile-time features. This had to be moved to options due to the nature of modules.

This also adds a new workflow file to test on MSVC 14.50 and Clang 18. GCC is not tested, as GitHub Actions currently doesn't support GCC 15, which is required for import std. This should be resolved when Ubuntu 26 is released.

This PR is also needed for the Glaze integration (stephenberry/glaze#1586).

@stephenberry
Copy link
Contributor

@DockedFerret800, it looks like a more recent CMake is needed for the CI. Might need to be installed as part of the workflows if it ins't available in these current images.

@DockedFerret800
Copy link
Contributor Author

@stephenberry I've just pushed a fix. It was partially my fault that it wasn't running on modules workflow, as I forgot to specify compilers and it used GCC instead. We cannot test it on GCC as version 15 or above is required, and GitHub Actions runners don't have it yet. I expect GCC 16 to become available when Ubuntu 26 is released. For the old GCC and Clang workflow runners, I lowered the required version to 3.31, which is available on GitHub Actions runners. Please, approve workflows and we'll see if it works. If not - I'll use lukka/run-cmake@v10, the same I use in the modules workflow, which installs the latest version of CMake available. We'll have to raise a requirement to 4.3 anyway when it releases, so we can remove experimental string.

@DockedFerret800
Copy link
Contributor Author

@stephenberry I've pushed a fix. The Windows workflows should be working now, I've switched to a Visual Studio generator. Unfortunately, we won't be able to test on Clang either, because the shipped std module files are broken. We'll have to wait for a new Ubuntu runner with the latest GCC, Clang and Ubuntu. I checked locally on Ubuntu WSL with Clang 21, and it built successfully.

@stephenberry
Copy link
Contributor

I had AI look at this PR and provide 3 suggestions:

  1. Package export is currently broken for consumers
    find_package(ut CONFIG) resolves ut::ut, but exported include dirs contain invalid paths like .../COMPONENT, which causes configure failure.
    We should fix install(TARGETS ...) argument ordering and ensure install interface includes are set correctly.

  2. UT_COMPILE_TIME behavior changed for downstream users
    It is now default-on and exported through target compile definitions. That can break runtime-only tests in consumer projects.
    We should either restore default OFF.

  3. Module CI should test actual import ut; consumption
    Right now module CI builds with modules enabled, but our test/example sources can still stay on include path.
    Let’s add at least one module-only consumer test target that unconditionally uses import ut;.


The second point is simple to change. Do you think we can test the modules approach with CI?

@DockedFerret800
Copy link
Contributor Author

@stephenberry I pushed a commit to address the first two issues. Regarding the last one, I didn't quite get that one, we have a dedicated workflow that tests modules and forces import instead of include:

#ifndef UT_ENABLE_MODULES
#include "ut/ut.hpp"
#else
import ut;
#endif

@DockedFerret800
Copy link
Contributor Author

I think I got what it meant, I pushed a dedicated unconditional import test file.

@DockedFerret800
Copy link
Contributor Author

@stephenberry Would you like me to remove dead code in ut.hpp as well?

@stephenberry
Copy link
Contributor

@DockedFerret800, go for it! I think this is about ready to merge.

@stephenberry
Copy link
Contributor

@DockedFerret800, thanks for your help on this. I'm merging and I'll make a new release.

@stephenberry stephenberry merged commit 864c810 into openalgz:main Mar 7, 2026
7 checks passed
@DockedFerret800
Copy link
Contributor Author

@stephenberry Thank you for reviewing and merging. I'll now continue with Glaze.

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.

2 participants