-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.sh
executable file
·196 lines (178 loc) · 3.15 KB
/
make.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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/bin/bash
set -e
set -x
export RUSTFLAGS="-C target-feature=+crt-static -C relocation-model=static"
cargo_jobs=20
# read from environment variables: ARCH, OS, LIBC
case "$ARCH" in
amd64 | x86-64 | x86_64 | x64)
arch="amd64"
;;
aarch64 | arm64)
arch="aarch64"
;;
mipsel)
arch="mipsel"
;;
armv7 | arm | armsf | armv7sf)
arch="armv7"
;;
armv7hf | armhf)
arch="armv7hf"
;;
i686 | x86)
arch="i686"
;;
*)
echo "unknown CPU arch $ARCH"
exit 1
;;
esac
case "$OS" in
linux | lin)
os="linux"
;;
android)
os="android"
;;
mac | macos | darwin | osx)
os="darwin"
;;
windows | win)
os="windows"
unset RUSTFLAGS
;;
freebsd | fbsd)
os="freebsd"
;;
netbsd | nbsd)
os="netbsd"
;;
openbsd | obsd)
os="openbsd"
;;
*)
echo "unknown OS $OS"
exit 2
;;
esac
case "$LIBC" in
gnu)
libc="gnu"
;;
musl)
libc="musl"
;;
msvc)
libc="msvc"
;;
*)
echo "does not specifiy a valid libc (${LIBC}), default to gnu (glibc)"
libc="gnu"
;;
esac
if test "libc" = "msvc" && test "$os" != "windows"
then
echo "os=$os does not support msvc"
exit 10
fi
target_arch="$arch"
if test "$arch" = "amd64"
then
target_arch="x86_64"
fi
case "$os" in
android)
echo "os=android: ignore libc=$libc"
case "$arch" in
aarch64)
target="aarch64-linux-android"
;;
amd64)
target="x86_64-linux-android"
;;
armv7 | armv7hf)
target="armv7-linux-androideabi"
;;
*)
echo "os=android does not support arch=$arch"
exit 20
;;
esac
;;
linux)
case "$arch" in
armv7)
libc="${libc}eabi"
;;
armv7hf)
target_arch="armv7"
libc="${libc}eabihf"
;;
amd64 | aarch64 | i686 | armv7 | armv7hf | mipsel)
;;
*)
echo "os=linux does not support arch=$arch"
exit 21
;;
esac
target="${target_arch}-unknown-linux-${libc}"
;;
freebsd)
echo "os=freebsd: ignore libc=$libc"
case "$arch" in
amd64 | aarch64 | i686)
;;
*)
echo "os=freebsd does not support arch=$arch"
exit 22
;;
esac
target="${target_arch}-unknown-freebsd"
;;
netbsd)
echo "os=netbsd: ignore libc=$libc"
if "$arch" != "amd64"
then
echo "os=netbsd does not arch=$arch"
exit 23
fi
target="${target_arch}-unknown-netbsd"
;;
openbsd)
echo "TODO: openbsd support"
exit 24
;;
*)
echo "bug: unreachable"
exit 25
;;
esac
case "$target" in
x86_64-unknown-linux-* | x86_64-apple-darwin | aarch64-apple-darwin | x86_64-*-windows-* )
cross="no"
;;
*)
cross="yes"
;;
esac
if test "$arch" = "i686" && test "$os" = "linux"
then
echo "not to use nightly due to rustix 'naked_asm!' issue"
cargo_args=""
else
echo "use nightly rust toolchain..."
rustup default nightly
rustup component add rust-src
cargo_args="-Z build-std=core,alloc,std,proc_macro"
fi
if test "$cross" = "yes"
then
RUSTFLAGS='' cargo install cross --jobs "$cargo_jobs"
cross build --target "$target" --jobs "$cargo_jobs" $cargo_args $@
status_code="$?"
else
cargo build --target "$target" --jobs "$cargo_jobs" $cargo_args $@
status_code="$?"
fi
exit $status_code