[PATCH] D99620: [CMake][Compiler-rt] Compute LLVM_MAIN_SRC_DIR assuming the monorepo layout.

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 30 23:38:07 PDT 2021


mstorsjo added a comment.

In D99620#2660251 <https://reviews.llvm.org/D99620#2660251>, @delcypher wrote:

> In D99620#2660215 <https://reviews.llvm.org/D99620#2660215>, @tstellar wrote:
>
>> @delcypher Ok, thanks.  So my question for for @phosek is what if we replaced the usage of llvm-config with find_package(LLVM) would that change also enable the clean ups you are talking about? Or does relying on any kind of out-of-tree files make the build more complicated?
>
> @tstellar
>
> @phosek likely has his own opinions on this but I wouldn't consider using `find_package(LLVM)` a clean up. `find_package(LLVM)` requires the the LLVM CMake files to actually be available and not all toolchain vendors ship them. This would make building a standalone build of compiler-rt even more painful than it already is.
>
> I think ideally we should move to a world where neither  the `llvm-config` binary nor doing `find_package(LLVM)` is required to build compiler-rt. I think it's fine for compiler-rt to depend on CMake source files in the LLVM source tree (it already does) but depending on any LLVM specific build artefacts (like llvm-config or a LLVM CMake package) that a toolchain might not ship is a pain which I don't think is technically necessary.

+1 for this. Preferring finding things from the surrounding monorepo is much nicer than relying on either `llvm-config` or `LLVMConfig.cmake` to be installed (as the toolchains I build don't ship with those).

> Compiler-rt currently depends on at least the following
>
> - The `LLVMConfig.cmake` file that's generated by the build of LLVM. It's located at `lib/cmake/llvm/LLVMConfig.cmake` in the root of an LLVM build and is optionally installed by toolchain maintainers.
> - Several CMake files that lives in the `llvm/cmake/modules` in the llvm source tree. `LLVMConfig.cmake` does `include(${LLVM_CMAKE_DIR}/LLVM-Config.cmake)` where `LLVM_CMAKE_DIR` points at the directory containing this file. For a build directory `LLVM_CMAKE_DIR` points into the llvm source tree, for an installed toolchain `LLVM_CMAKE_DIR` will point to where the files where optionally installed by toolchain maintainers.

It doesn't strictly require those, at least not for all build configurations: I do build compiler-rt (since a couple years) without an installed `llvm-config` and without `LLVMConfig.cmake` available (without any custom patches). This hits the case on lines 216-220 above, printing a build time warning about "UNSUPPORTED COMPILER-RT CONFIGURATION DETECTED: llvm-config not found. Reconfigure with -DLLVM_CONFIG_PATH=path/to/llvm-config", but it builds just fine despite that. I guess that I can't build and run tests in that configuration though, but other than that it does work. I do build with `-DCMAKE_C_COMPILER_TARGET=<triple> -DCOMPILER_RT_DEFAULT_TARGET_ONLY=TRUE` though, if that makes any difference.

Anyway, reducing the reliance on trying to locate `llvm-config` and `LLVMConfig.cmake` externally makes things much more predictable for me. As I don't install either of them from the main LLVM build, I expect hitting that "llvm config not found" case. However, if I do build this on a distro with LLVM installed system wide via the package manager, it can find a `llvm-config` from that installation (if those particular packages that contain it happen to be installed), which can be from a woefully different version. That makes it try to include odd old versions of the cmake files, with really funky (and hard to debug) results - when I just wanted it not to do that at all.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99620/new/

https://reviews.llvm.org/D99620



More information about the llvm-commits mailing list