Skip to content

Commit 53c4305

Browse files
committed
feat: enhance build_musl.sh with robust retry logic for installation
- Added a global wget configuration to handle transient HTTP errors and improve resilience during tarball downloads. - Implemented an outer retry loop around the `make install` command to manage potential failures, allowing up to four attempts with exponential backoff. - This enhancement ensures a more reliable build process when using musl-cross-make, particularly in environments with variable mirror quality.
1 parent 20179d0 commit 53c4305

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

common/build/deplib/build_musl.sh

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
#!/bin/bash
22

33
set -euo pipefail
4+
5+
# musl-cross-make pulls binutils/gmp/mpc/mpfr/gcc tarballs through
6+
# ftpmirror.gnu.org, which is a redirector that routes to mirrors of
7+
# wildly varying quality. When a redirect lands on a sad mirror the
8+
# response is HTTP 502 and the wget invocation inside their Makefile
9+
# gives up after one try, killing the entire build. We make wget retry
10+
# 5xx responses globally so musl-cross-make's untouched Makefile gets
11+
# the resilience for free.
12+
mkdir -p /etc
13+
cat > /etc/wgetrc <<'WGETRC'
14+
tries = 10
15+
waitretry = 10
16+
timeout = 60
17+
retry_connrefused = on
18+
retry_on_http_error = 408,429,500,502,503,504
19+
WGETRC
20+
421
git clone --depth 1 https://github.com/25077667/musl-cross-make.git
522

623
cp ./config.mak musl-cross-make/config.mak
@@ -11,7 +28,24 @@ if [ -z "${OUTPUT_DIR}" ]; then
1128
fi
1229

1330
cd musl-cross-make
14-
make -j "$(nproc)" install
31+
# Outer retry around the whole `make install`. musl-cross-make uses
32+
# `wget -c` for resumption, so a retried run picks up partial tarballs
33+
# rather than redownloading. Belt-and-braces with the wgetrc above:
34+
# wgetrc handles per-request transient errors; this loop covers the
35+
# case where the same tarball fails its full retry budget on a
36+
# completely-down mirror window.
37+
attempt=0
38+
max_attempts=4
39+
until make -j "$(nproc)" install; do
40+
attempt=$((attempt + 1))
41+
if [ "$attempt" -ge "$max_attempts" ]; then
42+
echo "build_musl.sh: make install failed after $attempt attempts" >&2
43+
exit 1
44+
fi
45+
backoff=$((attempt * 30))
46+
echo "build_musl.sh: make install failed (attempt $attempt/$max_attempts), retrying in ${backoff}s..." >&2
47+
sleep "$backoff"
48+
done
1549

1650
OUTPUT_PATH="${OUTPUT_DIR}"
1751

0 commit comments

Comments
 (0)