-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add custom llvm build scripts without term info and zlib to red…
…uce kclvm release size. (#478) feat: add custom llvm build scripts without term info and zlib for kclvm.
- Loading branch information
Showing
2 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
$LLVM_VERSION = $args[0] | ||
$LLVM_REPO_URL = $args[1] | ||
|
||
if ([string]::IsNullOrEmpty($LLVM_REPO_URL)) { | ||
$LLVM_REPO_URL = "https://github.com/llvm/llvm-project.git" | ||
} | ||
|
||
if ([string]::IsNullOrEmpty($LLVM_VERSION)) { | ||
Write-Output "Usage: $PSCommandPath <llvm-version> <llvm-repository-url>" | ||
Write-Output "" | ||
Write-Output "# Arguments" | ||
Write-Output " llvm-version The name of a LLVM release branch without the 'release/' prefix" | ||
Write-Output " llvm-repository-url The URL used to clone LLVM sources (default: https://github.com/llvm/llvm-project.git)" | ||
|
||
exit 1 | ||
} | ||
|
||
# Clone the LLVM project. | ||
if (-not (Test-Path -Path "llvm-project" -PathType Container)) { | ||
git clone "$LLVM_REPO_URL" llvm-project | ||
} | ||
|
||
Set-Location llvm-project | ||
git fetch origin | ||
git checkout "release/$LLVM_VERSION" | ||
git reset --hard origin/"release/$LLVM_VERSION" | ||
|
||
# Create a directory to build the project. | ||
New-Item -Path "build" -Force -ItemType "directory" | ||
Set-Location build | ||
|
||
# Create a directory to receive the complete installation. | ||
New-Item -Path "install" -Force -ItemType "directory" | ||
|
||
# Adjust compilation based on the OS. | ||
$CMAKE_ARGUMENTS = "" | ||
|
||
# Adjust cross compilation | ||
$CROSS_COMPILE = "" | ||
|
||
# Run `cmake` to configure the project. | ||
cmake ` | ||
-G "Visual Studio 16 2019" ` | ||
-DCMAKE_BUILD_TYPE=MinSizeRel ` | ||
-DCMAKE_INSTALL_PREFIX=destdir ` | ||
-DLLVM_ENABLE_PROJECTS="clang;lld" ` | ||
-DLLVM_ENABLE_TERMINFO=OFF ` | ||
-DLLVM_ENABLE_ZLIB=OFF ` | ||
-DLLVM_INCLUDE_DOCS=OFF ` | ||
-DLLVM_INCLUDE_EXAMPLES=OFF ` | ||
-DLLVM_INCLUDE_GO_TESTS=OFF ` | ||
-DLLVM_INCLUDE_TESTS=OFF ` | ||
-DLLVM_INCLUDE_TOOLS=ON ` | ||
-DLLVM_INCLUDE_UTILS=OFF ` | ||
-DLLVM_OPTIMIZED_TABLEGEN=ON ` | ||
-DLLVM_TARGETS_TO_BUILD="X86;AArch64" ` | ||
$CROSS_COMPILE ` | ||
$CMAKE_ARGUMENTS ` | ||
../llvm | ||
|
||
# Showtime! | ||
cmake --build . --config Release | ||
|
||
# Not using DESTDIR here, quote from | ||
# https://cmake.org/cmake/help/latest/envvar/DESTDIR.html | ||
# > `DESTDIR` may not be used on Windows because installation prefix | ||
# > usually contains a drive letter like in `C:/Program Files` which cannot | ||
# > be prepended with some other prefix. | ||
cmake --install . --strip --config Release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/bin/bash | ||
|
||
# Display all commands before executing them. | ||
set -o errexit | ||
set -o errtrace | ||
|
||
LLVM_VERSION=$1 | ||
LLVM_REPO_URL=${2:-https://github.com/llvm/llvm-project.git} | ||
LLVM_CROSS="$3" | ||
|
||
if [[ -z "$LLVM_REPO_URL" || -z "$LLVM_VERSION" ]] | ||
then | ||
echo "Usage: $0 <llvm-version> <llvm-repository-url> [aarch64]" | ||
echo | ||
echo "# Arguments" | ||
echo " llvm-version The name of a LLVM release branch without the 'release/' prefix" | ||
echo " llvm-repository-url The URL used to clone LLVM sources (default: https://github.com/llvm/llvm-project.git)" | ||
echo " aarch64 To cross-compile an aarch64 version of LLVM" | ||
|
||
exit 1 | ||
fi | ||
|
||
# Clone the LLVM project. | ||
if [ ! -d llvm-project ] | ||
then | ||
git clone "$LLVM_REPO_URL" llvm-project | ||
fi | ||
|
||
|
||
cd llvm-project | ||
git fetch origin | ||
git checkout "release/$LLVM_VERSION" | ||
git reset --hard origin/"release/$LLVM_VERSION" | ||
|
||
# Create a directory to build the project. | ||
mkdir -p build | ||
cd build | ||
|
||
# Create a directory to receive the complete installation. | ||
mkdir -p install | ||
|
||
# Adjust compilation based on the OS. | ||
CMAKE_ARGUMENTS="" | ||
|
||
case "${OSTYPE}" in | ||
darwin*) ;; | ||
linux*) ;; | ||
*) ;; | ||
esac | ||
|
||
# Adjust cross compilation | ||
CROSS_COMPILE="" | ||
|
||
case "${LLVM_CROSS}" in | ||
aarch64*) CROSS_COMPILE="-DLLVM_HOST_TRIPLE=aarch64-linux-gnu" ;; | ||
*) ;; | ||
esac | ||
|
||
# Run `cmake` to configure the project. | ||
cmake \ | ||
-G "Unix Makefiles" \ | ||
-DCMAKE_BUILD_TYPE=MinSizeRel \ | ||
-DCMAKE_INSTALL_PREFIX="/" \ | ||
-DLLVM_ENABLE_PROJECTS="clang;lld" \ | ||
-DLLVM_ENABLE_TERMINFO=OFF \ | ||
-DLLVM_ENABLE_ZLIB=OFF \ | ||
-DLLVM_INCLUDE_DOCS=OFF \ | ||
-DLLVM_INCLUDE_EXAMPLES=OFF \ | ||
-DLLVM_INCLUDE_GO_TESTS=OFF \ | ||
-DLLVM_INCLUDE_TESTS=OFF \ | ||
-DLLVM_INCLUDE_TOOLS=ON \ | ||
-DLLVM_INCLUDE_UTILS=OFF \ | ||
-DLLVM_OPTIMIZED_TABLEGEN=ON \ | ||
-DLLVM_TARGETS_TO_BUILD="X86;AArch64" \ | ||
"${CROSS_COMPILE}" \ | ||
"${CMAKE_ARGUMENTS}" \ | ||
../llvm | ||
|
||
# Showtime! | ||
cmake --build . --config MinSizeRel | ||
DESTDIR=destdir cmake --install . --strip --config MinSizeRel | ||
|
||
# move usr/bin/* to bin/ or llvm-config will be broken | ||
mv destdir/usr/bin/* destdir/bin/ |