-
Notifications
You must be signed in to change notification settings - Fork 5
/
build-cross-rustc.bash
executable file
·163 lines (143 loc) · 3.81 KB
/
build-cross-rustc.bash
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash -e
# Usage information.
_help_message() {
printf "\
Usage:
$0 AOSC_ARCH
- AOSC_ARCH: AOSC OS architecture (amd64, arm64, loongson3, etc.).
"
}
# Preformatted echo.
abwarn() { echo -e "[\e[33mWARN\e[0m]: \e[1m$*\e[0m"; }
aberr() { echo -e "[\e[31mERROR\e[0m]: \e[1m$*\e[0m"; exit 1; }
abinfo() { echo -e "[\e[96mINFO\e[0m]: \e[1m$*\e[0m"; }
abdbg() { echo -e "[\e[32mDEBUG\e[0m]: \e[1m$*\e[0m"; }
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
_help_message
exit 0
fi
if [ -z "$1" ]; then
aberr "Please specify a target architecture in AOSC OS format."
_help_message
exit 1
fi
# Triple map.
case $1 in
amd64)
CHOST="amd64-aosc-linux-gnu"
;;
arm64)
CHOST="aarch64-aosc-linux-gnu"
;;
armv4)
CHOST="arm-aosc-linux-gnueabi"
;;
armv6hf)
CHOST="arm-aosc-linux-gnueabihf"
;;
armv7hf)
CHOST="arm-aosc-linux-gnueabihf"
;;
i486)
CHOST="i486-aosc-linux-gnu"
;;
loongson2f)
CHOST="mips64el-aosc-linux-gnuabi64"
;;
loongson3)
CHOST="mips64el-aosc-linux-gnuabi64"
RUSTFLAGS="${RUSTFLAGS} -Clink-args=-fuse-ld=bfd"
;;
loongarch64)
CHOST="loongarch64-aosc-linux-gnu"
;;
m68k)
CHOST="m68k-aosc-linux-gnu"
;;
mips32r6el)
CHOST="mipsisa32r6el-aosc-linux-gnu"
RUSTFLAGS='-Clink-arg=-latomic --cap-lints allow'
;;
mips64r6el)
CHOST="mipsisa64r6el-aosc-linux-gnuabi64"
RUSTFLAGS="${RUSTFLAGS} -Clink-args=-fuse-ld=bfd"
;;
powerpc)
CHOST="powerpc-aosc-linux-gnu"
;;
ppc64)
CHOST="powerpc64-aosc-linux-gnu"
;;
ppc64el)
CHOST="powerpc64le-aosc-linux-gnu"
;;
riscv64)
CHOST="riscv64-aosc-linux-gnu"
;;
alpha)
CHOST="alpha-aosc-linux-gnu"
;;
esac
# Generate Rust architecture from triple.
RARCH="${CHOST%%-*}"
# Generate LLVM triple.
RHOST="${CHOST/aosc/unknown}"
# Generate LLVM tuple for variables.
RHOST_ENV="${RHOST//\-/_}"
RHOST_ENV="${RHOST_ENV^^}"
abinfo "Applying supplied patches ..."
shopt -s nullglob
if [[ -n $(echo *.patch) ]]; then
for i in *.patch; do
abinfo "... $i ..."
patch -Np1 -i $i || \
aberr "Failed to apply patch $i: $?"
done
fi
abinfo "Generating config.toml ..."
cat > config.toml <<EOF
[llvm]
download-ci-llvm = false
optimize = true
ninja = true
[rust]
debug = false
debuginfo-level = 0
deny-warnings = false
parallel-compiler = false
[build]
target = ["${RHOST}"]
host = ["${RHOST}"]
vendor = true
EOF
cat >> config.toml <<EOF
extended = true
tools = ["cargo", "clippy", "rustfmt", "rustdoc", "rust-analyzer-proc-macro-srv"]
[install]
prefix = "/opt/rustc-bootstrap-$(cat version | cut -f1 -d' ')-$1"
EOF
abinfo "Building cross Rust for $1 ($CHOST) ..."
env \
RUSTFLAGS="-Clink-arg=-lz ${RUSTFLAGS}" \
CROSS_COMPILE="/opt/abcross/$1/bin/${CHOST}-" \
DESTDIR=`pwd`/rustc-bootstrap-$(cat version | cut -f1 -d' ')-$1 \
${RHOST_ENV}_OPENSSL_NO_VENDOR=y \
${RHOST_ENV}_OPENSSL_INCLUDE_DIR="/var/ab/cross-root/$1/usr/include" \
${RHOST_ENV}_OPENSSL_LIB_DIR="/var/ab/cross-root/$1/usr/lib" \
${RHOST_ENV}_LIBFFI_NO_VENDOR=y \
${RHOST_ENV}_LIBFFI_INCLUDE_DIR="/var/ab/cross-root/$1/usr/include" \
${RHOST_ENV}_LIBFFI_LIB_DIR="/var/ab/cross-root/$1/usr/lib" \
python3 ./x.py install || \
aberr "Failed to build cross Rust for $1 ($CHOST): $?"
abinfo "Building cross Rust tarball for $1 ($CHOST) ..."
tar cvf - rustc-bootstrap-$(cat version | cut -f1 -d' ')-$1 | \
xz -T0 -9 > rustc-bootstrap-$(cat version | cut -f1 -d' ')-$1.tar.xz || \
aberr "Failed to build cross Rust tarball for $1 ($CHOST): $?"
abinfo "Generating checksums for the cross Rust tarball ($1, $CHOST) ..."
sha256sum rustc-bootstrap-$(cat version | cut -f1 -d' ')-$1.tar.xz \
> rustc-bootstrap-$(cat version | cut -f1 -d' ')-$1.tar.xz.sha256sum || \
aberr "Failed to generate checksums for the cross Rust tarball ($1, $CHOST): $?"
abinfo "Build complete, cross Rust tarball ($1, $CHOST) available at:"
echo -e "
$PWD/rustc-bootstrap-$(cat version | cut -f1 -d' ')-$1.tar.xz
"