Skip to content

Instantly share code, notes, and snippets.

@Leandros
Last active November 29, 2021 07:45
Show Gist options
  • Save Leandros/9148fcb7420f5788abe011a4c212729b to your computer and use it in GitHub Desktop.
Save Leandros/9148fcb7420f5788abe011a4c212729b to your computer and use it in GitHub Desktop.
Compile LLVM
@echo off
del /s /q build/*
rmdir /s /q build
mkdir build
cd build
cmake .. -G"Visual Studio 16 2019" -A x64 -Thost=x64^
-DCMAKE_BUILD_TYPE:STRING="Release"^
-DCMAKE_INSTALL_PREFIX:STRING="output"^
-DLLVM_TARGET_ARCH:STRING="host"^
-DLLVM_TARGETS_TO_BUILD:STRING="X86"^
-DLLVM_INCLUDE_EXAMPLES:BOOL=OFF^
-DLLVM_INCLUDE_TESTS:BOOL=OFF^
-DLLVM_ENABLE_ASSERTIONS:BOOL=ON
cmake --build . --target install
#!/bin/bash
VERSION="5.0.1"
# export CC="x86_64-linux-musl-gcc -static --static"
# export CXX="x86_64-linux-musl-g++ -static --static"
# Download
wget -nc "https://releases.llvm.org/$VERSION/llvm-$VERSION.src.tar.xz"
wget -nc "https://releases.llvm.org/$VERSION/cfe-$VERSION.src.tar.xz"
wget -nc "https://releases.llvm.org/$VERSION/clang-tools-extra-$VERSION.src.tar.xz"
wget -nc "https://releases.llvm.org/$VERSION/compiler-rt-$VERSION.src.tar.xz"
wget -nc "https://releases.llvm.org/$VERSION/libcxx-$VERSION.src.tar.xz"
wget -nc "https://releases.llvm.org/$VERSION/libcxxabi-$VERSION.src.tar.xz"
wget -nc "https://releases.llvm.org/$VERSION/libunwind-$VERSION.src.tar.xz"
wget -nc "https://releases.llvm.org/$VERSION/lld-$VERSION.src.tar.xz"
wget -nc "https://releases.llvm.org/$VERSION/openmp-$VERSION.src.tar.xz"
# Extract
function untar {
if [ ! -d "$2" ]; then
rm -rf $2
mkdir $2
tar xf $1 -C $2 --strip-components=1
fi
}
untar llvm-$VERSION.src.tar.xz llvm
untar cfe-$VERSION.src.tar.xz clang
untar clang-tools-extra-$VERSION.src.tar.xz extra
untar compiler-rt-$VERSION.src.tar.xz compiler-rt
untar libcxx-$VERSION.src.tar.xz libcxx
untar libcxxabi-$VERSION.src.tar.xz libcxxabi
untar libunwind-$VERSION.src.tar.xz libunwind
untar lld-$VERSION.src.tar.xz lld
untar openmp-$VERSION.src.tar.xz openmp
# rm -rf build
mkdir -p build
pushd build
cmake ../llvm -G"Ninja" \
-DCMAKE_BUILD_TYPE:STRING="Release" \
-DCMAKE_INSTALL_PREFIX:PATH="output" \
-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING="" \
\
-DLLVM_TARGET_ARCH:STRING="host" \
-DLLVM_TARGETS_TO_BUILD:STRING="X86;ARM;AArch64" \
-DLLVM_ENABLE_PROJECTS:STRING="clang;libcxx;libcxxabi;compiler-rt;lld;openmp;libunwind" \
\
-DLLVM_TOOL_COMPILER_RT_BUILD:BOOL="1" \
-DLLVM_TOOL_LIBUNWIND_BUILD:BOOL="1" \
-DLLVM_TOOL_OPENMP_BUILD:BOOL="1" \
-DLLVM_TOOL_CLANG_BUILD:BOOL="1" \
-DLLVM_TOOL_LIBCXX_BUILD:BOOL="1" \
-DLLVM_TOOL_LIBCXXABI_BUILD:BOOL="1" \
-DLLVM_TOOL_LLD_BUILD:BOOL="1" \
\
-DLLVM_INCLUDE_EXAMPLES:BOOL="0" \
-DLLVM_INCLUDE_TESTS:BOOL="0"
echo ""
echo ""
echo "succesfully configured llvm"
echo "you can now build the project by calling 'ninja' inside 'build/'"
ninja
ninja install
#!/bin/bash
if [ ! -d "$1" ]; then
echo "usage: strip.sh LLVM_DIRECTORY"
fi
rm $1/bin/bugpoint
rm $1/bin/c-index-test
rm $1/bin/clang-change-namespace
rm $1/bin/clang-check
rm $1/bin/clang-import-test
rm $1/bin/clang-include-fixer
rm $1/bin/clang-query
rm $1/bin/clang-rename
rm $1/bin/clang-reorder-fields
rm $1/bin/clangd
rm $1/bin/find-all-symbols
rm $1/bin/llvm-c-test
rm $1/bin/llvm-lto2
rm $1/bin/llvm-dsymutil
rm $1/bin/llvm-dwp
rm $1/bin/llvm-objdump
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment