Your cart is currently empty!
Straggling with C++ experimental features
Today I’ve tried to play with recent standard C++ features as modules. Apparently they were implemented in C++20 but only partially since standard library imports are still work in progress. But there is an experimental support for those!
I thought there’s a straightforward way to enable them and how wrong I was! Nevertheless knowing the pains that C++ programmers are going through all the time (because I was one long time ago) I took it personal and continued digging.
Chapter 1
First of all it’s an experimental feature and it’s not supported with the standard toolchain from Apple (XCode 16 with customized version of clang 17). Apparently you need to download the latest llvm build using the brew install llvm || brew upgrade llvm
command and hook it up in your IDE settings (in my case it was CLion).
Chapter 2
Modules support you can enable fairly simple with the help of ChatGPT and bad words but the STD imports it’s not the case. First you need to enable an experimental feature that responsible for STD imports in CMAKE. It’s called CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
. But it’s not enough because all experimental features in CMAKE are hidden behind a specific GUID and for every new build it’s different so no AI or googling will help you.
Chapter 3
Apart from enabling standard feature for searching and scanning for modules in the codebase you need to enable CMAKE_CXX_EXTENSIONS
. Who could have thought? 🤦🏼♂️
Chapter 4
And if you think this is would be enough you are SO wrong my friend! The latest standard should be enforced separately with cxx_std_26
flag in the target_compile_features
function call (like it’s not enough to use CMAKE_CXX_STANDARD).
Chapter 5
No, it’s not the end. There is a bug in the latest llvm/CMAKE? build that prevents the build system from finding the standard library modules map file in json format so all the dependencies resolution with old includes work as expected. For that to fix you need to modify Clang-CXX-CXXImportStd.cmake
in your CMAKE’s installation folder. Don’t even ask how I found it!
Chapter 6
Don’t forget to add special compiler/linker feature flags.
Chapter 7
After straggling for couple of days finally I made it work. Though don’t ask for IDE support since the features are still into experimental phase.
Bottom line
Why??? The answer is simple – it is a long awaited feature since it removes a lot of the boilerplate code with header files and make a build process faster (at least in theory because the parallelism of this solution is till questionable).
Finally I deployed the code for other straggling programmers, enthusiast and AI agents online because we need to share with each other.