I’ve proposed an opinionated change that affects how we build projects in standalone mode (e.g. for linux distributions). Let me put some of the information here so we have a place to discuss the overall idea and motivation okay?
Rationale
The rationale behind this change is to unify the CMake parts of standalone
builds that historically had to be kept in each and every project. With
the advent of the top-level cmake
directory inside the LLVM source
tree, it is now possible to bundle the CMake instructions into a file,
aka cmake/Modules/StandaloneBuildHelpers.cmake
, and include that file
in each project that wants to build in standalone-mode.
Historically the standalone build mode is used mostly by Linux
distributions. Certainly not every LLVM contributor cares about Linux
distributions. To reduce the frictions it makes even more sense to have
a unified place where to keep the specialities of building in standalone
mode.
Affected projects (so far)
This change brings the unified standalone build mode to the clang and
lld project.
Assumptions
One radical assumption for this change is that in order to build clang
or ldd in standalone mode, you have to first build the llvm
subproject
and install it into any location. You can assist the build process to
find LLVM using find_package(LLVM)
by specifying
-DCMAKE_PREFIX_PATH=${LLVM_INSTALL_DIR}/lib/cmake/llvm
-DLLVM_CMAKE_DIR=${LLVM_INSTALL_DIR}/lib/cmake/llvm
in the cmake
configuration process.
You have to build the llvm subproject with utilities included and (optionally) installed (
-DLLVM_INCLUDE_UTILS:BOOL=ONand
-DLLVM_INSTALL_UTILS:BOOL=ON`. But
I’m sure that this is done most of the time anyways, no?
Don’t build as you go: No more cross-project dependencies on LLVM utilties
Another assumption is that in standalone build mode it makes no sense to
build clang and try to build an LLVM utility binary like FileCheck
if
that is missing. This only adds noise to the cmake files and creates an
indirect dependency on the LLVM utilities directory which doesn’t exist
in the the clang source tarball.
Don’t silently turn off tests
Before this change, we would silently turn off tests if a binary like
FileCheck
, count
or not
was missing. This is not only dangerous
but IMHO not helpful. If someone asks for tests by passing
-DLLVM_INCLUDE_TESTS=On
we should error out at configure time because
we cannot fulfil this request when a binary is missing. This is exactly
what this tests does. If you want to check if an LLVM utility binary
exists and what the path to it is, you can call
require_llvm_utility_binary_path("FileCheck")
and it will
make sure the import location for the target exists, aka the path to the binary that
was found when we did find_package(LLVM)
.
NOTE: You can take a look at this small example project which shows you
how importing of an installed project works:
Require external LIT in standalone mode
We also think that in standalone mode you always want to use an external
lit and not build it as you go. That’s why the find_external_lit
macro
checks if LLVM_EXTERNAL_LIT
is set and the path exists. If one of
these conditions doesn’t hold true, we error out.
Some TODOs:
( ) make sure the correct binaries of FileCheck
and count
and not
get substituted in lit test files.
( ) get feedback on this change or just opinions
( ) extend usage to other projects like mlir
, libomp
and so on.
( ) more encapsulation in cmake/Modules/StandaloneBuildHelpers.cmake
I’d love to hear your feedback on this.