[llvm] [flang-rt] fix missing llvm_gtest target (PR #67936)

via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 1 16:29:46 PDT 2023


pscoro wrote:

> Isn't this just a question of gating your unittests so they are enabled only when `LLVM_INCLUDE_TESTS` is true?
> 
> Because in that case, the main llvm CMakeLists.txt will already make gtest available.
> 
> I think there is a lot of inconsistency here in the LLVM codebase regarding this.
> 
> Most places are making it a hard requirement, which seems to be the most consistent way with how this is implemented in the main CMakeLists.txt
> 
> Other places like flang and lldb are just creating their own tests enabled cache variable, and just taking it's default value from `LLVM_INCLUDE_TESTS`, which seems not correct but will at least work most of the times.
> 
> `flang-rt` seemed to not even be looking at `LLVM_INCLUDE_TESTS` at all, which I think is why this is broken.

>From `flang-rt/CMakeLists.txt`
```
option(FLANG_RT_INCLUDE_TESTS
    "Generate build targets for the Flang-rt unit tests." ${LLVM_INCLUDE_TESTS})
```
The value of `LLVM_INCLUDE_TESTS` is passed to `FLANG_RT_INCLUDE_TESTS`. In this way, flang-rt's tests can be toggled by a build flag without affecting how any other tests are run.

It has been a while since I wrote the flang-rt patch and since **I am no longer actively developing for flang** this situation is a bit difficult. I understand the patch was rushed to be merged because of the impending shut down of phabricator. I can help with what I remember about regarding the above in order to aid in the debugging but I will have to ask that @madanial0 help with the fix:

All the flang buildbots are supposed to be building flang-rt, but for flang-rt to work, it must be able to find a llvm gtest cmake built when llvm was built. that is what this line is searching for. To build this, we can use the `-DLLVM_INSTALL_GTEST=On` flag to add this build target. 

Unfortunately, if i recall correctly, the above hot fix does not work because of dependencies for `third-party/unittest` that are in `llvm/`.  Flang-rt is a runtime library and runtime libraries are decoupled (or iirc in the case of compiler-rt, in the process of being decoupled) from the `llvm` cmake project, meaning that they are not built at the same time. iirc besides flang-rt, the only runtime to use gtest was compiler-rt  and it was able to do so because its still buildable by the llvm cmake project while every other runtime is only built by the runtimes project (sidenote for clarity: targetting `llvm/` with `-DLLVM_ENABLE_RUNTIMES=...` will call a build of `runtimes/` as an external project). Flang-rt depends on the llvm target, so if you do not already have a build of llvm ready (with gtest installed), flang-rt can be built when building the llvm target as an external runtime with `-DLLVM_ENABLE_RUNTIMES=flang-rt -DLLVM_INSTALL_GTEST=On`. I hope this clarifies things.

As for the failing clang builds, they could use some more investigation. I think it could because I added flang-rt to default runtimes in `runtimes/CMakeLists.txt` which was likely not the best idea
```
set(LLVM_DEFAULT_RUNTIMES "libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp;flang-rt")
```
however if you are building an llvm target with default runtimes i would not expect flang-rt to get built:
```
if ("flang" IN_LIST LLVM_ENABLE_PROJECTS)
  set(LLVM_DEFAULT_RUNTIMES "libcxx;libcxxabi;libunwind;flang-rt")
endif()
```
unless you are building `flang`. 

Apologies again that I can not look into this more thoroughly myself.


https://github.com/llvm/llvm-project/pull/67936


More information about the llvm-commits mailing list