Skip to content

Commit

Permalink
build-llvm: Remove the --symlink-projects option
Browse files Browse the repository at this point in the history
This option was mostly relevant for making it possible to share
ccache between builds in different directories, due to specific
logic in CMake's Ninja generator, which used relative paths for
sources as long as they were below the main source directory
(llvm-project/llvm). This option wasn't usable on Windows.

Since CMake 3.21.0, this option no longer worked for the intended
purpose - that version of CMake changed the Ninja generator to
always use absolute paths to sources, for consistency with other
generators and to simplify things. (See commit
c564a3e3fff52ef811291c5ba8fb07a5a1b47f97 in CMake's git history.)

It is still possible to achieve ccache sharing across build
directories anyway, by setting the ccache option CCACHE_BASEDIR,
which makes ccache rewrite absolute paths to relative ones within
that tree, and by setting the LLVM CMake option
LLVM_USE_RELATIVE_PATHS_IN_FILES=ON, which adds -ffile-prefix-map
options to the compiler, to remap source paths as they are exposed
in the generated code.

(Strictly speaking, LLVM_USE_RELATIVE_PATHS_IN_FILES is only needed
if debug info is enabled. On its own, without CCACHE_BASEDIR, that
option produces compiler output that is identical across build
directories - but the absolute paths end up in the preprocessor output
in source file/line comments, which makes ccache fail to reuse the cache.)
  • Loading branch information
mstorsjo committed Jan 10, 2023
1 parent 04c623f commit bd190c0
Showing 1 changed file with 8 additions and 40 deletions.
48 changes: 8 additions & 40 deletions build-llvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ while [ $# -gt 0 ]; do
--with-python)
WITH_PYTHON=1
;;
--symlink-projects)
SYMLINK_PROJECTS=1
;;
--disable-lldb)
unset LLDB
;;
Expand All @@ -77,7 +74,7 @@ done
BUILDDIR="$BUILDDIR$ASSERTSSUFFIX"
if [ -z "$CHECKOUT_ONLY" ]; then
if [ -z "$PREFIX" ]; then
echo $0 [--enable-asserts] [--stage2] [--thinlto] [--lto] [--disable-dylib] [--full-llvm] [--with-python] [--symlink-projects] [--disable-lldb] [--disable-clang-tools-extra] [--host=triple] dest
echo $0 [--enable-asserts] [--stage2] [--thinlto] [--lto] [--disable-dylib] [--full-llvm] [--with-python] [--disable-lldb] [--disable-clang-tools-extra] [--host=triple] dest
exit 1
fi

Expand Down Expand Up @@ -283,41 +280,12 @@ fi

cd llvm-project/llvm

if [ -n "$SYMLINK_PROJECTS" ]; then
# If requested, hook up other tools by symlinking them into tools,
# instead of using LLVM_ENABLE_PROJECTS. This way, all source code is
# under the directory tree of the toplevel cmake file (llvm-project/llvm),
# which makes cmake use relative paths to all source files. Using relative
# paths makes for identical compiler output from different source trees in
# different locations (for cases where e.g. path names are included, in
# assert messages), allowing ccache to share caches across multiple
# checkouts.
cd tools
for p in clang lld lldb; do
if [ "$p" = "lldb" ] && [ -z "$LLDB" ]; then
continue
fi
if [ ! -e $p ]; then
ln -s ../../$p .
fi
done
cd ..
if [ -n "$CLANG_TOOLS_EXTRA" ]; then
cd ../clang/tools
if [ ! -e extra ]; then
ln -s ../../clang-tools-extra extra
fi
cd ../../llvm
fi
else
EXPLICIT_PROJECTS=1
PROJECTS="clang;lld"
if [ -n "$LLDB" ]; then
PROJECTS="$PROJECTS;lldb"
fi
if [ -n "$CLANG_TOOLS_EXTRA" ]; then
PROJECTS="$PROJECTS;clang-tools-extra"
fi
PROJECTS="clang;lld"
if [ -n "$LLDB" ]; then
PROJECTS="$PROJECTS;lldb"
fi
if [ -n "$CLANG_TOOLS_EXTRA" ]; then
PROJECTS="$PROJECTS;clang-tools-extra"
fi

[ -z "$CLEAN" ] || rm -rf $BUILDDIR
Expand All @@ -329,7 +297,7 @@ cmake \
-DCMAKE_INSTALL_PREFIX="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=$ASSERTS \
${EXPLICIT_PROJECTS+-DLLVM_ENABLE_PROJECTS="$PROJECTS"} \
-DLLVM_ENABLE_PROJECTS="$PROJECTS" \
-DLLVM_TARGETS_TO_BUILD="ARM;AArch64;X86" \
-DLLVM_INSTALL_TOOLCHAIN_ONLY=$TOOLCHAIN_ONLY \
-DLLVM_LINK_LLVM_DYLIB=$LINK_DYLIB \
Expand Down

0 comments on commit bd190c0

Please sign in to comment.