#!/usr/bin/env bash # Fetch a musl cross gcc for a static Linux release build. # scripts/ci_linux_toolchain.sh x86_64|x86|aarch64 # Prints "HOST BINDIR" on stdout (e.g. "x86_64-buildroot-linux-musl # /opt/x86-64--musl--stable-2025.08-1/bin"); progress goes to stderr. # Bootlin's pinned stable release first, musl.cc as a fallback. set -euo pipefail ARCH="${1:?usage: $0 x86_64|x86|aarch64}" BOOTLIN_VER="${CST_BOOTLIN_VER:-2025.08-1}" case "$ARCH" in x86_64) bl=x86-64 bl_host=x86_64-buildroot-linux-musl mc=x86_64-linux-musl sha=09fca3aa89540f1b01b5f4210d488cbeb00f522044c53e9989b1dd8a38076912 ;; x86) bl=x86-i686 bl_host=i686-buildroot-linux-musl mc=i686-linux-musl sha=3a340ebc386a057f5ddb24d8f4bbde07d2c013c99cebc02ac38565e2849bfda0 ;; aarch64) bl=aarch64 bl_host=aarch64-buildroot-linux-musl mc=aarch64-linux-musl sha=defba831ffa1175236f137069333e21ed46d4d19feb5080a90cf248b6fc2cb08 ;; *) echo "unknown arch: $ARCH" >&2 exit 1 ;; esac [[ "$BOOTLIN_VER" == 2025.08-1 ]] || sha="" # other releases: no pinned hash if [[ -n "${CST_TOOLCHAIN_ROOT:-}" ]]; then ROOT_DIR="$CST_TOOLCHAIN_ROOT" elif [[ -w /opt || "$(id -u)" -eq 0 ]]; then ROOT_DIR=/opt else ROOT_DIR="$HOME/.local/toolchains" fi mkdir -p "$ROOT_DIR" fetch() { # out url... local out="$1" u shift for u in "$@"; do echo " try $u" >&2 if curl -fsSL --retry 2 --connect-timeout 15 --max-time 900 -o "$out" "$u"; then return 0 fi done return 1 } emit() { # host bindir "$2/$1-gcc" -dumpmachine >&2 [[ -n "${GITHUB_PATH:-}" ]] && echo "$2" >>"$GITHUB_PATH" echo "$1 $2" } name="$bl--musl--stable-$BOOTLIN_VER" dir="$ROOT_DIR/$name" if [[ -x "$dir/bin/$bl_host-gcc" ]]; then emit "$bl_host" "$dir/bin" exit 0 fi echo "==> toolchain $name" >&2 tmp="$ROOT_DIR/$name.tar.xz" if fetch "$tmp" "https://toolchains.bootlin.com/downloads/releases/toolchains/$bl/tarballs/$name.tar.xz" && { [[ -z "$sha" ]] || echo "$sha $tmp" | sha256sum -c --quiet - >&2; }; then tar -C "$ROOT_DIR" -xJf "$tmp" rm -f "$tmp" # Bootlin toolchains are relocatable but must be told once where they are. [[ -x "$dir/relocate-sdk.sh" ]] && "$dir/relocate-sdk.sh" >&2 emit "$bl_host" "$dir/bin" exit 0 fi rm -f "$tmp" echo "==> bootlin unavailable, falling back to musl.cc" >&2 mdir="$ROOT_DIR/$mc-cross" if [[ ! -x "$mdir/bin/$mc-gcc" ]]; then tgz="$ROOT_DIR/$mc-cross.tgz" fetch "$tgz" "https://musl.cc/$mc-cross.tgz" "https://more.musl.cc/x86_64-linux-musl/$mc-cross.tgz" || { echo "no musl toolchain for $ARCH" >&2; exit 1; } tar -C "$ROOT_DIR" -xzf "$tgz" rm -f "$tgz" fi emit "$mc" "$mdir/bin"