Skip to content

Commit bbf941b

Browse files
committed
ci: Reduce redundant commands in build.sh
1 parent 67988b7 commit bbf941b

File tree

1 file changed

+77
-124
lines changed

1 file changed

+77
-124
lines changed

ci/build.sh

Lines changed: 77 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,24 @@ if [ "$TOOLCHAIN" = "nightly" ] ; then
2020
fi
2121

2222
test_target() {
23-
build_cmd="${1}"
24-
target="${2}"
25-
no_std="${3:-}"
23+
target="${1}"
24+
no_dist="${2:-0}"
2625

2726
RUSTFLAGS="${RUSTFLAGS:-}"
2827

29-
# If there is a std component, fetch it:
30-
if [ "${no_std}" != "1" ]; then
28+
# The basic command that is run each time
29+
cmd="cargo +$rust build --target $target"
30+
31+
if [ "${no_dist}" != "0" ]; then
32+
# If we can't download a `core`, we need to build it
33+
cmd="$cmd -Zbuild-std=core,alloc"
34+
35+
# FIXME: With `build-std` feature, `compiler_builtins` emits a lof of lint warnings.
36+
RUSTFLAGS="${RUSTFLAGS:-} -Aimproper_ctypes_definitions"
37+
export RUSTFLAGS
38+
else
39+
# Otherwise it is available for download; fetch it:
40+
3141
# FIXME: rustup often fails to download some artifacts due to network
3242
# issues, so we retry this N times.
3343
N=5
@@ -39,73 +49,16 @@ test_target() {
3949
n=$((n+1))
4050
sleep 1
4151
done
42-
43-
# FIXME: With `build-std` feature, `compiler_builtins` emits a lof of lint warnings.
44-
RUSTFLAGS="${RUSTFLAGS:-} -Aimproper_ctypes_definitions"
45-
export RUSTFLAGS
46-
fi
47-
48-
# Test that libc builds without any default features (no std)
49-
if [ "$no_std" != "1" ]; then
50-
cargo "+$rust" "$build_cmd" --no-default-features --target "$target"
51-
else
52-
cargo "+$rust" "$build_cmd" \
53-
-Z build-std=core,alloc \
54-
--no-default-features \
55-
--target "$target"
5652
fi
5753

58-
# Test that libc builds with default features (e.g. std)
59-
# if the target supports std
60-
if [ "$no_std" != "1" ]; then
61-
cargo "+$rust" "$build_cmd" --target "$target"
62-
else
63-
cargo "+$rust" "${build_cmd}" \
64-
-Z build-std=core,alloc \
65-
--target "$target"
66-
fi
67-
68-
# Test that libc builds with the `extra_traits` feature
69-
if [ "$no_std" != "1" ]; then
70-
cargo "+$rust" "$build_cmd" \
71-
--no-default-features \
72-
--features extra_traits \
73-
--target "$target"
74-
else
75-
cargo "+$rust" "$build_cmd" \
76-
-Z build-std=core,alloc \
77-
--no-default-features \
78-
--features extra_traits \
79-
--target "$target"
80-
fi
81-
82-
# Test the 'const-extern-fn' feature on nightly
83-
if [ "${rust}" = "nightly" ]; then
84-
if [ "${no_std}" != "1" ]; then
85-
cargo "+$rust" "$build_cmd" \
86-
--no-default-features \
87-
--features const-extern-fn \
88-
--target "$target"
89-
else
90-
cargo "+$rust" "$build_cmd" \
91-
-Z build-std=core,alloc \
92-
--no-default-features \
93-
--features const-extern-fn \
94-
--target "$target"
95-
fi
96-
fi
54+
# Test with expected combinations of features
55+
$cmd
56+
$cmd --features const-extern-fn
57+
$cmd --features extra_traits
9758

98-
# Also test that it builds with `extra_traits` and default features:
99-
if [ "$no_std" != "1" ]; then
100-
cargo "+$rust" "$build_cmd" \
101-
--target "$target" \
102-
--features extra_traits
103-
else
104-
cargo "+$rust" "$build_cmd" \
105-
-Z build-std=core,alloc \
106-
--target "$target" \
107-
--features extra_traits
108-
fi
59+
# Test again without default features, i.e. without "std"
60+
$cmd --no-default-features
61+
$cmd --no-default-features --features extra_traits
10962
}
11063

11164
rust_linux_targets="\
@@ -171,48 +124,10 @@ x86_64-pc-windows-gnu \
171124
i686-pc-windows-msvc \
172125
"
173126

174-
# The targets are listed here alphabetically
175-
targets=""
176-
case "${OS}" in
177-
linux*)
178-
targets="$rust_linux_targets"
179-
180-
if [ "$rust" = "nightly" ]; then
181-
targets="$targets $rust_nightly_linux_targets"
182-
fi
183-
184-
;;
185-
macos*)
186-
targets="$rust_apple_targets"
187-
188-
if [ "$rust" = "nightly" ]; then
189-
targets="$targets $rust_nightly_apple_targets"
190-
fi
191-
192-
;;
193-
windows*)
194-
targets=${rust_nightly_windows_targets}
195-
;;
196-
*) ;;
197-
esac
198-
199-
for target in $targets; do
200-
if echo "$target" | grep -q "$filter"; then
201-
if [ "${OS}" = "windows" ]; then
202-
TARGET="$target" ./ci/install-rust.sh
203-
test_target build "$target"
204-
else
205-
test_target build "$target"
206-
fi
207-
208-
test_run=1
209-
fi
210-
done
211-
212127
# Targets which are not available via rustup and must be built with -Zbuild-std
213128
# FIXME(hexagon): hexagon-unknown-linux-musl should be tested but currently has
214129
# duplicate symbol errors from `compiler_builtins`.
215-
rust_linux_no_core_targets="\
130+
rust_linux_no_dist_targets="\
216131
aarch64-pc-windows-msvc \
217132
aarch64-unknown-freebsd \
218133
aarch64-unknown-hermit \
@@ -276,31 +191,69 @@ x86_64-unknown-openbsd \
276191
x86_64-wrs-vxworks \
277192
"
278193

279-
if [ "${rust}" = "nightly" ] && [ "${OS}" = "linux" ]; then
280-
for target in $rust_linux_no_core_targets; do
281-
if echo "$target" | grep -q "$FILTER"; then
282-
test_target "$target" 1
283-
fi
284-
285-
test_run=1
286-
done
287-
fi
288-
289-
rust_apple_no_core_targets="\
194+
rust_apple_no_dist_targets="\
290195
armv7s-apple-ios \
291196
i686-apple-darwin \
292197
i386-apple-ios \
293198
"
294199

295-
if [ "${rust}" = "nightly" ] && [ "${OS}" = "macos" ]; then
296-
for target in $rust_apple_no_core_targets; do
297-
if echo "$target" | grep -q "$FILTER"; then
200+
# The targets are listed here alphabetically
201+
targets=""
202+
no_dist_targets=""
203+
204+
case "${OS}" in
205+
linux*)
206+
targets="$rust_linux_targets"
207+
208+
if [ "$rust" = "nightly" ]; then
209+
targets="$targets $rust_nightly_linux_targets"
210+
no_dist_targets="$rust_linux_no_dist_targets"
211+
fi
212+
213+
;;
214+
macos*)
215+
targets="$rust_apple_targets"
216+
217+
if [ "$rust" = "nightly" ]; then
218+
targets="$targets $rust_nightly_apple_targets"
219+
no_dist_targets="$rust_apple_no_dist_targets"
220+
fi
221+
222+
;;
223+
windows*)
224+
targets=${rust_nightly_windows_targets}
225+
;;
226+
*)
227+
echo "Unrecognized OS $OS"
228+
exit 1
229+
;;
230+
esac
231+
232+
for target in $targets; do
233+
if echo "$target" | grep -q "$filter"; then
234+
if [ "${OS}" = "windows" ]; then
235+
TARGET="$target" ./ci/install-rust.sh
236+
test_target "$target"
237+
else
238+
test_target "$target"
239+
fi
240+
241+
test_run=1
242+
fi
243+
done
244+
245+
for target in $no_dist_targets; do
246+
if echo "$target" | grep -q "$filter"; then
247+
if [ "${OS}" = "windows" ]; then
248+
TARGET="$target" ./ci/install-rust.sh
249+
test_target "$target" 1
250+
else
298251
test_target "$target" 1
299252
fi
300253

301254
test_run=1
302-
done
303-
fi
255+
fi
256+
done
304257

305258
# Make sure we didn't accidentally filter everything
306259
if [ "${test_run:-}" != 1 ]; then

0 commit comments

Comments
 (0)