e15590bc74
libclc's [source] uses git + path_in_repo="libclc", and the recipe assumed
COOKBOOK_SOURCE would already be the libclc subdir. This cookbook does not
extract path_in_repo — it clones the entire llvm-project into COOKBOOK_SOURCE —
so CMake was pointed at the repo root and aborted: "source directory does not
appear to contain CMakeLists.txt". Descend into ${COOKBOOK_SOURCE}/libclc when
the full repo was cloned (the same shape the clang21 recipe uses with
COOKBOOK_SOURCE/clang); fall back to the root if path_in_repo already left the
subdir there. recipe.toml is committed (not the operator's dirty source WIP).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
143 lines
6.2 KiB
TOML
143 lines
6.2 KiB
TOML
[package]
|
|
name = "libclc"
|
|
# Red Bear OS internal libclc. Upstream is llvm-project's libclc
|
|
# (https://github.com/llvm/llvm-project/tree/main/libclc). The source
|
|
# is vendored from the same revision as llvm21 (redox-2025-10-03).
|
|
# The version follows the Red Bear OS branch per local/AGENTS.md.
|
|
version = "0.3.1"
|
|
description = "libclc — Red Bear OS port of the OpenCL C library requirements (amdgcn, r600, spirv, generic targets). Provides the .bc bitcode files Mesa's clc tool consumes for hardware GPU drivers (iris, radeonsi, llvmpipe)."
|
|
|
|
[source]
|
|
# Vendored from the same revision as llvm21 / clang21.
|
|
git = "https://gitlab.redox-os.org/redox-os/llvm-project.git"
|
|
upstream = "https://github.com/llvm/llvm-project.git"
|
|
branch = "redox-2025-10-03"
|
|
path_in_repo = "libclc"
|
|
shallow_clone = true
|
|
|
|
[build]
|
|
template = "custom"
|
|
# Build depends on the HOST clang (built by clang21) and the
|
|
# LLVMConfig.cmake (provided by llvm21's install).
|
|
dependencies = [
|
|
"clang21",
|
|
"llvm21",
|
|
]
|
|
dev-dependencies = [
|
|
"clang21.dev",
|
|
"llvm21.dev",
|
|
]
|
|
script = '''
|
|
DYNAMIC_INIT
|
|
ARCH="$(echo "${TARGET}" | cut -d - -f1)"
|
|
|
|
# libclc is built with the HOST clang (not the cross-compiler):
|
|
# it produces .bc bitcode files that are architecture-independent
|
|
# for the GPU targets Mesa cares about (amdgcn, r600, spirv,
|
|
# generic). The output is then consumed at runtime by Mesa's clc
|
|
# tool via the dependency('libclc') pkg-config lookup.
|
|
|
|
# Save the cross-compile environment so we can use the HOST
|
|
# toolchain (Clang) to compile OpenCL kernels to bitcode.
|
|
_SAVED_LDFLAGS="${LDFLAGS:-}"
|
|
_SAVED_CFLAGS="${CFLAGS:-}"
|
|
_SAVED_CXXFLAGS="${CXXFLAGS:-}"
|
|
_SAVED_CPPFLAGS="${CPPFLAGS:-}"
|
|
unset LDFLAGS CFLAGS CXXFLAGS CPPFLAGS
|
|
|
|
# Generate a NATIVE toolchain file. We can't use cookbook_cmake
|
|
# because that targets the cross sysroot; libclc needs the host.
|
|
generate_cookbook_cmake_file "${COOKBOOK_HOST_TARGET}" "" "/usr" native_libclc.cmake
|
|
|
|
# Override the CMAKE_CXX_COMPILER etc. to point at the HOST clang
|
|
# that comes from the cookbook sysroot (clang21 build). The cookbook
|
|
# sysroot contains both the host Clang binary and the LLVM tools
|
|
# that libclc needs to find via LLVM_DIR.
|
|
cat >> native_libclc.cmake <<'NATIVE_EOF'
|
|
set(CMAKE_C_COMPILER "${COOKBOOK_SYSROOT}/bin/clang-21" CACHE FILEPATH "" FORCE)
|
|
set(CMAKE_CXX_COMPILER "${COOKBOOK_SYSROOT}/bin/clang-21" CACHE FILEPATH "" FORCE)
|
|
set(CMAKE_ASM_COMPILER "${COOKBOOK_SYSROOT}/bin/clang-21" CACHE FILEPATH "" FORCE)
|
|
set(CMAKE_AR "${COOKBOOK_SYSROOT}/bin/llvm-ar" CACHE FILEPATH "" FORCE)
|
|
set(CMAKE_NM "${COOKBOOK_SYSROOT}/bin/llvm-nm" CACHE FILEPATH "" FORCE)
|
|
set(CMAKE_RANLIB "${COOKBOOK_SYSROOT}/bin/llvm-ranlib" CACHE FILEPATH "" FORCE)
|
|
set(CMAKE_C_FLAGS_INIT "" CACHE STRING "" FORCE)
|
|
set(CMAKE_CXX_FLAGS_INIT "" CACHE STRING "" FORCE)
|
|
set(CMAKE_EXE_LINKER_FLAGS_INIT "" CACHE STRING "" FORCE)
|
|
set(CMAKE_SHARED_LINKER_FLAGS_INIT "" CACHE STRING "" FORCE)
|
|
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM "BYPASS" CACHE STRING "" FORCE)
|
|
set(LLVM_DIR "${COOKBOOK_SYSROOT}/lib/cmake/llvm" CACHE PATH "" FORCE)
|
|
set(LIBCLC_STANDALONE_BUILD TRUE CACHE BOOL "" FORCE)
|
|
NATIVE_EOF
|
|
|
|
# Run cmake with the host-native toolchain. LIBCLC_TARGETS_TO_BUILD
|
|
# is the list of GPU targets Mesa consumes. The target-name syntax
|
|
# in upstream libclc is `<triple>--` (double-dash suffix for the
|
|
# unspecified-ABI variant) plus the Mesa-specific `amdgcn-mesa-mesa3d`
|
|
# for the Mesa3D frontend. Targets not consumed by Mesa (ptx-nvidiacl
|
|
# for NVIDIA, clspv for Vulkan-SPIR-V) are excluded. The full set
|
|
# covers all gallium drivers Mesa 26.1.4 supports via the clc tool:
|
|
# r600 -> r600 (Southern Islands / Evergreen)
|
|
# amdgcn-- -> GCN GFX6..GFX12 (default-ABI)
|
|
# amdgcn--amdhsa -> GCN with HSA runtime
|
|
# amdgcn-mesa-mesa3d -> GCN via the Mesa3D-specific path
|
|
# The `spirv` target is handled by Mesa's own clc tool (not libclc
|
|
# bitcode); libclc's spirv files are used for mesa's SPIR-V codegen
|
|
# in clc, but the .bc files themselves are produced by Mesa's clc.
|
|
COOKBOOK_CMAKE_FLAGS+=(
|
|
-DCMAKE_TOOLCHAIN_FILE="$(realpath native_libclc.cmake)"
|
|
-DCMAKE_BUILD_TYPE=Release
|
|
-DLLVM_DIR="${COOKBOOK_SYSROOT}/lib/cmake/llvm"
|
|
-DLIBCLC_STANDALONE_BUILD=TRUE
|
|
-DLIBCLC_TARGETS_TO_BUILD="r600--;amdgcn--;amdgcn--amdhsa;amdgcn-mesa-mesa3d"
|
|
-DENABLE_RUNTIME_SUBNORMAL=OFF
|
|
-DCMAKE_INSTALL_PREFIX="${COOKBOOK_STAGE}/usr"
|
|
-DCMAKE_INSTALL_LIBDIR=lib
|
|
-DCMAKE_INSTALL_INCLUDEDIR=include
|
|
-DCMAKE_INSTALL_DATADIR=share
|
|
-DLLVM_TARGETS_TO_BUILD="$ARCH"
|
|
-G Ninja
|
|
-Wno-dev
|
|
)
|
|
|
|
# Restore the cross-compile environment (libclc install is the only
|
|
# step that uses the host toolchain; if subsequent install steps
|
|
# are added to the recipe, they'd want the cross env).
|
|
export LDFLAGS="$_SAVED_LDFLAGS"
|
|
export CFLAGS="$_SAVED_CFLAGS"
|
|
export CXXFLAGS="$_SAVED_CXXFLAGS"
|
|
export CPPFLAGS="$_SAVED_CPPFLAGS"
|
|
|
|
# Source dir is the path_in_repo subdir of the cloned llvm-project. This
|
|
# cookbook does not extract path_in_repo into COOKBOOK_SOURCE — it clones the
|
|
# whole llvm-project there — so CMake was pointed at the repo root and failed
|
|
# with "source directory does not appear to contain CMakeLists.txt". Descend
|
|
# into the libclc subdir when the whole repo was cloned (mirrors how the clang21
|
|
# recipe does COOKBOOK_SOURCE/clang); if path_in_repo already left the subdir at
|
|
# the root, use it as-is.
|
|
if [ -f "${COOKBOOK_SOURCE}/libclc/CMakeLists.txt" ]; then
|
|
COOKBOOK_SOURCE="${COOKBOOK_SOURCE}/libclc"
|
|
fi
|
|
"${COOKBOOK_CMAKE}" "${COOKBOOK_SOURCE}" "${COOKBOOK_CMAKE_FLAGS[@]}"
|
|
"${COOKBOOK_NINJA}" -j"${COOKBOOK_MAKE_JOBS}"
|
|
DESTDIR="${COOKBOOK_STAGE}/stage" "${COOKBOOK_NINJA}" install
|
|
|
|
# Move installed files from $COOKBOOK_STAGE/stage to $COOKBOOK_STAGE.
|
|
# The DESTDIR install above places everything under
|
|
# $COOKBOOK_STAGE/stage; flatten the extra stage dir.
|
|
if [ -d "${COOKBOOK_STAGE}/stage" ]; then
|
|
cp -a "${COOKBOOK_STAGE}/stage/." "${COOKBOOK_STAGE}/"
|
|
rm -rf "${COOKBOOK_STAGE}/stage"
|
|
fi
|
|
|
|
# Mesa's clc tool expects the .bc files at <libexecdir>/clc where
|
|
# libexecdir is <prefix>/share/clc (per the libclc.pc.in template).
|
|
# The cmake install above places them at $COOKBOOK_STAGE/usr/share/clc
|
|
# which is the right path; no further action needed.
|
|
'''
|
|
|
|
[[optional-packages]]
|
|
name = "dev"
|
|
files = [
|
|
"usr/include/**",
|
|
]
|