Skip to content

Instantly share code, notes, and snippets.

@CodingKoopa
Created October 30, 2022 20:37
Show Gist options
  • Save CodingKoopa/1f2db79e27793832a2e93a2fc79e0aae to your computer and use it in GitHub Desktop.
Save CodingKoopa/1f2db79e27793832a2e93a2fc79e0aae to your computer and use it in GitHub Desktop.
Setup LLVM
#!/bin/sh -eu
# See https://clang.llvm.org/get_started.html.
LLVM_VERSION=15.0.0
readonly LLVM_VERSION
source_dir=llvm-project-$LLVM_VERSION.src
source_archive=llvm-project-$LLVM_VERSION.src.tar.xz
source_url=https://github.com/llvm/llvm-project/releases/download/llvmorg-$LLVM_VERSION/$source_archive
tidy() {
find . -maxdepth 1 \
\( \
\( \
-type f \
! -name "$source_archive" \
! -name "$source_archive".sig \
\( -name 'llvm-project-*.src.tar.xz' -o \
-name 'llvm-project-*.src.tar.xz.sig' \) \
\) -o \
\( \
-type d \
! -name "$source_dir" \
-name 'clang-*.src' \
\) \
\) \
-delete
}
download() {
# Run in a subshell so that we can wait on just our own processes.
(
wget --no-clobber "$source_url" "$source_url".sig &
gpg --fetch-keys https://releases.llvm.org/release-keys.asc &
wait
)
}
verify() {
gpg --verify "$source_archive".sig "$source_archive"
}
extract() {
tar xvf "$source_archive"
}
build() {
cd "$source_dir"
cmake -S llvm -B build -G Ninja -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -DCMAKE_INSTALL_PREFIX="$HOME"/.local -DCMAKE_BUILD_TYPE=Release
cmake --build build
cd -
}
install() {
cd "$source_dir"
cmake --build build --target install
cd -
}
# TODO check free space
if [ $# -ge 1 ]; then
if [ -n "$1" ]; then
$1
exit 0
fi
fi
tidy &
download
verify
extract
build
# Uncomment this and comment the `ln` if you have room for `make install`.
#install
ln -sf "$source_dir" llvm-project
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment