llvm/mesa/rust: simplify llvm-config handling
PATCH v2 1/1 llvm/mesa/rust: simplify llvm-config handling
From: Deepesh Varatharajan <[email protected]>
Replace PATH-based llvm-config discovery with explicit sysroot-native resolution and simplify the target llvm-config wrapper to act as a pure pass-through while preserving Yocto alternate path handling.
The previous implementation relied on:
* which -a llvm-config | sed -n 2p
which is unreliable in cross-build environments because it only searches executables present in $PATH. Native sysroot tools (e.g. recipe-sysroot-native llvm-config) are not guaranteed to be exposed via PATH, so they may not be discovered at all.
* echo $base_libdir | sed -n '/lib64/p'
which depends on a BitBake variable that may be empty or unset in certain build contexts, leading to incorrect libdir selection.
Update the wrapper to:
* Use an @LLVM_CONFIG_PATH@ placeholder that is replaced during the build with the appropriate native llvm-config path.
* Detect libdir using filesystem inspection rather than variable parsing.
* Preserve YOCTO_ALTERNATE_EXE_PATH and YOCTO_ALTERNATE_LIBDIR handling.
* Delegate all arguments directly to the native llvm-config.
Update rust and mesa recipes to replace the placeholder with the native llvm-config path during target and nativesdk builds.
Also remove the native llvm-config copy logic and lib/lib64 symlink workarounds, relying instead on explicit native tool resolution.
--- ...unwind.pc.in-and-llvm-config-scripts.patch | 52 +++---------------- meta/recipes-devtools/rust/rust_1.96.0.bb | 51 +++++------------- meta/recipes-graphics/mesa/mesa.inc | 16 ++++++ 3 files changed, 38 insertions(+), 81 deletions(-)
meta/recipes-devtools/clang/clang/0026-llvm-Add-libunwind.pc.in-and-llvm-config-scripts.patch +8 -44
@@ -8,6 +8,7 @@ These are added by OE project Upstream-Status: Inappropriate [ OE-Specific ] Signed-off-by: Khem Raj <[email protected]> +Signed-off-by: Deepesh Varatharajan <[email protected]> --- libunwind/libunwind.pc.in | 9 ++++++ llvm/tools/llvm-config/llvm-config | 52 ++++++++++++++++++++++++++++++
@@ -35,56 +36,19 @@ new file mode 100644 index 000000000000..6a0dd54b8eab --- /dev/null +++ b/llvm/tools/llvm-config/llvm-config -@@ -0,0 +1,52 @@ +@@ -0,0 +1,15 @@ +#!/bin/bash +# -+# Wrapper script for llvm-config. Supplies the right environment variables -+# for the target and delegates to the native llvm-config for anything else. This -+# is needed because arguments like --ldflags, --cxxflags, etc. are set by the -+# native compile rather than the target compile. ++# The llvm-config wrapper will act as a pure pass-through to the native llvm-config ++# while preserving Yocto-specific environment variables used for alternate executable ++# and library path resolution. +# +SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" -+NEXT_LLVM_CONFIG="$(which -a llvm-config | sed -n 2p)" ++NEXT_LLVM_CONFIG="@LLVM_CONFIG_PATH@" +export YOCTO_ALTERNATE_EXE_PATH="${YOCTO_ALTERNATE_EXE_PATH:="$(readlink -f "$SCRIPT_DIR/../llvm-config")"}" -+if [ -n "$( echo $base_libdir | sed -n '/lib64/p')" ]; then ++if [ -d "$(readlink -f "$SCRIPT_DIR/../../lib64")" ]; then + export YOCTO_ALTERNATE_LIBDIR="${YOCTO_ALTERNATE_LIBDIR:="/lib64"}" +else + export YOCTO_ALTERNATE_LIBDIR="${YOCTO_ALTERNATE_LIBDIR:="/lib"}" +fi -+if [[ $# == 0 ]]; then -+ exec "$NEXT_LLVM_CONFIG" -+fi -+ -+remain="" -+output="" -+for arg in "$@"; do -+ case "$arg" in -+ --cppflags) -+ output="${output} ${CPPFLAGS}" -+ ;; -+ --cflags) -+ output="${output} ${CFLAGS}" -+ ;; -+ --cxxflags) -+ output="${output} ${CXXFLAGS}" -+ ;; -+ --ldflags) -+ output="${output} ${LDFLAGS}" -+ ;; -+ --shared-mode) -+ output="${output} shared" -+ ;; -+ --link-shared) -+ break -+ ;; -+ *) -+ remain="${remain} ${arg}" -+ ;; -+ esac -+done -+ -+if [ "${remain}" != "" ]; then -+ output="${output} "$("$NEXT_LLVM_CONFIG" ${remain}) -+fi -+ -+echo "${output}" ++exec "$NEXT_LLVM_CONFIG" "$@"
meta/recipes-devtools/rust/rust_1.96.0.bb +14 -37
72 lines not on this page · raw message
meta/recipes-graphics/mesa/mesa.inc +16 -0
@@ -51,6 +51,22 @@ ANY_OF_DISTRO_FEATURES = "opencl opengl vulkan" PLATFORMS ??= "${@bb.utils.filter('PACKAGECONFIG', 'x11 wayland', d)}" +replace_llvm_config_path() { + if [ -f "${STAGING_BINDIR_CROSS}/llvm-config" ]; then + sed -i \ + 's#@LLVM_CONFIG_PATH@#${STAGING_BINDIR_NATIVE}/llvm-config#g' \ + ${STAGING_BINDIR_CROSS}/llvm-config + fi +} + +do_configure:prepend:class-target() { + replace_llvm_config_path +} + +do_configure:prepend:class-nativesdk() { + replace_llvm_config_path +} + # set the MESA_BUILD_TYPE to either 'release' (default) or 'debug' # by default the upstream mesa sources build a debug release # here we assume the user will want a release build by default
Signature · 1 line
2.51.0
Hello Everyone,
The patch has been tested on the following architectures:
x86-64
x86
arm64
arm
riscv64
The following recipes were successfully built and validated:
rust
clang
mesa
nativesdk-rust
nativesdk-clang
nativesdk-mesa
Additionally, with multilib enabled, rust, clang, and mesa were tested successfully on x86-64.
Regards,
Deepesh
Quoted 34 lines · On Wed, 2026-06-10 at 04:26 -0700, [email protected] wrote:
From: Deepesh Varatharajan <[email protected]>
Replace PATH-based llvm-config discovery with explicit sysroot-native resolution and simplify the target llvm-config wrapper to act as a pure pass-through while preserving Yocto alternate path handling.
The previous implementation relied on:
*
which -a llvm-config | sed -n 2p
which is unreliable in cross-build environments because it only searches executables present in $PATH. Native sysroot tools (e.g. recipe-sysroot-native llvm-config) are not guaranteed to be exposed via PATH, so they may not be discovered at all.*
echo $base_libdir | sed -n '/lib64/p'
which depends on a BitBake variable that may be empty or unset in certain build contexts, leading to incorrect libdir selection.Update the wrapper to:
* Use an @LLVM_CONFIG_PATH@ placeholder that is replaced during the build with the appropriate native llvm-config path.
* Detect libdir using filesystem inspection rather than variable parsing.
* PreserveYOCTO_ALTERNATE_EXE_PATHandYOCTO_ALTERNATE_LIBDIRhandling.
* Delegate all arguments directly to the native llvm-config.Update rust and mesa recipes to replace the placeholder with the native llvm-config path during target and nativesdk builds.
Also remove the native llvm-config copy logic and lib/lib64 symlink workarounds, relying instead on explicit native tool resolution.
Quoted 6 lines
Signed-off-by Deepesh Varatharajan <[email protected]>---
...unwind.pc.in-and-llvm-config-scripts.patch | 52 +++---------------- meta/recipes-devtools/rust/rust_1.96.0.bb | 51 +++++------------- meta/recipes-graphics/mesa/mesa.inc | 16 ++++++3 files changed, 38 insertions(+), 81 deletions(-)
Thanks, this looks better in testing but we did see:
https://autobuilder.yoctoproject.org/valkyrie/#/builders/42/builds/3864
which mentions:
"/srv/pokybuild/yocto-worker/qemuarm-tc/build/build-st-3903846/tmp/work/cortexa15t2hf-neon-poky-linux-gnueabi/rust/1.96.0/recipe-sysroot/usr/bin/crossscripts/llvm-config: line 15: exec: @LLVM_CONFIG_PATH@: not found"
The rest of the build is ongoing.
Cheers,
Richard