Skip to content

Commit 6a0c173

Browse files
authored
feat: add custom llvm build scripts without term info and zlib to reduce kclvm release size. (#478)
feat: add custom llvm build scripts without term info and zlib for kclvm.
1 parent bd265c8 commit 6a0c173

File tree

2 files changed

+153
-0
lines changed

2 files changed

+153
-0
lines changed

scripts/build-llvm/build.ps1

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
$LLVM_VERSION = $args[0]
2+
$LLVM_REPO_URL = $args[1]
3+
4+
if ([string]::IsNullOrEmpty($LLVM_REPO_URL)) {
5+
$LLVM_REPO_URL = "https://github.com/llvm/llvm-project.git"
6+
}
7+
8+
if ([string]::IsNullOrEmpty($LLVM_VERSION)) {
9+
Write-Output "Usage: $PSCommandPath <llvm-version> <llvm-repository-url>"
10+
Write-Output ""
11+
Write-Output "# Arguments"
12+
Write-Output " llvm-version The name of a LLVM release branch without the 'release/' prefix"
13+
Write-Output " llvm-repository-url The URL used to clone LLVM sources (default: https://github.com/llvm/llvm-project.git)"
14+
15+
exit 1
16+
}
17+
18+
# Clone the LLVM project.
19+
if (-not (Test-Path -Path "llvm-project" -PathType Container)) {
20+
git clone "$LLVM_REPO_URL" llvm-project
21+
}
22+
23+
Set-Location llvm-project
24+
git fetch origin
25+
git checkout "release/$LLVM_VERSION"
26+
git reset --hard origin/"release/$LLVM_VERSION"
27+
28+
# Create a directory to build the project.
29+
New-Item -Path "build" -Force -ItemType "directory"
30+
Set-Location build
31+
32+
# Create a directory to receive the complete installation.
33+
New-Item -Path "install" -Force -ItemType "directory"
34+
35+
# Adjust compilation based on the OS.
36+
$CMAKE_ARGUMENTS = ""
37+
38+
# Adjust cross compilation
39+
$CROSS_COMPILE = ""
40+
41+
# Run `cmake` to configure the project.
42+
cmake `
43+
-G "Visual Studio 16 2019" `
44+
-DCMAKE_BUILD_TYPE=MinSizeRel `
45+
-DCMAKE_INSTALL_PREFIX=destdir `
46+
-DLLVM_ENABLE_PROJECTS="clang;lld" `
47+
-DLLVM_ENABLE_TERMINFO=OFF `
48+
-DLLVM_ENABLE_ZLIB=OFF `
49+
-DLLVM_INCLUDE_DOCS=OFF `
50+
-DLLVM_INCLUDE_EXAMPLES=OFF `
51+
-DLLVM_INCLUDE_GO_TESTS=OFF `
52+
-DLLVM_INCLUDE_TESTS=OFF `
53+
-DLLVM_INCLUDE_TOOLS=ON `
54+
-DLLVM_INCLUDE_UTILS=OFF `
55+
-DLLVM_OPTIMIZED_TABLEGEN=ON `
56+
-DLLVM_TARGETS_TO_BUILD="X86;AArch64" `
57+
$CROSS_COMPILE `
58+
$CMAKE_ARGUMENTS `
59+
../llvm
60+
61+
# Showtime!
62+
cmake --build . --config Release
63+
64+
# Not using DESTDIR here, quote from
65+
# https://cmake.org/cmake/help/latest/envvar/DESTDIR.html
66+
# > `DESTDIR` may not be used on Windows because installation prefix
67+
# > usually contains a drive letter like in `C:/Program Files` which cannot
68+
# > be prepended with some other prefix.
69+
cmake --install . --strip --config Release

scripts/build-llvm/build.sh

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/bash
2+
3+
# Display all commands before executing them.
4+
set -o errexit
5+
set -o errtrace
6+
7+
LLVM_VERSION=$1
8+
LLVM_REPO_URL=${2:-https://github.com/llvm/llvm-project.git}
9+
LLVM_CROSS="$3"
10+
11+
if [[ -z "$LLVM_REPO_URL" || -z "$LLVM_VERSION" ]]
12+
then
13+
echo "Usage: $0 <llvm-version> <llvm-repository-url> [aarch64]"
14+
echo
15+
echo "# Arguments"
16+
echo " llvm-version The name of a LLVM release branch without the 'release/' prefix"
17+
echo " llvm-repository-url The URL used to clone LLVM sources (default: https://github.com/llvm/llvm-project.git)"
18+
echo " aarch64 To cross-compile an aarch64 version of LLVM"
19+
20+
exit 1
21+
fi
22+
23+
# Clone the LLVM project.
24+
if [ ! -d llvm-project ]
25+
then
26+
git clone "$LLVM_REPO_URL" llvm-project
27+
fi
28+
29+
30+
cd llvm-project
31+
git fetch origin
32+
git checkout "release/$LLVM_VERSION"
33+
git reset --hard origin/"release/$LLVM_VERSION"
34+
35+
# Create a directory to build the project.
36+
mkdir -p build
37+
cd build
38+
39+
# Create a directory to receive the complete installation.
40+
mkdir -p install
41+
42+
# Adjust compilation based on the OS.
43+
CMAKE_ARGUMENTS=""
44+
45+
case "${OSTYPE}" in
46+
darwin*) ;;
47+
linux*) ;;
48+
*) ;;
49+
esac
50+
51+
# Adjust cross compilation
52+
CROSS_COMPILE=""
53+
54+
case "${LLVM_CROSS}" in
55+
aarch64*) CROSS_COMPILE="-DLLVM_HOST_TRIPLE=aarch64-linux-gnu" ;;
56+
*) ;;
57+
esac
58+
59+
# Run `cmake` to configure the project.
60+
cmake \
61+
-G "Unix Makefiles" \
62+
-DCMAKE_BUILD_TYPE=MinSizeRel \
63+
-DCMAKE_INSTALL_PREFIX="/" \
64+
-DLLVM_ENABLE_PROJECTS="clang;lld" \
65+
-DLLVM_ENABLE_TERMINFO=OFF \
66+
-DLLVM_ENABLE_ZLIB=OFF \
67+
-DLLVM_INCLUDE_DOCS=OFF \
68+
-DLLVM_INCLUDE_EXAMPLES=OFF \
69+
-DLLVM_INCLUDE_GO_TESTS=OFF \
70+
-DLLVM_INCLUDE_TESTS=OFF \
71+
-DLLVM_INCLUDE_TOOLS=ON \
72+
-DLLVM_INCLUDE_UTILS=OFF \
73+
-DLLVM_OPTIMIZED_TABLEGEN=ON \
74+
-DLLVM_TARGETS_TO_BUILD="X86;AArch64" \
75+
"${CROSS_COMPILE}" \
76+
"${CMAKE_ARGUMENTS}" \
77+
../llvm
78+
79+
# Showtime!
80+
cmake --build . --config MinSizeRel
81+
DESTDIR=destdir cmake --install . --strip --config MinSizeRel
82+
83+
# move usr/bin/* to bin/ or llvm-config will be broken
84+
mv destdir/usr/bin/* destdir/bin/

0 commit comments

Comments
 (0)