Files
RedBear-OS/recipes/dev/llvm21/recipe.toml
T
vasilito ce8359342c llvm21+policy: add NVPTX (future NVIDIA) + document GPU-driver/LLVM strategy
Per operator: don't forget Intel + virgl, and prepare for future NVIDIA. Intel
(iris/anvil) and virgl need NO LLVM GPU backend (NIR / virtualized) — they stay
in Mesa's driver lists as first-class targets. AMD needs AMDGPU (now); NVIDIA
(future, nouveau/NVK) needs NVPTX. LLVM rebuilds are very expensive, so include
NVPTX now (llvm21: X86;AMDGPU;NVPTX) to avoid an LLVM rebuild when NVIDIA lands.
Documented the vendor->driver->LLVM-backend matrix in the amd64-only policy.
2026-07-31 11:05:42 +03:00

163 lines
6.3 KiB
TOML

[package]
name = "llvm21"
version = "0.1.0"
[source]
git = "https://gitlab.redox-os.org/redox-os/llvm-project.git"
upstream = "https://github.com/rust-lang/llvm-project.git"
branch = "redox-2025-10-03"
shallow_clone = true
[build]
template = "custom"
dependencies = [
"zstd",
]
script = """
DYNAMIC_INIT
ARCH="$(echo "${TARGET}" | cut -d - -f1)"
# Save and unset cross-compile flags inherited from DYNAMIC_INIT so
# the host cc in the native TableGen build links against the host libc
# instead of the Redox sysroot libc (which would fail with "undefined
# reference to __libc_start_main"). These env vars are also cleared
# inside native.cmake for the sub-process, but the parent shell
# still needs them unset before generating native.cmake so that the
# generated file does not embed the cross sysroot paths. The cross
# build (cookbook_cmake below) restores them from the saved values.
_SAVED_LDFLAGS="${LDFLAGS:-}"
_SAVED_CFLAGS="${CFLAGS:-}"
_SAVED_CXXFLAGS="${CXXFLAGS:-}"
unset LDFLAGS CFLAGS CXXFLAGS
# Use /usr (host sysroot) for the native build, NOT $COOKBOOK_TOOLCHAIN
# (which points to the Redox cross sysroot). The Redox sysroot's libc.a
# (relibc) lacks __libc_start_main, causing the native cmake try_compile
# to fail with "undefined reference to __libc_start_main".
generate_cookbook_cmake_file "$COOKBOOK_HOST_TARGET" "" "/usr" native.cmake
# The generated native.cmake inherits CMAKE_C_FLAGS / CMAKE_LDFLAGS / etc.
# from the cross toolchain, which causes the host cc to link the native
# TableGen build against the Redox sysroot libc and fail with
# "undefined reference to __libc_start_main". CACHE FORCE is required
# because CMake's try_compile creates a sub-cache that re-reads the
# parent values unless they are explicitly forced in the cache.
cat >> native.cmake <<'NATIVE_EOF'
# Override cross-sysroot flags so the host cc links against the host libc.
# Also clear the LDFLAGS env var that DYNAMIC_INIT exports, because cc
# picks up -L<sysroot>/lib from it and links against the Redox libc,
# which then fails with "undefined reference to __libc_start_main".
set(CMAKE_C_FLAGS "" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS "" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS_DEBUG "" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS_RELEASE "" CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_DEBUG "" CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_RELEASE "" CACHE STRING "" FORCE)
set(CMAKE_LDFLAGS "" CACHE STRING "" FORCE)
set(CMAKE_LDFLAGS_DEBUG "" CACHE STRING "" FORCE)
set(CMAKE_LDFLAGS_RELEASE "" CACHE STRING "" FORCE)
set(CMAKE_EXE_LINKER_FLAGS "" CACHE STRING "" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS "" CACHE STRING "" FORCE)
set(CMAKE_C_IMPLICIT_LINK_DIRECTORIES "" CACHE STRING "" FORCE)
set(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "" CACHE STRING "" FORCE)
set(CMAKE_SYSROOT "" CACHE STRING "" FORCE)
set(CMAKE_FIND_ROOT_PATH "" CACHE STRING "" FORCE)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM "NEVER" CACHE STRING "" FORCE)
set(ENV{LDFLAGS} "")
set(ENV{CFLAGS} "")
set(ENV{CXXFLAGS} "")
NATIVE_EOF
# amd64-only (see local/AGENTS.md): the CPU target is X86 (= amd64/x86_64).
# GPU codegen backends are a separate axis from the CPU platform and are driven
# by which Mesa drivers we ship:
# - AMDGPU -> radeonsi (GL) + radv (Vulkan), AMD hardware GPUs. Required now:
# Mesa's `dependency('llvm', modules: [... amdgpu ...])` fails without it.
# - NVPTX -> future NVIDIA support (nouveau/NVK). Included NOW so enabling
# NVIDIA later needs no (very expensive) LLVM rebuild.
# - Intel (iris/anvil) and virgl need NO LLVM GPU backend — Intel is NIR-based
# with its own shader compiler and virgl is virtualized; they are enabled via
# Mesa's gallium/vulkan driver lists, not an LLVM target.
# None of these add a second CPU platform, so amd64-only still holds.
case "${ARCH}" in
x86 | x86_64) LLVM_TARGETS_TO_BUILD="X86;AMDGPU;NVPTX";;
aarch64) LLVM_TARGETS_TO_BUILD="AArch64;AMDGPU;NVPTX";;
riscv64gc) LLVM_TARGETS_TO_BUILD="RISCV;AMDGPU;NVPTX";;
esac
if [ "${COOKBOOK_HOST_SYSROOT}" = "/usr" ]; then
LLVM_TARGETS_TO_BUILD="X86;AMDGPU;NVPTX"
fi
# This just build the LLVM library and tools just enough for Rust, to build the rest of LLVM see
# https://github.com/llvm/llvm-zorg/blob/main/zorg/buildbot/builders/annotated/standalone-build.sh
COOKBOOK_CMAKE_FLAGS+=(
-DLLVM_BUILD_LLVM_DYLIB=On
-DLLVM_LINK_LLVM_DYLIB=On
-DLLVM_INCLUDE_UTILS=On
-DLLVM_INSTALL_UTILS=On
-DLLVM_TOOL_LLVM_COV_BUILD=On
-DLLVM_TOOL_LLVM_PROFDATA_BUILD=On
-DLLVM_TARGETS_TO_BUILD="$LLVM_TARGETS_TO_BUILD"
-DLLVM_ENABLE_ZLIB=Off
-DLLVM_USE_STATIC_ZSTD=On
-DLLVM_ENABLE_LIBXML2=Off
# the rest of options that shared to clang
-DCROSS_TOOLCHAIN_FLAGS_NATIVE="-DCMAKE_TOOLCHAIN_FILE=$(realpath "${COOKBOOK_RECIPE}/native.cmake")"
-DCMAKE_CXX_FLAGS="--std=gnu++11"
-DBUILD_SHARED_LIBS=False
-DLLVM_BUILD_EXAMPLES=Off
-DLLVM_BUILD_TESTS=Off
-DLLVM_DEFAULT_TARGET_TRIPLE="${TARGET}"
-DLLVM_ENABLE_LTO=Off
-DLLVM_ENABLE_RTTI=On
-DLLVM_ENABLE_THREADS=On
-DLLVM_INCLUDE_EXAMPLES=Off
-DLLVM_INCLUDE_TESTS=Off
-DLLVM_OPTIMIZED_TABLEGEN=On
-DLLVM_TARGET_ARCH=$ARCH
-DLLVM_TOOLS_INSTALL_DIR=bin
-DLLVM_UTILS_INSTALL_DIR=bin
-DUNIX=1
)
COOKBOOK_SOURCE="$COOKBOOK_SOURCE/llvm"
# Pass cross-compile linker flags via cmake variables instead of the
# LDFLAGS env var. LDFLAGS in the environment leaks into the native
# TableGen build's cmake try_compile, causing it to link against the
# Redox relibc (which lacks __libc_start_main) instead of host glibc.
# By keeping LDFLAGS unset and passing flags through cmake, the native
# build inherits a clean environment.
if [ -n "${_SAVED_LDFLAGS}" ]; then
COOKBOOK_CMAKE_FLAGS+=(-DCMAKE_EXE_LINKER_FLAGS="${_SAVED_LDFLAGS}")
COOKBOOK_CMAKE_FLAGS+=(-DCMAKE_SHARED_LINKER_FLAGS="${_SAVED_LDFLAGS}")
fi
if [ -n "${_SAVED_CFLAGS}" ]; then
COOKBOOK_CMAKE_FLAGS+=(-DCMAKE_C_FLAGS="${_SAVED_CFLAGS}")
fi
if [ -n "${_SAVED_CXXFLAGS}" ]; then
COOKBOOK_CMAKE_FLAGS+=(-DCMAKE_CXX_FLAGS="--std=gnu++11 ${_SAVED_CXXFLAGS}")
else
COOKBOOK_CMAKE_FLAGS+=(-DCMAKE_CXX_FLAGS="--std=gnu++11")
fi
cookbook_cmake
"""
# llvm runtime
[[optional-packages]]
name = "runtime"
files = [
"usr/bin/**",
]
[[optional-packages]]
name = "dev"
dependencies = [ ".runtime" ]
files = [
"usr/include/llvm*/**",
"usr/lib/libLLVM*.a",
"usr/lib/cmake/llvm/**",
]