r/cpp • cmake dev • Jun 01 '26

BMI Compatibility: Testing Build System C++ Modules Support

https://blog.vito.nyc/posts/bmi-compatibility/
68 Upvotes

43 comments sorted by

View all comments

Show parent comment

2

u/not_a_novel_account cmake dev Jun 02 '26

something like an inline function

Yes, it's an astute observation, inline function definitions get serialized into BMIs so you can stumble into IFNDR ODR violations very indirectly this way, but this is as risky as header files, not moreso.

I'm just unclear on what constitutes a justified context for option swapping that isn't a liability

It is always a liability. It is necessary, otherwise the module is unusable in different language contexts. The question of "what to swap" is undecided, no one knows. There was work in this area from SG15, prior to the EcosystemIS being withdrawn, but nothing definitive. This is a big problem IMHO.

Maybe I'm misunderstanding your idea of a private header ... wouldn't be installed as part of the public interface of a library.

You're not misunderstanding, there is a new class of header involved here.

It is private in that it is restricted to the provider's context. Only translation units owned by the provider may #include this header. In this case it aligns with your understanding, private headers may only be used in "implementation".

The problem is with modules, implementation and interface are mixed together. We need to install module TUs, and thus we need ship any private headers they depend on. These headers need not be exposed to projects which consume the installed modules. You can't #include <private_header.hpp> in your project, the build system will not pass you the -I flags, but it will use the appropriate -I flags when creating the BMI.

1

u/kamrann_ Jun 02 '26

Thank you, this has clarified my understanding.

And yep I see now the distinction with the private header case and why you might want to do this. It's unfortunate that it's yet another complication that build systems have to deal with.