r/cpp • u/not_a_novel_account cmake dev • Jun 01 '26
BMI Compatibility: Testing Build System C++ Modules Support
https://blog.vito.nyc/posts/bmi-compatibility/
68
Upvotes
r/cpp • u/not_a_novel_account cmake dev • Jun 01 '26
18
u/PunctuationGood Jun 01 '26
The test:
The result:
So, silly question perhaps but how can it claim even experimental support if the "Hello, World" example of modules fails? What does it support if not that?
2
u/kamrann_ Jun 02 '26
Thanks for a great article.
This is an area of modules that I've never really got my head around, probably largely because I use build2 and work on a single project where all dependencies are compiled from source with a consistent language standard.
I'm curious about the potential dangers of recompiling BMIs from the consumer's context. If I understand right (and maybe I don't), it seems as if the XMake approach is essentially trading off a significant chunk of the ODR benefits modules were intended to provide? Recompiling with consumer definitions can presumably lead to the exact same kinds of problems you can get traditionally by having a mix of compiler/preprocessor options amongst TUs that share headers. Are there any guarantees even with CMake's less aggressive approach? Can't a swapped in language standard or compiler option lead to the consumer seeing a symbol which wasn't emitted into the upstream module unit object file? Or worse still, a mismatch in something like observed
sizeof(Type)?The example with the private header seems a little strange to me. The notion of a private header presumably means that in a traditional non-modules project, it would only have been included from cpp files or other private headers, allowing the build system to avoid propagating its path; in which case, why is it being included in a module interface in the first place? Or to look at it from the other way around, if it's included in an interface, then implicitly it's not private, and its path needs to be propagated.
25
u/GabrielDosReis Jun 01 '26
Great write up!
Agreed.
7
u/BadlyCamouflagedKiwi Jun 01 '26
Nice. If we want better build system support, it would be a bunch easier with more clear examples like this; given a simple (but not entirely trivial) repo, and some Makefiles to show what commands should be run (I suppose you'd need a gcc / clang fork, probably), someone familiar with Bazel could write support for it in that system. Without, that person also has to figure out what compiler invocations are needed, which isn't simple without something to look at as a model.
1
u/Agitated-Elk5768 Jun 02 '26
I tried your test on my build system. It failed in the fully automatic scanning mode, but I kept a semi-manual mode: direct dependencies must be specified explicitly, while indirect dependencies can still be resolved automatically. With that setup, everything works fine.
The root cause of all these issues seems to be the automation requirement itself.
What concerns me most right now is that clangd holds onto PCM files. I've already worked around some cases by renaming the files, but sometimes even renaming fails, and the only solution is to restart clangd. If I'm lucky, the build succeeds without problems. But even then, clangd has to be restarted to load the updated PCM files.
1
u/mwasplund soup Jun 07 '26
This feels like incidental complexity from how existing build systems manage dependencies which may have custom definitions that are incompatible. In your examples you are allowing the producer to explicitly define it's language version and then expect the build system to dynamically override this value to match the consumer. If a system is able to capture all incompatible configurations as a global definition for the closure of dependencies then it no longer needs to worry about injecting consumer context into the provider compilation operations. The language version would then be specified in the arguments for building the specific consumer and by extension the dependency producer would be built with BMI compatible flags.
7
u/ABlockInTheChain Jun 01 '26
If the question of "how are DLLs supposed work with modules?" ever came up during the committee meetings about modules, I'm certain that somebody must have said, "but why do you need DLLs now that we have modules?"