serenity/Ports/llvm/package.sh
Dan Klishch fa1eef8bbe Toolchain: Update LLVM to 18.1.3
Apart from bumping the toolchain Clang's and port's version, this commit
completely overhauls the way LLVM toolchain is built.

First, it gets rid of a complicated two-stage process of first compiling
clang and compiler-rt builtins and then building libunwind, libc++abi,
and libc++ -- it is possible to create a complete cross-compilation
toolchain in a single CMake invocation with a modern LLVM. Moreover, the
old method was inherently unsupported and subtly broken.

Next, it utilizes full potential of the Stubs "framework". Now we are
even able to compile Clang with -Wl,-z,defs which makes one of the
patches obsolete and the whole installation less error-prone. Note that
it comes at a cost of complicating the bootstrap process on a completely
novel architecture but this hopefully won't happen often.

Lastly, it fixes handling of the -no*lib* family of flags in the
Serenity LLVM driver and correctly uses -nostartfiles in conjunction
with stubs to make necessary CMake configure-time checks succeed.
2024-04-18 13:14:33 -06:00

67 lines
2.1 KiB
Bash
Executable file

#!/usr/bin/env -S bash ../.port_include.sh
port='llvm'
useconfigure='true'
version='18.1.3'
workdir="llvm-project-${version}.src"
configopts=(
"-DCMAKE_TOOLCHAIN_FILE=${SERENITY_BUILD_DIR}/CMakeToolchain.txt"
)
files=(
"https://github.com/llvm/llvm-project/releases/download/llvmorg-${version}/llvm-project-${version}.src.tar.xz#2929f62d69dec0379e529eb632c40e15191e36f3bd58c2cb2df0413a0dc48651"
)
depends=(
"ncurses"
"zlib"
"zstd"
)
configure() {
# The cross compilers will be picked up from the CMake toolchain file.
# CC/CXX must point to the host compiler to let it build host tools (tblgen).
host_env
if [ "$SERENITY_TOOLCHAIN" = "Clang" ]; then
stdlib=""
unwindlib=""
exclude_atomic_builtin="OFF"
else
stdlib="libstdc++"
unwindlib="libgcc"
# Atomic builtins can't be cross-compiled with GCC. Use the libatomic port
# if the program you're building has references to symbols like __atomic_load.
exclude_atomic_builtin="ON"
fi
mkdir -p llvm-build
cmake ${workdir}/llvm \
-G Ninja \
-B llvm-build "${configopts[@]}" \
-DCLANG_DEFAULT_CXX_STDLIB=$stdlib \
-DCLANG_DEFAULT_UNWINDLIB=$unwindlib \
-DCMAKE_BUILD_TYPE=MinSizeRel \
-DCMAKE_FIND_ROOT_PATH="$SERENITY_BUILD_DIR"/Root \
-DCOMPILER_RT_BUILD_CRT=ON \
-DCOMPILER_RT_BUILD_ORC=OFF \
-DCOMPILER_RT_EXCLUDE_ATOMIC_BUILTIN=$exclude_atomic_builtin \
-DCOMPILER_RT_OS_DIR=serenity \
-DCROSS_TOOLCHAIN_FLAGS_NATIVE="-DCMAKE_C_COMPILER=$CC;-DCMAKE_CXX_COMPILER=$CXX" \
-DHAVE_LIBRT=OFF \
-DLLVM_DEFAULT_TARGET_TRIPLE=$SERENITY_ARCH-pc-serenity \
-DLLVM_ENABLE_PROJECTS="clang;lld;compiler-rt" \
-DLLVM_HAVE_LIBXAR=OFF \
-DLLVM_INCLUDE_BENCHMARKS=OFF \
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_INSTALL_TOOLCHAIN_ONLY=ON \
-DLLVM_OCAML_INSTALL_PATH="${SERENITY_INSTALL_ROOT}/usr/local/ocaml" \
-DLLVM_PTHREAD_LIB=pthread \
-DLLVM_TARGETS_TO_BUILD="X86;AArch64;RISCV"
}
build() {
ninja -j${MAKEJOBS} -C llvm-build
}
install() {
ninja -C llvm-build install
}