diff --git a/.github/workflows/build-dev-binaries.yml b/.github/workflows/build-dev-binaries.yml index 649d5f249..f6640521a 100644 --- a/.github/workflows/build-dev-binaries.yml +++ b/.github/workflows/build-dev-binaries.yml @@ -24,7 +24,8 @@ jobs: with: persist-credentials: false - - uses: rui314/setup-mold@725a8794d15fc7563f59595bd9556495c0564878 # v1 + - name: "Install mold" + run: ./scripts/install-mold.sh - uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2 with: @@ -51,7 +52,8 @@ jobs: with: persist-credentials: false - - uses: rui314/setup-mold@725a8794d15fc7563f59595bd9556495c0564878 # v1 + - name: "Install mold" + run: ./scripts/install-mold.sh - uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2 with: @@ -78,7 +80,8 @@ jobs: with: persist-credentials: false - - uses: rui314/setup-mold@725a8794d15fc7563f59595bd9556495c0564878 # v1 + - name: "Install mold" + run: ./scripts/install-mold.sh - name: "Setup musl" run: | @@ -110,8 +113,6 @@ jobs: with: persist-credentials: false - - uses: rui314/setup-mold@725a8794d15fc7563f59595bd9556495c0564878 # v1 - - uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2 with: save-if: ${{ inputs.save-rust-cache == 'true' }} @@ -136,8 +137,6 @@ jobs: with: persist-credentials: false - - uses: rui314/setup-mold@725a8794d15fc7563f59595bd9556495c0564878 # v1 - - uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2 with: save-if: ${{ inputs.save-rust-cache == 'true' }} @@ -241,7 +240,7 @@ jobs: env: MSRV: ${{ steps.msrv.outputs.value }} - name: "Install mold" - uses: rui314/setup-mold@725a8794d15fc7563f59595bd9556495c0564878 # v1 + run: ./scripts/install-mold.sh - uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2 with: save-if: ${{ inputs.save-rust-cache == 'true' }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 91bf79cba..8d1f05952 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,7 +33,8 @@ jobs: with: persist-credentials: false - - uses: rui314/setup-mold@725a8794d15fc7563f59595bd9556495c0564878 # v1 + - name: "Install mold" + run: ./scripts/install-mold.sh - uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2 with: @@ -106,8 +107,6 @@ jobs: with: persist-credentials: false - - uses: rui314/setup-mold@725a8794d15fc7563f59595bd9556495c0564878 # v1 - - uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2 with: save-if: ${{ inputs.save-rust-cache == 'true' }} diff --git a/scripts/install-mold.sh b/scripts/install-mold.sh new file mode 100755 index 000000000..c302a11b8 --- /dev/null +++ b/scripts/install-mold.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# Install mold linker and make it the default linker. +# +# Retries on transient HTTP errors (e.g., 500) that the `rui314/setup-mold` +# GitHub Action does not handle. + +set -euo pipefail + +MOLD_VERSION="${MOLD_VERSION:-2.40.4}" + +arch="$(uname -m)" +url="https://github.com/rui314/mold/releases/download/v${MOLD_VERSION}/mold-${MOLD_VERSION}-${arch}-linux.tar.gz" + +if [ "$(whoami)" = root ]; then + SUDO="" +else + SUDO="sudo" +fi + +echo "Installing mold ${MOLD_VERSION} (${arch})..." + +wget -O- \ + --timeout=10 \ + --tries=5 \ + --waitretry=3 \ + --retry-connrefused \ + --retry-on-http-error=429,500,502,503,504 \ + --progress=dot:mega \ + "$url" \ + | $SUDO tar -C /usr/local --strip-components=1 --no-overwrite-dir -xzf - + +# Make mold the default linker +current_ld="$(realpath /usr/bin/ld)" +if [ "$current_ld" != /usr/local/bin/mold ]; then + $SUDO ln -sf /usr/local/bin/mold "$current_ld" +fi + +echo "mold ${MOLD_VERSION} installed successfully" +mold --version