C++20 Modules: Practical Insights, Status and TODOs

https://news.ycombinator.com/rss Hits: 4
Summary

The post was written in Chinese and translated by LLM. Feel free to contact me if any phrasing seems unnatural. 25-08-22 update for Modules Wrapper,[One big thirdparty module], [suggested filename suffix], [mix include and import] C++20 Modules are beneficial for improving code modularity, enhancing program encapsulation, boosting compilation speed, and reducing the size of library code. Consequently, C++20 Modules have been highly anticipated since their inception. However, it is unsatisfactory that this feature, finalized in 2019, is still not widely adopted as of the latter half of 2025. This article shares findings and thoughts from our practical experience in developing and applying Modules, hoping to help friends interested in C++20 Modules. I am more familiar with Clang’s implementation and work exclusively in a Linux environment. Unless otherwise specified, the environment described in this article should be assumed to be Linux + Clang. I have not verified information related to Windows environments and GCC, so it may not align with the latest facts due to memory errors or outdated information. For basic knowledge about Modules, you can refer to background and terminology. For ease of reading, this article will be described from a high-level to a low-level perspective. Build System The build system I use at work is a version of Bazel that we’ve modified downstream. We are trying to contribute this implementation to the Bazel community. I have written some small examples with CMake with C++20 Modules, but I haven’t used it seriously. Therefore, this article will not cover CMake. However, in my memory, CMake seems to be a blocking issue for many people using C++20 Modules. The most memorable example is Boost’s Modules experiment, where one of the blocking issues mentioned was CMake. Additionally, XMake and Build2 also provide C++20 Modules support, and both projects have heavy users of C++20 Modules, so I have a good impression of them. There is also HMake, wh...

First seen: 2025-09-11 12:15

Last seen: 2025-09-11 15:15