build-redbear: ensure toolchain LLVM has AMDGPU backend before cooking (Mesa)

The redoxer toolchain ships a prebuilt host LLVM built X86;AArch64;RISCV only.
Mesa resolves dependency('llvm', modules:[amdgpu,...]) against that host
llvm-config (COOKBOOK_HOST_SYSROOT), so radeonsi/radv AND the Intel iris/ANV
CLC precompile path fail and the whole desktop stack silently drops. The
binary prefix never regenerates that host LLVM, so add an idempotent pre-cook
hook (redbear-full only): if the toolchain llvm-config lacks AMDGPU, cook
host:llvm21 (recipe carries X86;AMDGPU;NVPTX) and splice its llvm-config +
libLLVM.so + AMDGPU headers/static libs into the toolchain, backing up the
originals first. Fails loudly; a no-op once AMDGPU is present.
This commit is contained in:
2026-07-31 13:21:47 +03:00
parent 448800aea9
commit 8a6d8ff2b7
+48 -1
View File
@@ -9,7 +9,7 @@ PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
# REDBEAR_VERSION (which tracks the OS release derived from the git branch).
# Starts at 1.0 and is bumped AUTOMATICALLY on every change by the pre-commit
# git hook (local/scripts/bump-build-version.sh); do not edit the minor by hand.
BUILD_REDBEAR_VERSION="1.6"
BUILD_REDBEAR_VERSION="1.7"
# ── Colorized output ──────────────────────────────────
# Enabled only on a TTY with NO_COLOR unset, so redirected build logs and CI
@@ -1057,6 +1057,53 @@ if [ ! -e "$_HOST_TC_DIR/toolchain" ] && [ -d "$_REDOX_TC" ]; then
ln -sfn "$_REDOX_TC" "$_HOST_TC_DIR/toolchain"
fi
# --- Ensure the redoxer toolchain LLVM carries the AMDGPU (+NVPTX) backend ---
# Mesa resolves `dependency('llvm', modules: [amdgpu, ...])` against the host
# llvm-config in the redoxer toolchain (COOKBOOK_HOST_SYSROOT, set by the mesa
# recipe). The prebuilt toolchain LLVM is compiled X86;AArch64;RISCV only — no
# GPU codegen backend — so radeonsi/radv AND the Intel iris/ANV CLC precompile
# path fail that dependency and the whole desktop (Mesa) stack silently drops.
# The prebuilt host toolchain LLVM is not regenerated by the (binary) prefix, so
# cook host:llvm21 (its recipe carries X86;AMDGPU;NVPTX) and splice its
# llvm-config + libLLVM.so + AMDGPU headers/static libs into the toolchain.
# Idempotent: a fast no-op once the toolchain already reports AMDGPU.
if [ "$CONFIG" = "redbear-full" ]; then
_TC="$HOME/.redoxer/x86_64-unknown-redox/toolchain"
_REPO="$PROJECT_ROOT/target/release/repo"
if [ -x "$_TC/bin/llvm-config" ] \
&& ! "$_TC/bin/llvm-config" --targets-built 2>/dev/null | grep -qw AMDGPU; then
echo "${C_INFO}>>>${C_RESET} Toolchain LLVM lacks the AMDGPU backend — cooking host:llvm21 (X86;AMDGPU;NVPTX) and splicing it into the toolchain (Mesa needs this)..."
if REDBEAR_CANONICAL_BUILD=1 "$_REPO" cook host:llvm21; then
_ST="$PROJECT_ROOT/recipes/dev/llvm21/target/x86_64-unknown-linux-gnu"
_LC="$_ST/stage.runtime/usr/bin/llvm-config"
if [ -x "$_LC" ] && "$_LC" --targets-built | grep -qw AMDGPU; then
if [ ! -d "$_TC/.pre-amdgpu-backup" ]; then
mkdir -p "$_TC/.pre-amdgpu-backup/bin" "$_TC/.pre-amdgpu-backup/lib"
cp -a "$_TC/bin/llvm-config" "$_TC/.pre-amdgpu-backup/bin/" 2>/dev/null || true
cp -a "$_TC"/lib/libLLVM* "$_TC/.pre-amdgpu-backup/lib/" 2>/dev/null || true
fi
rsync -a "$_LC" "$_TC/bin/llvm-config"
rsync -a "$_ST"/stage/usr/lib/libLLVM.so "$_ST"/stage/usr/lib/libLLVM.so.* "$_ST"/stage/usr/lib/libLLVM-*.so "$_TC/lib/" 2>/dev/null || true
rsync -a "$_ST"/stage.dev/usr/lib/libLLVM*.a "$_TC/lib/" 2>/dev/null || true
rsync -a --delete "$_ST"/stage.dev/usr/include/llvm "$_TC/include/" 2>/dev/null || true
rsync -a --delete "$_ST"/stage.dev/usr/include/llvm-c "$_TC/include/" 2>/dev/null || true
if "$_TC/bin/llvm-config" --targets-built | grep -qw AMDGPU; then
echo "${C_INFO}>>>${C_RESET} Toolchain LLVM now provides AMDGPU/NVPTX."
else
echo "${C_ERR}>>> ERROR:${C_RESET} AMDGPU splice failed (toolchain still lacks AMDGPU)." >&2
exit 1
fi
else
echo "${C_ERR}>>> ERROR:${C_RESET} host:llvm21 did not stage an AMDGPU-enabled llvm-config." >&2
exit 1
fi
else
echo "${C_ERR}>>> ERROR:${C_RESET} host:llvm21 cook failed (required for the Mesa AMDGPU backend)." >&2
exit 1
fi
fi
fi
echo "${C_INFO}>>>${C_RESET} Pre-cooking critical packages..."
if [ "$CONFIG" = "redbear-full" ]; then
# The Qt stack has a strict internal build order (qtbase -> qtshadertools ->