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

    <tr>
        <th>Summary</th>
        <td>
            [BOLT] Missing VCSRevision.h dependency
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            BOLT
      </td>
    </tr>

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

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

<pre>
    Initially reported to me at https://github.com/ClangBuiltLinux/tc-build/issues/227 by @Gelbpunkt, I did some further investigation but I am not sure if my fix is correct, hence just this report.

On Alpine Linux, I see a build failure due to missing `VCSRevision.h`. I can reliably trigger this with the following commands:

```
$ cmake \
-B build \
-G Ninja \
-S llvm \
-Wno-dev \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_COMPILER=/usr/bin/clang++ \
-DCMAKE_C_COMPILER=/usr/bin/clang-15 \
-DCMAKE_EXE_LINKER_FLAGS=-Wl,--emit-relocs \
-DCOMPILER_RT_BUILD_GWP_ASAN=OFF \
-DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-alpine-linux-musl \
-DLLVM_ENABLE_PROJECTS='bolt;clang;compiler-rt;lld' \
-DLLVM_ENABLE_TERMINFO=OFF \
-DLLVM_TARGETS_TO_BUILD='ARM;AArch64;X86' \
-DLLVM_USE_LINKER=/usr/bin/ld.lld
...

$ ninja -C build
...
ninja: job failed: /usr/bin/clang++ -DGTEST_HAS_RTTI=0 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/build/tools/bolt/lib/Utils -I/llvm/bolt/lib/Utils -I/build/include -I/llvm/llvm/include -I/llvm/bolt/include -I/build/tools/bolt/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG  -fno-exceptions -fno-rtti -std=c++17 -MD -MT tools/bolt/lib/Utils/CMakeFiles/LLVMBOLTUtils.dir/CommandLineOpts.cpp.o -MF tools/bolt/lib/Utils/CMakeFiles/LLVMBOLTUtils.dir/CommandLineOpts.cpp.o.d -o tools/bolt/lib/Utils/CMakeFiles/LLVMBOLTUtils.dir/CommandLineOpts.cpp.o -c /llvm/bolt/lib/Utils/CommandLineOpts.cpp
/llvm/bolt/lib/Utils/CommandLineOpts.cpp:14:10: fatal error: 'llvm/Support/VCSRevision.h' file not found
#include "llvm/Support/VCSRevision.h"
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
...
```

If I remove `compiler-rt` from `LLVM_ENABLE_PROJECTS`, the error does not happen, so I assume this might have something to do with the order in which things get built with and without any runtimes. I cannot reliably reproduce this on Arch Linux, so I am not sure exactly how the distribution fits into this problem (versions, tools, etc.), but the following patch does resolve the problems for me but I am not sure if this is the right fix or has implications for other types of builds like standalone.

```diff
diff --git a/bolt/lib/Utils/CMakeLists.txt b/bolt/lib/Utils/CMakeLists.txt
index 9ed9be6e1d85..fb1f0349756b 100644
--- a/bolt/lib/Utils/CMakeLists.txt
+++ b/bolt/lib/Utils/CMakeLists.txt
@@ -2,6 +2,9 @@ add_llvm_library(LLVMBOLTUtils
   CommandLineOpts.cpp
 Utils.cpp

+  DEPENDS
+  llvm_vcsrevision_h
+
 DISABLE_LLVM_LINK_LLVM_DYLIB

   LINK_LIBS
```

I set up an Alpine Linux container like so to reproduce this problem:

```
$ podman run \
--interactive \
--pids-limit -1 \
--rm \
--tty \
--volume $PWD:/llvm \
--workdir /llvm \
docker.io/alpine:edge
/llvm # apk upgrade
/llvm # apk add clang cmake git linux-headers lld llvm musl-dev ninja python3
/llvm # cmake ...
/llvm # ninja -C build
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0WE934jgS_zTKpZ54xgYSDjkAhiw7kOQBPek58WSrjNWRJa8kk7CH_ez7JDsd0vkzM4fJ6zZ2qapUklW_-pWZteKgEK_JcEqG6QVrXKnNtWKuZCr3__Ei0_x0vVTCCSblCQzW2jjk4DRUCMxB6VxtSTIh8YLEi4NwZZP1cl2ReDGTTB2mjZBuJVTzTOKFy2nWCMlJvBDWNmhJvIjjS8hOQAbRDcqsbtSjI_EMlsAFB6srhKIxrkQDQh3ROnFgTmgFWeNgCawCpR3YxiCIAqoTFOIZhIVcG4N5cFWiyhF-NNaBK4XtFtEjUUqiSXu9UzCRtVAIXag-AIsIDELAUDAh_Ry8wbB2Ya1QByCj6PfZdoNHYYVWvZKMoh4sIWcKDErBMnkCZ8ThgKad-0m4ElyJUGgp9ZP3keuqYoqHTTwLiYyi7l_7GA8gr9gjAhnOWhGddsG9Sm7gVqgf7EyyBSmP1ZngQWnK8XgmSWfryW_z_fTbcpXud3_cz0mSblAis_hea_b9-352t75fruYbkqQkXjTWkHiRCUXiRe5fOYmnJJ5-YPpnhrQ_fG81_z7fr5a3v803-8VqcrMlSUofJIlnlGIlHDUodW7f2HWz7De7blE3D_f7yXZyS5L0brE4112tfl_v0_li8m212-8mm5v5br_bLO9XfhOer0b70YCycDKo9CeDVo2V7xzMbyfT1Xx_v7n793y224blXWZaOpJM2y1JprmuaiHRUOOl0ifB5WeOdvPNenm7uPsk3jbO7X53166vnW-yWZNkOpmYvBwNSDL9fjX6aIpv25f9fP8WJO_5wIJ6r_cmQ_z5U-Fs0Vl77H5RC4MkmcAPnYV0Qe6fvjggNL3Zzbe7_b8m2_1mt1uSJI2Apvv9dpf6s3K73U1ud_v1ZLa5274OLO4268l78Wq5Xr5Kl37GDmqc1tIjTXgh8UKK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