[CI] Authenticate GitHub release downloads (#25370)

Website publishing hit GitHub’s anonymous API rate limit, and CI
intermittently failed to download toolchains from GitHub Releases.

Use the ephemeral read-only `GITHUB_TOKEN` for release requests. Retry
failed downloads with a fresh URL and verify each toolchain’s pinned
checksum before installation.

Assisted-By: Codex
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 18502d3..370a7d8 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -97,6 +97,12 @@
           sudo apt install -y ninja-build
           echo "CC=clang" >> $GITHUB_ENV
           echo "CXX=clang++" >> $GITHUB_ENV
+      - name: (Windows) Install ccache
+        if: runner.os == 'Windows'
+        shell: bash
+        env:
+          GH_TOKEN: ${{ github.token }}
+        run: bash ./build_tools/scripts/install_windows_ccache.sh
       - name: (Windows) Configure MSVC
         if: contains(matrix.name, 'windows')
         uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0
@@ -113,6 +119,8 @@
       - name: ccache
         uses: hendrikmuhs/ccache-action@e91f31892a1d1b8c44424b1a94c0b7f52d337168 # v1.2.26
         with:
+          install: ${{ runner.os == 'Windows' && 'no' || 'detect' }}
+          verbose: ${{ runner.os == 'Windows' && '1' || '0' }}
           key: ${{ github.job }}-${{ matrix.name }}
           save: ${{ needs.setup.outputs.write-caches == 1 }}
       - name: CMake - configure
@@ -121,6 +129,7 @@
             -G Ninja \
             -B ${BUILD_DIR} \
             -DCMAKE_BUILD_TYPE=RelWithDebInfo \
+            ${{ runner.os == 'Windows' && '-DCMAKE_MSVC_DEBUG_INFORMATION_FORMAT=Embedded' || '' }} \
             -DCMAKE_C_COMPILER_LAUNCHER=ccache \
             -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
             -DIREE_BUILD_COMPILER=OFF \
@@ -201,9 +210,16 @@
         with:
           key: ${{ github.job }}
           save: ${{ needs.setup.outputs.write-caches == 1 }}
+      - name: Download WASI SDK
+        env:
+          GH_TOKEN: ${{ github.token }}
+        run: python3 build_tools/wasm/download_ci_wasi_sdk.py "${RUNNER_TEMP}/wasi-dist"
       - name: CMake - configure
         run: |
+          mkdir -p "${RUNNER_TEMP}/wasi-sdk"
+          tar -xf "${RUNNER_TEMP}"/wasi-dist/*.tar.gz -C "${RUNNER_TEMP}/wasi-sdk" --strip-components=1
           cmake \
+            -DIREE_WASI_SDK_ROOT="${RUNNER_TEMP}/wasi-sdk" \
             -G Ninja \
             -B ${BUILD_DIR} \
             -DCMAKE_TOOLCHAIN_FILE=build_tools/cmake/wasm32.cmake \
@@ -249,6 +265,12 @@
           sudo apt install -y ninja-build
           echo "CC=clang" >> $GITHUB_ENV
           echo "CXX=clang++" >> $GITHUB_ENV
+      - name: (Windows) Install ccache
+        if: runner.os == 'Windows'
+        shell: bash
+        env:
+          GH_TOKEN: ${{ github.token }}
+        run: bash ./build_tools/scripts/install_windows_ccache.sh
       - name: (Windows) Configure MSVC
         if: contains(matrix.runs-on, 'windows')
         uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0
@@ -268,6 +290,8 @@
       - name: ccache
         uses: hendrikmuhs/ccache-action@e91f31892a1d1b8c44424b1a94c0b7f52d337168 # v1.2.26
         with:
+          install: ${{ runner.os == 'Windows' && 'no' || 'detect' }}
+          verbose: ${{ runner.os == 'Windows' && '1' || '0' }}
           key: ${{ github.job }}-${{ matrix.runs-on}}-${{ matrix.provider }}
           save: ${{ needs.setup.outputs.write-caches == 1 }}
       - name: CMake - configure
@@ -276,6 +300,7 @@
             -G Ninja \
             -B ${BUILD_DIR} \
             -DCMAKE_BUILD_TYPE=RelWithDebInfo \
+            ${{ runner.os == 'Windows' && '-DCMAKE_MSVC_DEBUG_INFORMATION_FORMAT=Embedded' || '' }} \
             -DCMAKE_C_COMPILER_LAUNCHER=ccache \
             -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
             -DIREE_BUILD_COMPILER=OFF \
diff --git a/.github/workflows/ci_linux_x64_bazel.yml b/.github/workflows/ci_linux_x64_bazel.yml
index f906ba6..c9b21e8 100644
--- a/.github/workflows/ci_linux_x64_bazel.yml
+++ b/.github/workflows/ci_linux_x64_bazel.yml
@@ -33,13 +33,20 @@
           submodules: true
       - name: Install Python requirements
         run: python3 -m pip install -r ./runtime/bindings/python/iree/runtime/build_requirements.txt
+      - name: Install Bazelisk
+        env:
+          GH_TOKEN: ${{ github.token }}
+        run: ./build_tools/bazel/install_bazelisk.sh 1.30.0
+      - name: Download WASI SDK
+        env:
+          GH_TOKEN: ${{ github.token }}
+        run: python3 build_tools/wasm/download_ci_wasi_sdk.py "${RUNNER_TEMP}/wasi-dist"
       - name: Build and test with Bazel
         env:
           IREE_CUDA_DEPS_DIR: /usr/local/iree_cuda_deps
         run: |
-          ./build_tools/bazel/install_bazelisk.sh 1.30.0
           cp ./build_tools/scripts/fetch_cuda_deps.sh /usr/local/bin
           /usr/local/bin/fetch_cuda_deps.sh ${IREE_CUDA_DEPS_DIR}
-          ./build_tools/bazel/build_test_all.sh
+          ./build_tools/bazel/build_test_all.sh --distdir="${RUNNER_TEMP}/wasi-dist"
 
       # Alerting on failure is the responsibility of the calling job.
diff --git a/.github/workflows/pkgci_test_riscv64.yml b/.github/workflows/pkgci_test_riscv64.yml
index 0019fba..703350e 100644
--- a/.github/workflows/pkgci_test_riscv64.yml
+++ b/.github/workflows/pkgci_test_riscv64.yml
@@ -112,11 +112,11 @@
     env:
       PACKAGE_DOWNLOAD_DIR: ${{ github.workspace }}/.packages
       VENV_DIR: ${{ github.workspace }}/.venv
-      GH_TOKEN: ${{ github.token }}
       RISCV_TOOLCHAIN_ROOT: ${{ github.workspace }}/riscv/xpack-gcc
       # xPack riscv-none-elf gcc: newlib is built -mcmodel=medany and ships
       # semihost.specs, as samples/baremetal_riscv64 requires.
       XPACK_GCC_VERSION: "15.2.0-1"
+      XPACK_GCC_ASSET_ID: "307838096"
       XPACK_GCC_SHA256: "aaaa8060c914851a3e5ee1ba82cc3d6f80972f90638a05c6e823a37557a33758"
     steps:
       # General setup.
@@ -158,10 +158,12 @@
           key: riscv-baremetal-toolchain-xpack-${{ env.XPACK_GCC_VERSION }}-${{ runner.arch }}
       - name: Bootstrap toolchain
         if: ${{ steps.restore-toolchain.outputs.cache-hit != 'true' }}
+        env:
+          GH_TOKEN: ${{ github.token }}
         run: |
           TARBALL="xpack-riscv-none-elf-gcc-${XPACK_GCC_VERSION}-linux-x64.tar.gz"
-          wget -q "https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases/download/v${XPACK_GCC_VERSION}/${TARBALL}"
-          echo "${XPACK_GCC_SHA256}  ${TARBALL}" | sha256sum -c -
+          bash build_tools/scripts/download_github_release.sh xpack-dev-tools/riscv-none-elf-gcc-xpack \
+            "${XPACK_GCC_ASSET_ID}" "${XPACK_GCC_SHA256}" "${TARBALL}"
           mkdir -p "${RISCV_TOOLCHAIN_ROOT}"
           tar -xzf "${TARBALL}" -C "${RISCV_TOOLCHAIN_ROOT}" --no-same-owner --strip-components=1
           rm "${TARBALL}"
diff --git a/.github/workflows/publish_website.yml b/.github/workflows/publish_website.yml
index 2f92104..47f1069 100644
--- a/.github/workflows/publish_website.yml
+++ b/.github/workflows/publish_website.yml
@@ -79,6 +79,8 @@
       #   https://github.com/llvm/torch-mlir (see below)
       #   https://github.com/llvm/torch-mlir-release
       - name: Generating release index
+        env:
+          GH_TOKEN: ${{ github.token }}
         run: |
           ./build_tools/python_deploy/generate_release_index.py \
             --repos="iree-org/iree,iree-org/iree-turbine" \
diff --git a/build_tools/bazel/build_test_all.sh b/build_tools/bazel/build_test_all.sh
index f547e5c..7cc76aa 100755
--- a/build_tools/bazel/build_test_all.sh
+++ b/build_tools/bazel/build_test_all.sh
@@ -9,6 +9,7 @@
 # Build IREE's core workspace with Bazel and runs tests.
 # Designed for CI, but can be run manually.
 #
+# Additional arguments are passed to both bazel cquery and bazel test.
 # Looks at environment variables and uses CI-friendly defaults for unset vars.
 #
 # GPU / hardware-dependent tests can be enabled by setting any of these to 0:
@@ -166,6 +167,7 @@
 declare -a BAZEL_TEST_CMD=(
   "${BAZEL_STARTUP_CMD[@]}"
   test
+  "$@"
 )
 
 if [[ ! -z "${SANDBOX_BASE}" ]]; then
@@ -192,7 +194,7 @@
 )
 
 CQUERY_STARLARK='str(target.label) if "IncompatiblePlatformProvider" not in providers(target) else ""'
-"${BAZEL_STARTUP_CMD[@]}" cquery //... \
+"${BAZEL_STARTUP_CMD[@]}" cquery "$@" //... \
     --output=starlark --starlark:expr="${CQUERY_STARLARK}" 2>/dev/null | \
   grep -v '^$' | \
   xargs --max-args 1000000 --max-chars 1000000 --exit \
diff --git a/build_tools/bazel/install_bazelisk.sh b/build_tools/bazel/install_bazelisk.sh
index 3206901..5407189 100755
--- a/build_tools/bazel/install_bazelisk.sh
+++ b/build_tools/bazel/install_bazelisk.sh
@@ -13,21 +13,24 @@
 
 # SHA-256 of each supported binary, as published next to it in the release.
 case "${BAZELISK_VERSION}-${ARCH}" in
-  1.30.0-amd64) BAZELISK_SHA256="a248ae2b2b62b5baebb748f6fba7203bff1a27e5d01b55399a8406744cb539e8" ;;
-  1.30.0-arm64) BAZELISK_SHA256="b2bcc040c213b44586b121bda6d983c35df121b917c3a7a66fb16f2fa0df1a4f" ;;
+  1.30.0-amd64)
+    asset_id=660754143
+    BAZELISK_SHA256="a248ae2b2b62b5baebb748f6fba7203bff1a27e5d01b55399a8406744cb539e8"
+    ;;
+  1.30.0-arm64)
+    asset_id=660754381
+    BAZELISK_SHA256="b2bcc040c213b44586b121bda6d983c35df121b917c3a7a66fb16f2fa0df1a4f"
+    ;;
   *)
     echo "No SHA-256 known for bazelisk ${BAZELISK_VERSION} on ${ARCH}; add it to $0."
     exit 1
     ;;
 esac
 
-curl --silent --fail --show-error --location \
-    "https://github.com/bazelbuild/bazelisk/releases/download/v${BAZELISK_VERSION}/bazelisk-linux-${ARCH}" \
-    --output bazelisk
-echo "${BAZELISK_SHA256}  bazelisk" | sha256sum -c -
-
-cp ./bazelisk /usr/local/bin/bazel
-chmod +x /usr/local/bin/bazel
-cp ./bazelisk /usr/local/bin/bazelisk
-chmod +x /usr/local/bin/bazelisk
-rm ./bazelisk
+download="$(mktemp)"
+trap 'rm -f "${download}"' EXIT
+bash "$(dirname "$0")/../scripts/download_github_release.sh" \
+    bazelbuild/bazelisk "${asset_id}" \
+    "${BAZELISK_SHA256}" "${download}"
+install -m 755 "${download}" /usr/local/bin/bazel
+install -m 755 "${download}" /usr/local/bin/bazelisk
diff --git a/build_tools/cmake/wasm32.cmake b/build_tools/cmake/wasm32.cmake
index 24a84be..d2ab143 100644
--- a/build_tools/cmake/wasm32.cmake
+++ b/build_tools/cmake/wasm32.cmake
@@ -67,6 +67,7 @@
 # Users can provide IREE_WASI_SDK_ROOT to skip the download.
 # Otherwise we download wasi-sdk into the build directory.
 if(NOT "${IREE_WASI_SDK_ROOT}" STREQUAL "")
+  list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES IREE_WASI_SDK_ROOT)
   set(_WASI_SDK_ROOT "${IREE_WASI_SDK_ROOT}")
 else()
   # Download wasi-sdk into the build tree (idempotent via stamp file).
diff --git a/build_tools/python_deploy/generate_release_index.py b/build_tools/python_deploy/generate_release_index.py
index a4f56f0..b64740e 100755
--- a/build_tools/python_deploy/generate_release_index.py
+++ b/build_tools/python_deploy/generate_release_index.py
@@ -24,7 +24,7 @@
   This script only requires read access to public endpoints, but you
   authenticate yourself to take advantage of the higher rate limit.
   Creating a fine-grained personal access token with no extra permissions and
-  storing it in the `GITHUB_TOKEN` environment variable seems to work well
+  storing it in the `GH_TOKEN` environment variable seems to work well
   enough.
 
   See documentation at:
@@ -44,7 +44,7 @@
 import sys
 import textwrap
 
-GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")
+GH_TOKEN = os.getenv("GH_TOKEN") or os.getenv("GITHUB_TOKEN")
 
 
 def parse_arguments():
@@ -73,8 +73,8 @@
             "Accept": "application/vnd.github+json",
             "X-GitHub-Api-Version": "2022-11-28",
         }
-        if GITHUB_TOKEN:
-            self.headers["Authorization"] = f"Bearer {GITHUB_TOKEN}"
+        if GH_TOKEN:
+            self.headers["Authorization"] = f"Bearer {GH_TOKEN}"
 
     def get_all(self):
         url = f"https://api.github.com/repos/{self._repo}/releases"
diff --git a/build_tools/scripts/download_github_release.sh b/build_tools/scripts/download_github_release.sh
new file mode 100644
index 0000000..5ecfa4d
--- /dev/null
+++ b/build_tools/scripts/download_github_release.sh
@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+# Copyright 2026 The IREE Authors
+#
+# Licensed under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+# Download a public release asset to a caller-owned temporary file.
+set -euo pipefail
+
+set +x
+url="https://api.github.com/repos/$1/releases/assets/$2"
+sha256="$3"
+output="$4"
+authorization=""
+if [[ -n "${GH_TOKEN:-}" ]]; then
+  authorization="Authorization: Bearer ${GH_TOKEN}"
+fi
+for attempt in 1 2 3; do
+  echo "Downloading $1 release asset $2 (attempt ${attempt}/3)" >&2
+  # A cached redirect may point at an expired signed asset URL.
+  if curl --proto '=https' --proto-redir '=https' --fail --silent --show-error \
+      --header 'Accept: application/octet-stream' --header @- \
+      --location --connect-timeout 15 --max-time 600 \
+      "${url}?request=$(date +%s)-${attempt}" --output "${output}" <<< "${authorization}"; then
+    echo "${sha256} *${output}" | sha256sum --check
+    exit 0
+  fi
+  if [[ "${attempt}" != 3 ]]; then
+    sleep "$((5 * attempt))"
+  fi
+done
+exit 1
diff --git a/build_tools/scripts/install_windows_ccache.sh b/build_tools/scripts/install_windows_ccache.sh
new file mode 100644
index 0000000..db13974
--- /dev/null
+++ b/build_tools/scripts/install_windows_ccache.sh
@@ -0,0 +1,17 @@
+#!/usr/bin/env bash
+# Copyright 2026 The IREE Authors
+#
+# Licensed under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+set -euo pipefail
+
+package=ccache-4.13.6-windows-x86_64
+directory="$(mktemp -d)"
+bash "$(dirname "$0")/download_github_release.sh" \
+    ccache/ccache 411999996 \
+    3d7cebb05850ad704e197b3f1d3f0f924ab6c9fdfc561578e146184fe9d89380 \
+    "${directory}/ccache.zip"
+unzip -q "${directory}/ccache.zip" "${package}/ccache.exe" -d "${directory}"
+cygpath -aw "${directory}/${package}" >> "${GITHUB_PATH}"
diff --git a/build_tools/wasm/download_ci_wasi_sdk.py b/build_tools/wasm/download_ci_wasi_sdk.py
new file mode 100644
index 0000000..1203deb
--- /dev/null
+++ b/build_tools/wasm/download_ci_wasi_sdk.py
@@ -0,0 +1,29 @@
+# Copyright 2026 The IREE Authors
+#
+# Licensed under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+"""Fetch the pinned Linux x86_64 SDK archive for the CMake and Bazel CI jobs."""
+
+from pathlib import Path
+import runpy
+import subprocess
+import sys
+
+scripts = Path(__file__).resolve().parent
+sdk = runpy.run_path(str(scripts / "wasi_sdk_version.bzl"))
+destination = Path(sys.argv[1])
+destination.mkdir(parents=True, exist_ok=True)
+archive = destination / f"wasi-sdk-{sdk['WASI_SDK_VERSION']}-x86_64-linux.tar.gz"
+subprocess.run(
+    [
+        "bash",
+        scripts.parent / "scripts/download_github_release.sh",
+        "WebAssembly/wasi-sdk",
+        sdk["WASI_SDK_LINUX_X86_64_ASSET_ID"],
+        sdk["WASI_SDK_SHA256"]["x86_64-linux"],
+        archive,
+    ],
+    check=True,
+)
diff --git a/build_tools/wasm/wasi_sdk_version.bzl b/build_tools/wasm/wasi_sdk_version.bzl
index ecb10b1..6f40dca 100644
--- a/build_tools/wasm/wasi_sdk_version.bzl
+++ b/build_tools/wasm/wasi_sdk_version.bzl
@@ -17,6 +17,10 @@
 WASI_SDK_VERSION = "30.0"
 WASI_SDK_TAG = "wasi-sdk-30"
 
+# List asset names and IDs with:
+# gh api repos/WebAssembly/wasi-sdk/releases/tags/<tag> --jq '.assets[] | [.name, .id] | @tsv'
+WASI_SDK_LINUX_X86_64_ASSET_ID = "349659806"
+
 # URL template: replace {version}, {arch}, {os}.
 WASI_SDK_URL_TEMPLATE = "https://github.com/WebAssembly/wasi-sdk/releases/download/{tag}/wasi-sdk-{version}-{arch}-{os}.tar.gz"