Skip to content

Commit 5b7dd81

Browse files
committedNov 20, 2024
ci: Reduce redundant commands in build.sh
1 parent c1a30e1 commit 5b7dd81

File tree

1 file changed

+28
-75
lines changed

1 file changed

+28
-75
lines changed
 

‎ci/build.sh

+28-75
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
4652
fi
4753

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"
56-
fi
54+
# Test with expected combinations of features
55+
$cmd
56+
$cmd --features const-extern-fn
57+
$cmd --features extra_traits
5758

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
97-
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="\
@@ -200,9 +153,9 @@ for target in $targets; do
200153
if echo "$target" | grep -q "$filter"; then
201154
if [ "${OS}" = "windows" ]; then
202155
TARGET="$target" ./ci/install-rust.sh
203-
test_target build "$target"
156+
test_target "$target"
204157
else
205-
test_target build "$target"
158+
test_target "$target"
206159
fi
207160

208161
test_run=1
@@ -212,7 +165,7 @@ done
212165
# Targets which are not available via rustup and must be built with -Zbuild-std
213166
# FIXME(hexagon): hexagon-unknown-linux-musl should be tested but currently has
214167
# duplicate symbol errors from `compiler_builtins`.
215-
rust_linux_no_core_targets="\
168+
rust_linux_no_dist_targets="\
216169
aarch64-pc-windows-msvc \
217170
aarch64-unknown-freebsd \
218171
aarch64-unknown-hermit \
@@ -277,7 +230,7 @@ x86_64-wrs-vxworks \
277230
"
278231

279232
if [ "${rust}" = "nightly" ] && [ "${OS}" = "linux" ]; then
280-
for target in $rust_linux_no_core_targets; do
233+
for target in $rust_linux_no_dist_targets; do
281234
if echo "$target" | grep -q "$FILTER"; then
282235
test_target "$target" 1
283236
fi
@@ -286,14 +239,14 @@ if [ "${rust}" = "nightly" ] && [ "${OS}" = "linux" ]; then
286239
done
287240
fi
288241

289-
rust_apple_no_core_targets="\
242+
rust_apple_no_dist_targets="\
290243
armv7s-apple-ios \
291244
i686-apple-darwin \
292245
i386-apple-ios \
293246
"
294247

295248
if [ "${rust}" = "nightly" ] && [ "${OS}" = "macos" ]; then
296-
for target in $rust_apple_no_core_targets; do
249+
for target in $rust_apple_no_dist_targets; do
297250
if echo "$target" | grep -q "$FILTER"; then
298251
test_target "$target" 1
299252
fi

0 commit comments

Comments
 (0)