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

    <tr>
        <th>Summary</th>
        <td>
            [ C++20 ] [ modules ] [ libc++ ] All BMIs are irreproducible
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          aaronmondal
      </td>
    </tr>
</table>

<pre>
    @ChuanqiXu9 @mordante Sorry for creating this issue so late. This is what I mentioned in the last meeting.

Modules reference BMIs via absolute paths. This makes it impossible to e.g run module precompilation on remote executors. It makes all precompilations irreproducible to a degree that you couldn't reuse the same BMIs on two identically setup machines where just the *username* differs.

The workaround currently employed in `rules_ll` is to disable sandboxing and remote execution for precompilations, but that can significantly impact performance down the line. Irreproducibility is transitive. If a single module is used, all other targets depending on that can't be built remotely and are irreproducible across systems. Since libcxx is pretty much always at the root of any dependency graph, this means that any build using module `std` (https://reviews.llvm.org/D144994) will be fully irreproducible.

This doesn't only affect Bazel, it affects CMake as well but isn't noticeable during local builds since CMake doesn't use sandboxing in the same way.

For module `std` we're already telling users build the BMIs themselves, but maybe as warning to any distro maintainers experimenting with this: *At the moment all precompilations leak absolute paths from the build machines into the BMIs.*

```bash
mkdir include

echo "" > include/myheader.h

printf '
module;

#include "myheader.h"

export module mymodule;
' > mymodule.cppm

printf '
import mymodule;

auto main() -> int { return 0; }
' > main.cpp

# Prepare first sandbox.
mkdir -p sandbox/include
cp mymodule.cppm sandbox/mymodule.cppm
cp include/myheader.h sandbox/include/myheader.h

# Simulate first sandboxed compilation.
cd sandbox
# Adding `-Xclang -fmodules-embed-all-files` makes the next compilation pass,
# but still leaves irreproducible, absolue paths in the pcm.
clang -v -std=c++20 -Iinclude --precompile mymodule.cppm -o mymodule.pcm
cp mymodule.pcm ..
cd ..
rm -rd sandbox

echo

# Prepare second sandbox.
mkdir sandbox2
cp mymodule.pcm sandbox2/mymodule.pcm

# Simulate second sandboxed compilation.
cd sandbox2
clang -v -std=c++20 -c mymodule.pcm -o mymodule.o
cp mymodule.o ..
cd ..
rm -rd sandbox2

# Print strings. If you used `-Xclang -fembed-module-files` this still contains
# irreproducible absolute paths to no longer existent sandbox.
printf '
IRREPRODUCIBLE PATHS:
'
strings mymodule.pcm | grep sandbox

# Cleanup.
rm -rd include
rm main.cpp mymodule.cppm mymodule.pcm
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEV11v47oR_TX0y8CGlnbs5MEPdrJBA3TRxe4WuG_FiBxZvOGHSlJx1F9fjCQ7luN7FwgcmyJnzpwzHxSmZA6eaCvu9uLuaYZtrkPcIsbgXfAa7awMutuKVfFYt-j_a_5oH0CsCheiRp8JfoYYO6hCBBUJs_EHyLVJYFJqCVIAi5kW8GtYg2ONGV7Akc8meNJgPOSawGLK4IjYwEIUT6LYDZ_fgm4tJYhUUSSvCPbfXhK8GQQsU7BtJmgw12n04fCVEpgMxjUhJVNaghyAFgeIrQfXm4MmkgquMRYZBgQPkVzIBPROqs0hpgW85NEYWnt1IIGJkZoYdKtOHhA0HSIRZA6xCy2o0FrthdxkiNQm6gNN6MYQgod8DGA0c6HQ2g4S5bYBh6o2npgsigR_tin3R4XctYmiR0dC7kCbqqKYJmz9qgmOIb5iDK3XoNoYyWfbAbnGhm7gW6yLyJz-x1qxLliVHECbhBxJQq_L8M46otdTWpgqVvqKDCEfoWzzELhCD5xTpjIKe9fGNagyNBSrEB2yhDocR9mNpwW8XJBprMldjymiTyabN95QAUIy_mDppKBJ0CbS7Jv1CbmmCBnjgXICTQ15zTEwySOsXoiSoGyNzWNgtuujxEjXiqKKISVIXcrk0gJ-GgZuTane39l5EynnDlyrakB7xC4BDjLFEDKECtB3IxDyqoNDxKZmuH15OEKfBmi8jzFpaDnEU4BiXaSsWSAh7-ucmySWOyGfhXyO9GbomBbWvrlFiAchn5--rFYPDy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