modules-report
modules-report copied to clipboard
C++20 Modules Status Report
"When can we begin to use modules?"
This document reports about the state of the ongoing effort to use C++20's modules across the C++ ecosystem - compilers, build systems, and (currently almost non-existent) libraries.
This document references a lot of work in progress, and will hopefully get outdated fast - so PRs to update and expand this document are very welcome.
Compilers Support
MSVC
MSVC have a complete implementation of modules. Support of C++23's
import std is done and was shipped in VS2022 17.5. However, it is recommended to wait until 17.6 because of some serious compiler bugs that were not fixed in time.
See here for a list of reported compiler modules bugs.
GCC
GCC has some support for modules, but it seems to still be pretty buggy and progress has pretty much stalled until very recently (Sep 22). See here for the state of the module papers and here for a list of reported bugs in the current implementation.
Clang
Work on Clang C++20 modules support is ongoing. See here for the state of module papers and here for module related issues. There's a lot of very recent progress, so working with upstream versions is probably best (binaries available from here).
This project explores modularizing libc++ with Clang. There's also some preliminary work to build a modular libc++ here.
Build Systems
CMake
CMake 3.26, released in 14th March, experimentally supports building C++20 modules. However, it relies on the module scanning protocol from P1689R5, which means it also requires dedicated compiler support. MSVC 17.4 and Clang 16 already support it. A series of GCC patches to add support for P1689R5 has now finally been merged to trunk, so expect support in GCC 14, somewhere in 2024Q2.
To enable this experimental support, you have to set the magic variable CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API (doc).
You can track changes relevant to modules on Kitware's GitLab. Relevant discussions are on their discourse or in this GitLab issue.
A stub project for using CMake with MSVC is available here.
For more details, you can read this recent blog post. This talk from about a year ago details the goals of the CMake modules support.
xmake
xmake seem to have a pretty good support for modules with all the big-three compilers, having rolled out their own dependency discovery code. Here's a good place to find usage examples.
Bazel
Relevant bazel issue is here.
rules_ll have support for compiling modules with Bazel + Clang. This is another Bazel modules attempt that targets Clang.
MSBuild
Should work (in Visual Studio).
Meson
Pretty old blogpost here.
Build2
Build2 supports building modules with GCC since the start of 2021. This blog post has details on how to use it, and there is a repository with various usage examples.
Standardization
The modules related discussions in WG21 happen in 'SG15', the committee's study group dedicated to C++ tooling. Its mailing list archive is open and available here.
IDEs
Visual Studio
As it is tightly integrated with MSVC and MSBuild, Visual Studio can be expected to work quite well with C++ modules. However, since IntelliSense is running with a different compiler frontend (EDG), it is not always up to par with MSVC in this regard.
CLion
CLion have announced support for C++ modules in their 2022.3 edition.
Libraries
ASIO
There's a modules port by Daniela Engert here.
fmtlib
fmtlib supports modules, but only on windows.
Boost
There was a discussion about modules in boost in April 2022 on their mailing list. Currently there seem to be no progress in this direction.
async_simple
There's experimental module support for xmake and cmake, see here.
SDL
There's a modules port by Daniela Engert here.
Ser20
Ser20, a C++20 cereal port (by myself), has experimental module support.
Usage Examples
LibTwo
LibTwo makes some usage of modules, particularly importing some third-party dependencies as modules here.
HiveWE
The open source HiveWE uses modules and has some practical examples.
Blogposts
- C++20 modules with GCC11 by Niall Cooling
- Moving a project to C++ named Modules - Cameron DaCamara
- C++20 modules with Clang - Eduardo Costa
- Integrating C++ header units into Office using MSVC (1/n) - Cameron DaCamara & Zachary Henkel