[all-commits] [llvm/llvm-project] fa818b: [CMake][Compiler-rt] Compute `LLVM_MAIN_SRC_DIR` a...

Dan Liew via All-commits all-commits at lists.llvm.org
Tue Apr 6 08:33:27 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: fa818bb0357d140987155f75296b1205303be31d
      https://github.com/llvm/llvm-project/commit/fa818bb0357d140987155f75296b1205303be31d
  Author: Dan Liew <dliew at apple.com>
  Date:   2021-04-06 (Tue, 06 Apr 2021)

  Changed paths:
    M compiler-rt/cmake/Modules/CompilerRTUtils.cmake

  Log Message:
  -----------
  [CMake][Compiler-rt] Compute `LLVM_MAIN_SRC_DIR` assuming the monorepo
layout.

When doing a standalone compiler-rt build we currently rely on
getting information from the `llvm-config` binary. Previously
we would rely on calling `llvm-config --src-root` to find the
LLVM sources. Unfortunately the returned path could easily be wrong
if the sources were built on another machine.

Now that compiler-rt is part of a monorepo we can easily fix this
problem by finding the LLVM source tree next to `compiler-rt` in
the monorepo. We do this regardless of whether or not the `llvm-config`
binary is available which moves us one step closer to not requiring
`llvm-config` to be available.

To try avoid anyone breaking anyone who relies on the current behavior,
if the path assuming the monorepo layout doesn't exist we invoke
`llvm-config --src-root` to get the path. A deprecation warning is
emitted if this path is taken because we should remove this path
in the future given that other runtimes already assume the monorepo
layout.

We also now emit a warning if `LLVM_MAIN_SRC_DIR` does not exist.
The intention is that this should be a hard error in future but
to avoid breaking existing users we'll keep this as a warning
for now.

rdar://76016632

Differential Revision: https://reviews.llvm.org/D99620


  Commit: fd28517d878e1d3d14f492ab659aabdf729fd331
      https://github.com/llvm/llvm-project/commit/fd28517d878e1d3d14f492ab659aabdf729fd331
  Author: Dan Liew <dliew at apple.com>
  Date:   2021-04-06 (Tue, 06 Apr 2021)

  Changed paths:
    A compiler-rt/cmake/Modules/CompilerRTMockLLVMCMakeConfig.cmake
    M compiler-rt/cmake/Modules/CompilerRTUtils.cmake

  Log Message:
  -----------
  [CMake][Compiler-rt] Make it possible to configure standalone compiler-rt without `LLVMConfig.cmake`.

Previously it wasn't possible to configure a standalone compiler-rt
build if the `LLVMConfig.cmake` file isn't present in a shipped
toolchain.

This patch adds a fallback behaviour for when `LLVMConfig.cmake` is not
available in the toolchain being used for configure. The fallback
behaviour mocks out the bare minimum required to make a configure
succeed when the host is Darwin. Support for other platforms could
be added in future patches.

The new code path is taken either in one of the following cases:

* `llvm-config` is not available.
* `llvm-config` is available but it provides an invalid path for the CMake files.

The motivation here is to be able to generate the compiler-rt lit test
suites for an arbitrary LLVM toolchain and then run the tests against
it.

The invocation to do this looks something like.

```
CC=/path/to/cc \
CXX=/path/to/c++ \
cmake \
  -G Ninja \
  -DLLVM_CONFIG_PATH=/path/to/llvm-config \
  -DCOMPILER_RT_INCLUDE_TESTS=ON \
  /path/to/llvm-project/compiler-rt

 # Note we don't compile compiler-rt in this workflow.
bin/llvm-lit -v test/path/to/generated/test_suite
```

A possible alternative approach is to configure the
`cmake/modules/LLVMConfig.cmake.in` file in the LLVM source tree
and then include it. This approach was not taken because it is more
complicated.

An interesting side benefit of this patch is that it is now
possible to configure on Darwin without `llvm-config` being available
by configuring with `-DLLVM_CONFIG_PATH=""`. This moves us a step
closer to a world where no LLVM build artefacts are required to
build compiler-rt.

rdar://76016632

Differential Revision: https://reviews.llvm.org/D99621


Compare: https://github.com/llvm/llvm-project/compare/b36ef9f47db7...fd28517d878e


More information about the All-commits mailing list