Skip to content

Commit 36ce4a0

Browse files
committedNov 20, 2024
ci: Reduce redundant commands in build.sh
(backport <rust-lang#4124>) (cherry picked from commit bbf941b)
1 parent af6fc9e commit 36ce4a0

File tree

1 file changed

+77
-124
lines changed

1 file changed

+77
-124
lines changed
 

‎ci/build.sh

+77-124
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="\
@@ -173,48 +126,10 @@ x86_64-pc-windows-gnu \
173126
i686-pc-windows-msvc \
174127
"
175128

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

282-
if [ "${rust}" = "nightly" ] && [ "${OS}" = "linux" ]; then
283-
for target in $rust_linux_no_core_targets; do
284-
if echo "$target" | grep -q "$FILTER"; then
285-
test_target "$target" 1
286-
fi
287-
288-
test_run=1
289-
done
290-
fi
291-
292-
rust_apple_no_core_targets="\
197+
rust_apple_no_dist_targets="\
293198
armv7s-apple-ios \
294199
i686-apple-darwin \
295200
i386-apple-ios \
296201
"
297202

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

304257
test_run=1
305-
done
306-
fi
258+
fi
259+
done
307260

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

0 commit comments

Comments
 (0)