mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:37:46 +00:00
Toolchain+Meta: Update LLVM version to 13.0.0
This commit updates the Clang toolchain's version to 13.0.0, which comes with better C++20 support and improved handling of new features by clang-format. Due to the newly enabled `-Bsymbolic-functions` flag, our Clang binaries will only be 2-4% slower than if we dynamically linked them, but we save hundreds of megabytes of disk space. The `BuildClang.sh` script has been reworked to build the entire toolchain in just three steps: one for the compiler, one for GNU binutils, and one for the runtime libraries. This reduces the complexity of the build script, and will allow us to modify the CI configuration to only rebuild the libraries when our libc headers change. Most of the compile flags have been moved out to a separate CMake cache file, similarly to how the Android and Fuchsia toolchains are implemented within the LLVM repo. This provides a nicer interface than the heaps of command-line arguments. We no longer build separate toolchains for each architecture, as the same Clang binary can compile code for multiple targets. The horrible mess that `SERENITY_CLANG_ARCH` was, has been removed in this commit. Clang happily accepts an `i686-pc-serenity` target triple, which matches what our GCC toolchain accepts.
This commit is contained in:
parent
28c088cd91
commit
06fc64be13
12 changed files with 534 additions and 663 deletions
|
@ -7,13 +7,10 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|||
|
||||
echo "$DIR"
|
||||
|
||||
ARCH=${ARCH:-"i686"}
|
||||
LLVM_ARCH=
|
||||
[ "$ARCH" = "i686" ] && LLVM_ARCH="i386" || LLVM_ARCH="$ARCH"
|
||||
LLVM_TARGET="$LLVM_ARCH-pc-serenity"
|
||||
PREFIX="$DIR/Local/clang/$ARCH"
|
||||
BUILD="$DIR/../Build/clang/$ARCH"
|
||||
SYSROOT="$BUILD/Root"
|
||||
PREFIX="$DIR/Local/clang/"
|
||||
BUILD="$DIR/../Build/"
|
||||
USERLAND_ARCHS="i686 x86_64"
|
||||
ARCHS="$USERLAND_ARCHS aarch64"
|
||||
|
||||
MD5SUM="md5sum"
|
||||
REALPATH="realpath"
|
||||
|
@ -65,12 +62,11 @@ if [ "$dev" = "1" ] && [ "$ci" = "1" ]; then
|
|||
fi
|
||||
|
||||
echo PREFIX is "$PREFIX"
|
||||
echo SYSROOT is "$SYSROOT"
|
||||
|
||||
mkdir -p "$DIR/Tarballs"
|
||||
|
||||
LLVM_VERSION="12.0.1"
|
||||
LLVM_MD5SUM="c28061313a4f1b7d74cd491a19f569b4"
|
||||
LLVM_VERSION="13.0.0"
|
||||
LLVM_MD5SUM="bfc5191cbe87954952d25c6884596ccb"
|
||||
LLVM_NAME="llvm-project-$LLVM_VERSION.src"
|
||||
LLVM_PKG="$LLVM_NAME.tar.xz"
|
||||
LLVM_URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-$LLVM_VERSION/$LLVM_PKG"
|
||||
|
@ -92,7 +88,7 @@ buildstep_ninja() {
|
|||
# When ninja writes to a pipe, it strips ANSI escape codes and prints one line per buildstep.
|
||||
# Instead, use NINJA_STATUS so that we get colored output from LLVM's build and fewer lines of output when running in a tty.
|
||||
# ANSI escape codes in NINJA_STATUS are slightly janky (ninja thinks that "\e[34m" needs 5 output characters instead of 5, so
|
||||
# it's middle elision is slightly off; also it would happily elide the "\e39m" which messes up the output if the terminal is too
|
||||
# its middle elision is slightly off; also it would happily elide the "\e39m" which messes up the output if the terminal is too
|
||||
# narrow), but it's still working better than the alternative.
|
||||
NAME=$1
|
||||
shift
|
||||
|
@ -100,6 +96,7 @@ buildstep_ninja() {
|
|||
}
|
||||
|
||||
# === DEPENDENCIES ===
|
||||
|
||||
buildstep dependencies echo "Checking whether 'make' is available..."
|
||||
if ! command -v ${MAKE:-make} >/dev/null; then
|
||||
buildstep dependencies echo "Please make sure to install GNU Make (for the '${MAKE:-make}' tool)."
|
||||
|
@ -192,7 +189,7 @@ pushd "$DIR/Tarballs"
|
|||
# Drop the previously patched extracted dir
|
||||
rm -rf "${LLVM_NAME}"
|
||||
# Also drop the build dir
|
||||
rm -rf "$DIR/Build/clang/$ARCH"
|
||||
rm -rf "$DIR/Build/clang"
|
||||
fi
|
||||
echo "Extracting LLVM..."
|
||||
tar -xJf "$LLVM_PKG"
|
||||
|
@ -224,7 +221,7 @@ pushd "$DIR/Tarballs"
|
|||
|
||||
if [ -d "$BINUTILS_NAME" ]; then
|
||||
rm -rf "$BINUTILS_NAME"
|
||||
rm -rf "$DIR/Build/clang/$ARCH/binutils"
|
||||
rm -rf "$DIR/Build/clang/binutils"
|
||||
fi
|
||||
echo "Extracting GNU binutils"
|
||||
|
||||
|
@ -243,182 +240,95 @@ pushd "$DIR/Tarballs"
|
|||
popd
|
||||
popd
|
||||
|
||||
# === COPY SERENITYOS HEADERS ===
|
||||
# === COPY HEADERS ===
|
||||
|
||||
mkdir -p "$BUILD"
|
||||
pushd "$BUILD"
|
||||
mkdir -p Root/usr/include/
|
||||
SRC_ROOT=$($REALPATH "$DIR"/..)
|
||||
FILES=$(find "$SRC_ROOT"/Kernel/API "$SRC_ROOT"/Userland/Libraries/LibC "$SRC_ROOT"/Userland/Libraries/LibM "$SRC_ROOT"/Userland/Libraries/LibPthread "$SRC_ROOT"/Userland/Libraries/LibDl -name '*.h' -print)
|
||||
for header in $FILES; do
|
||||
target=$(echo "$header" | sed -e "s@$SRC_ROOT/Userland/Libraries/LibC@@" -e "s@$SRC_ROOT/Userland/Libraries/LibM@@" -e "s@$SRC_ROOT/Userland/Libraries/LibPthread@@" -e "s@$SRC_ROOT/Userland/Libraries/LibDl@@" -e "s@$SRC_ROOT/Kernel/@Kernel/@")
|
||||
buildstep "system_headers" install -D "$header" "Root/usr/include/$target"
|
||||
done
|
||||
unset SRC_ROOT
|
||||
popd
|
||||
SRC_ROOT=$($REALPATH "$DIR"/..)
|
||||
FILES=$(find "$SRC_ROOT"/Kernel/API "$SRC_ROOT"/Userland/Libraries/LibC "$SRC_ROOT"/Userland/Libraries/LibM "$SRC_ROOT"/Userland/Libraries/LibPthread "$SRC_ROOT"/Userland/Libraries/LibDl -name '*.h' -print)
|
||||
|
||||
for arch in $ARCHS; do
|
||||
mkdir -p "$BUILD/${arch}clang"
|
||||
pushd "$BUILD/${arch}clang"
|
||||
mkdir -p Root/usr/include/
|
||||
for header in $FILES; do
|
||||
target=$(echo "$header" | sed -e "s@$SRC_ROOT/Userland/Libraries/LibC@@" -e "s@$SRC_ROOT/Userland/Libraries/LibM@@" -e "s@$SRC_ROOT/Userland/Libraries/LibPthread@@" -e "s@$SRC_ROOT/Userland/Libraries/LibDl@@" -e "s@$SRC_ROOT/Kernel/@Kernel/@")
|
||||
buildstep "system_headers" install -D "$header" "Root/usr/include/$target"
|
||||
done
|
||||
popd
|
||||
done
|
||||
unset SRC_ROOT
|
||||
|
||||
# === COPY LIBRARY STUBS ===
|
||||
|
||||
for arch in $USERLAND_ARCHS; do
|
||||
pushd "$BUILD/${arch}clang"
|
||||
mkdir -p Root/usr/lib/
|
||||
for lib in "$DIR/Stubs/${arch}clang/"*".so"; do
|
||||
lib_name=$(basename "$lib")
|
||||
[ ! -f "Root/usr/lib/${lib_name}.so" ] && cp "$lib" "Root/usr/lib/${lib_name}"
|
||||
done
|
||||
popd
|
||||
done
|
||||
|
||||
# === COMPILE AND INSTALL ===
|
||||
|
||||
rm -rf "$PREFIX"
|
||||
mkdir -p "$PREFIX"
|
||||
|
||||
mkdir -p "$DIR/Build/clang/$ARCH"
|
||||
|
||||
pushd "$DIR/Build/clang/$ARCH"
|
||||
mkdir -p "$DIR/Build/clang"
|
||||
|
||||
pushd "$DIR/Build/clang"
|
||||
mkdir -p llvm
|
||||
pushd llvm
|
||||
buildstep "llvm+clang/configure" cmake "$DIR/Tarballs/llvm-project-$LLVM_VERSION.src/llvm" \
|
||||
buildstep "llvm/configure" cmake "$DIR/Tarballs/$LLVM_NAME/llvm" \
|
||||
-G Ninja \
|
||||
-DCMAKE_BUILD_TYPE="MinSizeRel" \
|
||||
-DSERENITY_i686-pc-serenity_SYSROOT="$BUILD/i686clang/Root" \
|
||||
-DSERENITY_x86_64-pc-serenity_SYSROOT="$BUILD/x86_64clang/Root" \
|
||||
-DSERENITY_aarch64-pc-serenity_SYSROOT="$BUILD/aarch64clang/Root" \
|
||||
-DCMAKE_INSTALL_PREFIX="$PREFIX" \
|
||||
-DLLVM_DEFAULT_TARGET_TRIPLE="$LLVM_TARGET" \
|
||||
'-DLLVM_TARGETS_TO_BUILD=X86;AArch64' \
|
||||
-DLLVM_ENABLE_BINDINGS=OFF \
|
||||
-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF \
|
||||
-DLLVM_ENABLE_PROJECTS="clang;lld" \
|
||||
-DLLVM_INCLUDE_BENCHMARKS=OFF \
|
||||
-DLLVM_INCLUDE_TESTS=OFF \
|
||||
-DLLVM_LINK_LLVM_DYLIB=ON \
|
||||
-DLLVM_INSTALL_UTILS=OFF \
|
||||
-C "$DIR/CMake/LLVMConfig.cmake" \
|
||||
${dev:+"-DLLVM_CCACHE_BUILD=ON"} \
|
||||
${ci:+"-DLLVM_CCACHE_BUILD=ON"} \
|
||||
${ci:+"-DLLVM_CCACHE_DIR=$LLVM_CCACHE_DIR"} \
|
||||
${ci:+"-DLLVM_CCACHE_MAXSIZE=$LLVM_CCACHE_MAXSIZE"} \
|
||||
|| exit 1
|
||||
${ci:+"-DLLVM_CCACHE_MAXSIZE=$LLVM_CCACHE_MAXSIZE"}
|
||||
|
||||
buildstep_ninja "llvm+clang/build" ninja -j "$MAKEJOBS" || exit 1
|
||||
buildstep "llvm+clang/install" ninja install || exit 1
|
||||
popd
|
||||
|
||||
LLVM_COMPILER_FLAGS="-target $LLVM_TARGET --sysroot $SYSROOT -ftls-model=initial-exec -ffreestanding -nostdlib -nostdlib++"
|
||||
|
||||
mkdir -p "compiler-rt"
|
||||
pushd compiler-rt
|
||||
buildstep "compiler-rt/configure" cmake "$DIR/Tarballs/llvm-project-$LLVM_VERSION.src/compiler-rt" \
|
||||
-GNinja \
|
||||
-DCMAKE_SYSROOT="$SYSROOT" \
|
||||
-DCMAKE_INSTALL_PREFIX="$PREFIX/lib/clang/${LLVM_VERSION}" \
|
||||
-DCMAKE_BUILD_TYPE="Release" \
|
||||
-DCMAKE_AR="$PREFIX/bin/llvm-ar" \
|
||||
-DCMAKE_C_COMPILER="$PREFIX/bin/clang" \
|
||||
-DCMAKE_C_COMPILER_TARGET="$LLVM_TARGET" \
|
||||
-DCMAKE_C_FLAGS="$LLVM_COMPILER_FLAGS" \
|
||||
-DCMAKE_CXX_COMPILER="$PREFIX/bin/clang++" \
|
||||
-DCMAKE_CXX_FLAGS="$LLVM_COMPILER_FLAGS" \
|
||||
-DCMAKE_CXX_COMPILER_TARGET="$LLVM_TARGET" \
|
||||
-DCMAKE_ASM_COMPILER="$PREFIX/bin/clang" \
|
||||
-DCMAKE_ASM_COMPILER_TARGET="$LLVM_TARGET" \
|
||||
-DCMAKE_ASM_FLAGS="$LLVM_COMPILER_FLAGS" \
|
||||
-DLLVM_CONFIG_PATH="$PREFIX/bin/llvm-config" \
|
||||
-DCOMPILER_RT_EXCLUDE_ATOMIC_BUILTIN=OFF \
|
||||
-DCOMPILER_RT_OS_DIR="serenity" \
|
||||
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \
|
||||
-DCOMPILER_RT_BUILD_BUILTINS=ON \
|
||||
-DCOMPILER_RT_BUILD_CRT=ON \
|
||||
-DCOMPILER_RT_BUILD_LIBFUZZER=OFF \
|
||||
-DCOMPILER_RT_BUILD_MEMPROF=OFF \
|
||||
-DCOMPILER_RT_BUILD_PROFILE=OFF \
|
||||
-DCOMPILER_RT_BUILD_SANITIZERS=OFF \
|
||||
-DCOMPILER_RT_BUILD_XRAY=OFF || exit 1
|
||||
|
||||
buildstep_ninja "compiler-rt/build" ninja -j "$MAKEJOBS" || exit 1
|
||||
buildstep "compiler-rt/install" ninja install || exit 1
|
||||
popd
|
||||
|
||||
mkdir -p libunwind
|
||||
pushd libunwind
|
||||
buildstep "libunwind/configure" cmake "$DIR/Tarballs/llvm-project-$LLVM_VERSION.src/libunwind" \
|
||||
-GNinja \
|
||||
-DCMAKE_BUILD_TYPE="Release" \
|
||||
-DCMAKE_SYSROOT="$SYSROOT" \
|
||||
-DCMAKE_C_COMPILER="$PREFIX/bin/clang" \
|
||||
-DCMAKE_C_COMPILER_TARGET="$LLVM_TARGET" \
|
||||
-DCMAKE_C_FLAGS="$LLVM_COMPILER_FLAGS" \
|
||||
-DCMAKE_CXX_COMPILER="$PREFIX/bin/clang++" \
|
||||
-DCMAKE_CXX_COMPILER_TARGET="$LLVM_TARGET" \
|
||||
-DCMAKE_CXX_FLAGS="$LLVM_COMPILER_FLAGS" \
|
||||
-DCMAKE_INSTALL_PREFIX="$PREFIX" \
|
||||
-DLLVM_CONFIG_PATH="$PREFIX/bin/llvm-config" \
|
||||
-DLIBUNWIND_TARGET_TRIPLE="$LLVM_TARGET" \
|
||||
-DLIBUNWIND_SYSROOT="$SYSROOT" || exit 1
|
||||
|
||||
buildstep_ninja "libunwind/build" ninja -j "$MAKEJOBS" || exit 1
|
||||
buildstep "libunwind/install" ninja install || exit 1
|
||||
popd
|
||||
|
||||
mkdir -p libcxxabi
|
||||
pushd libcxxabi
|
||||
buildstep "libcxxabi/configure" cmake "$DIR/Tarballs/llvm-project-$LLVM_VERSION.src/libcxxabi" \
|
||||
-GNinja \
|
||||
-DCMAKE_BUILD_TYPE="Release" \
|
||||
-DCMAKE_SYSROOT="$SYSROOT" \
|
||||
-DCMAKE_C_COMPILER="$PREFIX/bin/clang" \
|
||||
-DCMAKE_C_COMPILER_TARGET="$LLVM_TARGET" \
|
||||
-DCMAKE_C_FLAGS="$LLVM_COMPILER_FLAGS" \
|
||||
-DCMAKE_CXX_COMPILER="$PREFIX/bin/clang++" \
|
||||
-DCMAKE_CXX_COMPILER_TARGET="$LLVM_TARGET" \
|
||||
-DCMAKE_CXX_FLAGS="$LLVM_COMPILER_FLAGS" \
|
||||
-DCMAKE_INSTALL_PREFIX="$PREFIX" \
|
||||
-DLLVM_CONFIG_PATH="$PREFIX/bin/llvm-config" \
|
||||
-DLIBCXXABI_STANDALONE_BUILD=ON \
|
||||
-DLIBCXXABI_ENABLE_EXCEPTIONS=ON \
|
||||
-DLIBCXXABI_STANDALONE_BUILD=ON \
|
||||
-DLIBCXXABI_ENABLE_ASSERTIONS=OFF \
|
||||
-DLIBCXXABI_BAREMETAL=ON || exit 1
|
||||
|
||||
buildstep_ninja "libcxxabi/build" ninja -j "$MAKEJOBS" || exit 1
|
||||
buildstep "libcxxabi/install" ninja install || exit 1
|
||||
popd
|
||||
|
||||
mkdir -p libcxx
|
||||
pushd libcxx
|
||||
buildstep "libcxx/configure" cmake "$DIR/Tarballs/llvm-project-$LLVM_VERSION.src/libcxx" \
|
||||
-G Ninja \
|
||||
-DCMAKE_BUILD_TYPE="Release" \
|
||||
-DCMAKE_BINARY_DIR="$PREFIX/usr" \
|
||||
-DCMAKE_SYSROOT="$SYSROOT" \
|
||||
-DCMAKE_C_COMPILER="$PREFIX/bin/clang" \
|
||||
-DCMAKE_C_FLAGS="$LLVM_COMPILER_FLAGS" \
|
||||
-DCMAKE_CXX_COMPILER="$PREFIX/bin/clang++" \
|
||||
-DCMAKE_CXX_FLAGS="$LLVM_COMPILER_FLAGS" \
|
||||
-DCMAKE_INSTALL_PREFIX="$PREFIX" \
|
||||
-DLLVM_CONFIG_PATH="$PREFIX/bin/llvm-config" \
|
||||
-DLLVM_BINARY_DIR="$PREFIX/usr" \
|
||||
-DLIBCXX_INSTALL_LIBRARY=ON \
|
||||
-DLIBCXX_ENABLE_LOCALIZATION=OFF \
|
||||
-DLIBCXX_ENABLE_FILESYSTEM=OFF \
|
||||
-DLIBCXX_INSTALL_HEADERS=ON \
|
||||
-DLIBCXX_ENABLE_SHARED=ON \
|
||||
-DLIBCXX_ENABLE_LOCALIZATION=OFF \
|
||||
-DLIBCXX_ENABLE_STATIC=ON \
|
||||
-DLIBCXX_CXX_ABI="libcxxabi" \
|
||||
-DLIBCXX_INCLUDE_BENCHMARKS=OFF || exit 1
|
||||
|
||||
buildstep "libcxx/build" ninja -j "$MAKEJOBS" || exit 1
|
||||
buildstep "libcxx/install" ninja install || exit 1
|
||||
buildstep "libcxx/install-headers" ninja install-cxx-headers || exit 1
|
||||
buildstep_ninja "llvm/build" ninja -j "$MAKEJOBS"
|
||||
buildstep "llvm/install" ninja install/strip
|
||||
popd
|
||||
|
||||
mkdir -p binutils
|
||||
pushd binutils
|
||||
buildstep "binutils/configure" "$DIR/Tarballs/$BINUTILS_NAME/configure" --prefix="$PREFIX/binutils" \
|
||||
--target="$ARCH-pc-serenity" \
|
||||
buildstep "binutils/configure" "$DIR/Tarballs/$BINUTILS_NAME/configure" --prefix="$PREFIX" \
|
||||
--enable-targets="$(echo "$ARCHS" | sed -E "s@(\S)(\s|$)@\1-pc-serenity,@g")" \
|
||||
--program-prefix="gnu-" \
|
||||
--disable-nls \
|
||||
--disable-gas \
|
||||
--disable-gold \
|
||||
--disable-ld \
|
||||
--disable-gprof \
|
||||
--enable-shared || exit 1
|
||||
buildstep "binutils/build" "$MAKE" -j "$MAKEJOBS" || exit 1
|
||||
buildstep "binutils/install" "$MAKE" install || exit 1
|
||||
--enable-shared
|
||||
buildstep "binutils/build" "$MAKE" -j "$MAKEJOBS"
|
||||
buildstep "binutils/install" "$MAKE" install
|
||||
popd
|
||||
|
||||
for arch in $ARCHS; do
|
||||
mkdir -p runtimes/"$arch"
|
||||
pushd runtimes/"$arch"
|
||||
buildstep "runtimes/$arch/configure" cmake "$DIR/Tarballs/$LLVM_NAME/runtimes" \
|
||||
-G Ninja \
|
||||
-DSERENITY_TOOLCHAIN_ARCH="$arch" \
|
||||
-DSERENITY_TOOLCHAIN_ROOT="$PREFIX" \
|
||||
-DSERENITY_BUILD_DIR="$BUILD/${arch}clang/" \
|
||||
-DCMAKE_INSTALL_PREFIX="$PREFIX" \
|
||||
-C "$DIR/CMake/LLVMRuntimesConfig.cmake"
|
||||
|
||||
buildstep "runtimes/$arch/build" ninja -j "$MAKEJOBS"
|
||||
buildstep "runtimes/$arch/install" ninja install
|
||||
popd
|
||||
done
|
||||
popd
|
||||
|
||||
# === REMOVE UNNECESSARY BUILD ARTIFACTS ===
|
||||
rm -r "$PREFIX"/lib/libclang*.a "$PREFIX"/lib/libLLVM*.a "$PREFIX"/lib/liblld*.a
|
||||
|
||||
# === SAVE TO CACHE ===
|
||||
|
||||
pushd "$DIR"
|
||||
if [ "$TRY_USE_LOCAL_TOOLCHAIN" = "y" ]; then
|
||||
echo "::endgroup::"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue