diff --git a/local/recipes/dev/libclc/recipe.toml b/local/recipes/dev/libclc/recipe.toml index f414d4a9ad..46c8c47566 100644 --- a/local/recipes/dev/libclc/recipe.toml +++ b/local/recipes/dev/libclc/recipe.toml @@ -17,15 +17,25 @@ shallow_clone = true [build] template = "custom" -# Build depends on the HOST clang (built by clang21) and the -# LLVMConfig.cmake (provided by llvm21's install). +# libclc's *native* build needs a COMPLETE HOST LLVM dev tree: a host-runnable +# clang + llvm-as/opt/llc/llvm-link plus find_package(LLVM)'s LLVMConfig.cmake, +# LLVMExports.cmake AND the static component libs they reference. The redoxer +# runtime toolchain (COOKBOOK_TOOLCHAIN) ships only libLLVM.so + clang — its +# LLVMExports.cmake references static libs that are not present, so +# find_package(LLVM) fails ("file does not exist"). The cross llvm21.dev is the +# WRONG LLVM (its cmake/libs target Redox, not the host). +# +# llvm-native is exactly the missing piece: a native (host) LLVM/Clang/LLD 21 +# build (same redox-2025-10-03 revision as llvm21/clang21) whose .dev package +# ships usr/lib/cmake/llvm/**, libLLVM*.a and host clang/llvm-* binaries. We +# depend on it ALONE for the host toolchain — pulling in llvm21.dev too would +# stage a SECOND, conflicting usr/lib/cmake/llvm (the cross one) into the same +# sysroot path, and find_package would non-deterministically pick the wrong one. dependencies = [ - "clang21", - "llvm21", + "llvm-native", ] dev-dependencies = [ - "clang21.dev", - "llvm21.dev", + "llvm-native.dev", ] script = ''' DYNAMIC_INIT @@ -45,27 +55,53 @@ _SAVED_CXXFLAGS="${CXXFLAGS:-}" _SAVED_CPPFLAGS="${CPPFLAGS:-}" unset LDFLAGS CFLAGS CXXFLAGS CPPFLAGS +# Resolve the HOST LLVM prefix provided by llvm-native (+ .dev), staged into +# the cross sysroot by our build-dependencies. pkgar extracts packages as-is, +# so llvm-native's usr/ tree lands under ${COOKBOOK_SYSROOT}/usr/. Everything +# libclc's native build needs is under here: the host clang/llvm-* binaries +# (usr/bin), and find_package(LLVM)'s complete cmake tree + static libs +# (usr/lib/cmake/llvm, usr/lib/libLLVM*.a). +HOST_LLVM_PREFIX="${COOKBOOK_SYSROOT}/usr" +HOST_LLVM_CMAKE="${HOST_LLVM_PREFIX}/lib/cmake/llvm" + +# Pick the host clang: llvm-native installs an unprefixed `clang` symlink; fall +# back to clang-21 if only the versioned name is present. +if [ -x "${HOST_LLVM_PREFIX}/bin/clang" ]; then + HOST_CLANG="${HOST_LLVM_PREFIX}/bin/clang" +elif [ -x "${HOST_LLVM_PREFIX}/bin/clang-21" ]; then + HOST_CLANG="${HOST_LLVM_PREFIX}/bin/clang-21" +else + echo "libclc: ERROR — host clang not found under ${HOST_LLVM_PREFIX}/bin" >&2 + echo "libclc: is the 'llvm-native' build-dependency staged? ls:" >&2 + ls -la "${HOST_LLVM_PREFIX}/bin" 2>/dev/null | grep -i clang >&2 || true + exit 1 +fi +if [ ! -f "${HOST_LLVM_CMAKE}/LLVMConfig.cmake" ]; then + echo "libclc: ERROR — host LLVMConfig.cmake not found at ${HOST_LLVM_CMAKE}" >&2 + echo "libclc: is the 'llvm-native.dev' build-dependency staged?" >&2 + exit 1 +fi + # 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 +generate_cookbook_cmake_file "${COOKBOOK_HOST_TARGET}" "" "${HOST_LLVM_PREFIX}" 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 "$ENV{COOKBOOK_TOOLCHAIN}/bin/clang-21" CACHE FILEPATH "" FORCE) -set(CMAKE_CXX_COMPILER "$ENV{COOKBOOK_TOOLCHAIN}/bin/clang-21" CACHE FILEPATH "" FORCE) -set(CMAKE_ASM_COMPILER "$ENV{COOKBOOK_TOOLCHAIN}/bin/clang-21" CACHE FILEPATH "" FORCE) -set(CMAKE_AR "$ENV{COOKBOOK_TOOLCHAIN}/bin/llvm-ar" CACHE FILEPATH "" FORCE) -set(CMAKE_NM "$ENV{COOKBOOK_TOOLCHAIN}/bin/llvm-nm" CACHE FILEPATH "" FORCE) -set(CMAKE_RANLIB "$ENV{COOKBOOK_TOOLCHAIN}/bin/llvm-ranlib" CACHE FILEPATH "" FORCE) +# Override CMAKE_C/CXX/ASM_COMPILER etc. to point at llvm-native's HOST clang +# and llvm-* tools in the sysroot, and LLVM_DIR at llvm-native's complete host +# cmake tree (the whole point of depending on llvm-native). +cat >> native_libclc.cmake <