-
Notifications
You must be signed in to change notification settings - Fork 23
/
build-tc.sh
executable file
·120 lines (100 loc) · 3.79 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
#!/usr/bin/env bash
# Secret Variable for CI
# LLVM_NAME | Your desired Toolchain Name
# TG_TOKEN | Your Telegram Bot Token
# TG_CHAT_ID | Your Telegram Channel / Group Chat ID
# GH_USERNAME | Your Github Username
# GH_EMAIL | Your Github Email
# GH_TOKEN | Your Github Token ( repo & repo_hook )
# GH_PUSH_REPO_URL | Your Repository for store compiled Toolchain ( without https:// or www. ) ex. github.com/xyz-prjkt/xRageTC.git
# Function to show an informational message
msg() {
echo -e "\e[1;32m$*\e[0m"
}
err() {
echo -e "\e[1;41m$*\e[0m"
}
# Set a directory
DIR="$(pwd ...)"
# Inlined function to post a message
export BOT_MSG_URL="https://api.telegram.org/bot$TG_TOKEN/sendMessage"
tg_post_msg() {
curl -s -X POST "$BOT_MSG_URL" -d chat_id="$TG_CHAT_ID" \
-d "disable_web_page_preview=true" \
-d "parse_mode=html" \
-d text="$1"
}
tg_post_build() {
curl --progress-bar -F document=@"$1" "$BOT_MSG_URL" \
-F chat_id="$TG_CHAT_ID" \
-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>$LLVM_NAME: Toolchain Compilation Started</b>%0A<b>Date : </b><code>$rel_friendly_date</code>%0A<b>Toolchain Script Commit : </b><code>$builder_commit</code>%0A"
# Build LLVM
msg "$LLVM_NAME: Building LLVM..."
tg_post_msg "<b>$LLVM_NAME: Building LLVM. . .</b>"
./build-llvm.py \
--clang-vendor "$LLVM_NAME" \
--projects "clang;lld;polly" \
--targets "ARM;AArch64" \
--shallow-clone \
--incremental \
--build-type "Release" 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" "$TG_CHAT_ID" "Error Log"
exit 1
}
# Build binutils
msg "$LLVM_NAME: Building binutils..."
tg_post_msg "<b>$LLVM_NAME: Building Binutils. . .</b>"
./build-binutils.py --targets arm aarch64
# 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>$LLVM_NAME: Toolchain 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 $GH_USERNAME
git config --global user.email $GH_EMAIL
git clone "https://$GH_USERNAME:$GH_TOKEN@$GH_PUSH_REPO_URL" 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 "$LLVM_NAME: Bump to $rel_date build
LLVM commit: $llvm_commit_url
Clang Version: $clang_version
Binutils version: $binutils_ver
Builder commit: https://$GH_PUSH_REPO_URL/commit/$builder_commit"
git push -f
popd || exit
tg_post_msg "<b>$LLVM_NAME: Toolchain pushed to <code>https://$GH_PUSH_REPO_URL</code></b>"