-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-tc.sh
128 lines (104 loc) · 3.85 KB
/
build-tc.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env bash
# Function to show an informational message
msg() {
echo -e "\e[1;32m$*\e[0m"
}
err() {
echo -e "\e[1;41m$*\e[0m"
}
# Set Chat ID, to push Notifications
CHATID="-1001688638823"
BOT_TOKEN="$BTOKEN"
GITLAB_TOKEN="$GTOKEN"
# Set a directory
DIR="$(pwd ...)"
# Inlined function to post a message
export BOT_MSG_URL="https://api.telegram.org/bot$BOT_TOKEN/sendMessage"
tg_post_msg() {
curl -s -X POST "$BOT_MSG_URL" -d chat_id="$CHATID" \
-d "disable_web_page_preview=true" \
-d "parse_mode=html" \
-d text="$1"
}
tg_post_build() {
curl --progress-bar -F document=@"$1" "$BOT_BUILD_URL" \
-F chat_id="$2" \
-F "disable_web_page_preview=true" \
-F "parse_mode=html" \
-F caption="$3"
}
# Build Info
rel_date="$(date "+%Y%m%d")" # ISO 8601 format
rel_friendly_date="$(date "+%B %-d, %Y")" # "Month day, year" format
builder_commit="$(git rev-parse HEAD)"
# Send a notificaton to TG
tg_post_msg "<b>Ngntd Clang Compilation Started with $(nproc --all) CPUs</b>%0A<b>Date : </b><code>$rel_friendly_date</code>%0A<b>Toolchain Script Commit : </b><code>$builder_commit</code>%0A"
# Build LLVM
msg "Building LLVM..."
tg_post_msg "<code>Building LLVM</code>"
./build-llvm.py \
--clang-vendor "Ngntd" \
--defines "LLVM_PARALLEL_COMPILE_JOBS=$(nproc) LLVM_PARALLEL_LINK_JOBS=$(nproc) CMAKE_C_FLAGS=-O3 CMAKE_CXX_FLAGS=-O3" \
--incremental \
--lto thin \
--projects "clang;lld;polly;compiler-rt" \
--pgo kernel-defconfig \
--shallow-clone \
--targets "ARM;AArch64;X86" 2>&1 | tee build.log
# Check if the final clang binary exists or not.
[ ! -f install/bin/clang-1* ] && {
err "Building LLVM failed ! Kindly check errors !!"
tg_post_build "build.log" "$CHATID" "Error Log"
exit 1
}
# Build binutils
msg "Building binutils..."
tg_post_msg "<code>Building Binutils</code>"
./build-binutils.py --targets arm aarch64 x86_64
# Remove unused products
rm -fr install/include
rm -f install/lib/*.a install/lib/*.la
# Strip remaining products
for f in $(find install -type f -exec file {} \; | grep 'not stripped' | awk '{print $1}'); do
strip -s "${f: : -1}"
done
# Set executable rpaths so setting LD_LIBRARY_PATH isn't necessary
for bin in $(find install -mindepth 2 -maxdepth 3 -type f -exec file {} \; | grep 'ELF .* interpreter' | awk '{print $1}'); do
# Remove last character from file output (':')
bin="${bin: : -1}"
echo "$bin"
patchelf --set-rpath "$DIR/install/lib" "$bin"
done
# Release Info
pushd llvm-project || exit
llvm_commit="$(git rev-parse HEAD)"
short_llvm_commit="$(cut -c-8 <<< "$llvm_commit")"
popd || exit
llvm_commit_url="https://github.com/llvm/llvm-project/commit/$short_llvm_commit"
binutils_ver="$(ls | grep "^binutils-" | sed "s/binutils-//g")"
clang_version="$(install/bin/clang --version | head -n1 | cut -d' ' -f4)"
tg_post_msg "<b>Ngntd clang compilation Finished</b>%0A<b>Clang Version : </b><code>$clang_version</code>%0A<b>LLVM Commit : </b><code>$llvm_commit_url</code>%0A<b>Binutils Version : </b><code>$binutils_ver</code>"
# Push to GitHub
# Update Git repository
git config --global user.name "azrim"
git config --global user.email "mirzaspc@gmail.com"
git clone "https://azrim:$GITLAB_TOKEN@gitlab.com/silont-project/clang.git" rel_repo
pushd rel_repo || exit
rm -fr ./*
cp -r ../install/* .
git checkout README.md # keep this as it's not part of the toolchain itself
git add .
git commit -asm "Update to $rel_date build
LLVM commit: $llvm_commit_url
Clang Version: $clang_version
Binutils version: $binutils_ver
Builder commit: https://github.com/ClangBuiltLinux/tc-build/commit/main"
# Downgrade the HTTP version to 1.1
git config --global http.version HTTP/1.1
# Increase git buffer size
git config --global http.postBuffer 55428800
git push -f
popd || exit
# Set git buffer to original size
git config --global http.version HTTP/2
tg_post_msg "<b>Toolchain Compilation Finished and pushed to https://gitlab.com/silont-project/clang.git</b>"