Description
I've been trying out the std
module in libc++
with build2
(per the Modules in libc++ documentation) and everything seems to work without any issues, at least on simple examples. Very impressive, I must say.
There is just one snag: std.cppm
is not installed. Quoting the relevant part from the above documentation:
Once libc++'s implementation is more mature we will reach out to build system vendors, with the goal that building the BMI files is done by the build system.
Currently this requires a local build of libc++ with modules enabled. Since modules are not part of the installation yet, they are used from the build directory.
In build2
we have the ability to build BMIs of external libraries on the fly (this is needed for consuming modules from installed libraries). So if std.cppm
were installed somewhere where we could find it, then this would work pretty much out of the box in our case.
I can see two immediate questions about installing std.cppm
: where to install it and how to make it self-contained (currently, it #include
s a large number of files from the std/
subdirectory).
Regarding where to install, I would suggest just installing it next to the headers (e.g., into /usr/include/c++/v1/
). I can think of two advantage with doing it this way:
-
There is already a way for a build system to find this directory (by parsing the header search paths in the
-v
output) and some build systems already do this (for example, inbuild2
we extract the compiler's header and library search paths). -
The
std.cppm
file will end up in the right distribution package (e.g.,-dev
on Debian,-devel
on Fedora, etc) without any extra effort.
The only objection I've heard to installing modules next to headers is that "it's not a header" and "it may be included by mistake". While both are true, we are already installing non-header files (e.g., inline/template implementation files) and nobody seems to be including them by mistake. We could also take an extra measure to preclude this by, for example, installing the modules into a subdirectory (e.g., /usr/include/c++/v1/modules/
).
Regarding making std.cppm
self-contained, I assume there is no desire to install all the 100+ files from std/
that it includes (though there is nothing technically bad about doing it, just feels unnecessary). It seems the easiest would be to just append their contents to std.cppm.in
instead of #include
ing them. Though I am not sure if this is easy to achieve in CMake.
Thoughts?
P.S. For completeness, let me also mention what I've done as a (hopefully) temporary measure in build2
to support import std
right now. I've made a self-contained std.cppm
(as described above), patched it slightly so that it works for both libc++
17 and 18, and bundled it with build2
. In other words, instead of being installed with libc++
, it is being installed with build2
(again, hopefully temporarily and into build2
's own directory, naturally).