Skip to content

Commit 776c4e2

Browse files
authored
fix(ci): harden cargo build retry by wiping target dir and disabling sccache (#77)
The multi-arch publish job fails with 'extern location does not exist' errors for version_check when BuildKit cache mounts contain stale artifacts. The existing retry logic (cargo clean + retry) was ineffective because: 1. cargo clean relies on its own metadata to decide what to remove, which can itself be stale on BuildKit cache mounts shared across different build profiles (debug vs release). 2. sccache remained enabled during the retry, so a corrupt memcached cache entry would reproduce the same failure even after cleaning. Replace cargo clean with rm -rf /build/target/* for a thorough wipe, and unset RUSTC_WRAPPER on retry so cargo falls back to raw rustc.
1 parent 47bd104 commit 776c4e2

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

deploy/docker/cross-build.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,17 @@ cargo_cross_build() {
108108
# "No such file or directory" writing .d files if deps/ is missing.
109109
mkdir -p "$(cross_output_dir "$profile")/deps"
110110
# Retry once after cleaning if the build fails. BuildKit cargo-target cache
111-
# mounts can retain stale .rmeta files from prior builds with different
112-
# dependency versions; cargo clean purges them so the retry succeeds.
113-
# sccache still has the compiled objects, so the clean rebuild is fast.
111+
# mounts can retain stale .rmeta/.rlib files from prior builds with different
112+
# dependency versions or profiles. We wipe the entire target directory
113+
# (rm -rf is more thorough than cargo clean, which relies on its own stale
114+
# metadata) and disable sccache for the retry — a corrupt sccache cache
115+
# entry can cause "extern location does not exist" errors even on a
116+
# freshly-cleaned target dir, so falling back to raw rustc is safer.
114117
if ! cargo build $target_flag "$@"; then
115-
echo "cargo build failed; cleaning stale target cache and retrying..." >&2
116-
cargo clean 2>/dev/null || true
118+
echo "cargo build failed; cleaning stale target cache and retrying without sccache..." >&2
119+
rm -rf /build/target/*
117120
mkdir -p "$(cross_output_dir "$profile")/deps"
121+
unset RUSTC_WRAPPER 2>/dev/null || true
118122
cargo build $target_flag "$@"
119123
fi
120124
}

0 commit comments

Comments
 (0)