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

Dan Liew via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 31 10:04:29 PDT 2021


delcypher added a comment.

In D99620#2660641 <https://reviews.llvm.org/D99620#2660641>, @mstorsjo wrote:

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

Yeah that does make a difference. I discovered in https://reviews.llvm.org/D99621 that we rely on the `TARGET_TRIPLE` variable from `LLVMConfig.cmake` to work. IIRC specifying `CMAKE_C_COMPILER_TARGET` and `COMPILER_RT_DEFAULT_TARGET_ONLY=TRUE` works around that problem. Without those variables, the first sign of trouble is

  CMake Error at cmake/Modules/CompilerRTUtils.cmake:361 (string):                                                   
    string sub-command REPLACE requires at least four arguments.                                                     
  Call Stack (most recent call first):                                                                               
    CMakeLists.txt:111 (construct_compiler_rt_default_triple)      

then you'll get a bunch of other configure errors later on.


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