<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/73089>73089</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Please consider installing `std.cppm` in `lib++`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          boris-kolpackov
      </td>
    </tr>
</table>

<pre>
    I've been trying out the `std` module  in `libc++` with `build2` (per the [Modules in libc++](https://github.com/llvm/llvm-project/blob/main/libcxx/docs/Modules.rst) 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:

1. 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, in `build2` we extract the compiler's header and library search paths).

2. 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).

@mordante @iains @ChuanqiXu9 @dwblaikie @mathstuf
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUV11v4zoO_TXuCzFGokya5iEP084G6MNg7-4s9u4rbTGxbmXJo4-k_vcLUnaapHuxuMBMk8iWRB4eHpIYozk6ol21fq7W3x8wp86HXeODiV_evB2wffOnh8brcfdaqc2JoCFykMJo3BF8TpA6gupxEZOuHhfQe50tARjHi9Y0baWe-d_jAs4mdbzaZGO14pVKPQ0UyhHr5x-yN_Leq43r75V66lIaYrX6Vql9pfZHk7rc1K3vK7W39jR_fBmC_4PaVKl9Y31TqX2PxvFD07Tv75Xaa9_GSu2nm-oQU6W2oH2be3IJk_GOF9BpoBOFMXXsZiTqIyQPZx_exA12HN0IJsZMsVIvgAksYUzgHUTTD5aA3pE_Yw3_pjCC6YdAMZoT8fuv0OeYIOJYV4vv1eJb-fuvjgKBifBHlrMIosNjtfo2YVy3w9AzdCaC8wmMiwmtJV3DP7JPbC2jGcjSCV2CAUOCQ_C9LGPjT3Tn7urb9f3V6m_wd9fSdQTUJoJ4dNnEt_c-EPSYciA4E5yNtRAI266wwoOEGeIYE_VwIqd9EKSEBmzN0aOF1GEqr862P_94hYMRIkTQDEEzyoPrA-uLuR92v-QQyCXLb5sIgX5lEygCgvUt2mm_P1z5VozpJ-KRw0ag_GkYgnkZAwnWgqU_iC0T7gWNkRI7ljoa5eUcSX-AXq7VJlCbfLgN96u7TYgzQYcnmoJlrEnjB5TPP14j30_viYJDy34EDIYik463HOzIOSXuM0GINFviA7TexdwzxLNXYt-FPh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