Clang -fmodules-driver: C++20 modules and import std without an external build system
Earlier this year, Clang added basic support for building simple programs that use Clang modules or C++20 modules directly from the Clang driver, without an external build system. This includes using the std/std.compat modules: https://godbolt.org/z/sahYMsxna
The documentation landed yesterday (although the feature is already in Clang 23), so I thought I would advertise it here now: https://clang.llvm.org/docs/StandardCPlusPlusModules.html#compiling-modules-using-the-clang-modules-driver
This is still a very experimental feature, and it doesn't support caching yet. Currently, all modules used are recompiled on each invocation, which is especially painful with the large C++ Standard library modules.
The main purpose of this isn't to compete with dedicated build systems such as CMake, but to make modules more accessible. I hope this makes it easier to use modules in smaller examples, and maybe even in some people's first Hello World programs.
(This was part of a GSoC project I did in 2025. Happy to answer any questions!)
•
u/13steinj 3h ago
... am I drunk? Is this not... nearly the entire point of modules?
•
u/0navs 3h ago edited 2h ago
(The godbolt example just showcases the `import std` support since it is more difficult to showcase examples with multiple files on godbolt)