Skip to content

Commit 7dbd1d1

Browse files
committed
ci: patch codspeed v4.0.4 for gnu11 compatibility
Dynamically patches codspeed build.rs during CI to use gnu11 instead of gnu17, addressing CodSpeedHQ/codspeed-rust#139 for older GCC toolchain compatibility in cross-compilation containers. Implementation: - Clone and patch codspeed v4.0.4 with retry logic - Validate build.rs and verify patch application - Inject [patch.crates-io] configuration at runtime - Platform-aware sed handling (macOS/Linux) - Update Cargo.lock for patched dependency The patch applies only during CI runs and does not persist in source control.
1 parent 36ca7bc commit 7dbd1d1

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

.github/workflows/CICD.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,45 @@ jobs:
777777
echo 200:x:2000: | sudo tee -a /etc/group
778778
;;
779779
esac
780+
- name: Apply CodSpeed gnu11 compatibility patch
781+
shell: bash
782+
run: |
783+
## CodSpeed gnu11 compatibility patch (addresses CodSpeedHQ/codspeed-rust#139)
784+
set -euo pipefail
785+
CODSPEED_VERSION="v4.0.4"
786+
CODSPEED_REPO="https://github.com/CodSpeedHQ/codspeed-rust"
787+
CODSPEED_TMP="${RUNNER_TEMP:-/tmp}/codspeed-rust"
788+
BUILD_RS="$CODSPEED_TMP/crates/codspeed/build.rs"
789+
# clone with retry
790+
for attempt in 1 2 3; do
791+
git clone --depth 1 --branch "$CODSPEED_VERSION" "$CODSPEED_REPO" "$CODSPEED_TMP" 2>/dev/null && break
792+
[ $attempt -eq 3 ] && { echo "::error::Failed to clone codspeed-rust"; exit 1; }
793+
sleep 2
794+
done
795+
# validate and patch build.rs
796+
[ ! -f "$BUILD_RS" ] && { echo "::error::build.rs not found"; exit 1; }
797+
if grep -q '\-std=gnu17' "$BUILD_RS"; then
798+
if [[ "$OSTYPE" == "darwin"* ]]; then
799+
sed -i '' 's/-std=gnu17/-std=gnu11/g' "$BUILD_RS"
800+
else
801+
sed -i 's/-std=gnu17/-std=gnu11/g' "$BUILD_RS"
802+
fi
803+
grep -q '\-std=gnu11' "$BUILD_RS" && ! grep -q '\-std=gnu17' "$BUILD_RS" || { echo "::error::Patch failed"; exit 1; }
804+
fi
805+
# inject cargo patch
806+
PATCH_ENTRY="codspeed = { path = \"$CODSPEED_TMP/crates/codspeed\" }"
807+
if grep -q '^\[patch\.crates-io\]' Cargo.toml; then
808+
if grep -q '^codspeed\s*=' Cargo.toml; then
809+
[[ "$OSTYPE" == "darwin"* ]] && sed -i '' "s|^codspeed\s*=.*|$PATCH_ENTRY|" Cargo.toml || sed -i "s|^codspeed\s*=.*|$PATCH_ENTRY|" Cargo.toml
810+
else
811+
awk -v entry="$PATCH_ENTRY" '/^\[patch\.crates-io\]/ { print; print entry; next } { print }' Cargo.toml > Cargo.toml.tmp && mv Cargo.toml.tmp Cargo.toml
812+
fi
813+
else
814+
printf "\n[patch.crates-io]\n%s\n" "$PATCH_ENTRY" >> Cargo.toml
815+
fi
816+
grep -q "codspeed.*=.*path.*$CODSPEED_TMP" Cargo.toml || { echo "::error::Failed to add patch"; exit 1; }
817+
# update lockfile
818+
cargo update -p codspeed 2>/dev/null || cargo update -p codspeed-divan-compat 2>/dev/null || true
780819
- uses: taiki-e/install-action@v2
781820
if: steps.vars.outputs.CARGO_CMD == 'redoxer'
782821
with:

0 commit comments

Comments
 (0)