HomePhabricator

[CMake][Compiler-rt] Make it possible to configure standalone compiler-rt…

Authored by delcypher on Tue, Mar 30, 1:47 PM.

Description

[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