commit:     fb63c610fc9ae2a48f3c1150f0704e1741dd02c5
Author:     Michal Rostecki <vadorovsky <AT> protonmail <DOT> com>
AuthorDate: Mon Aug  4 11:53:21 2025 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Wed Aug  6 12:29:18 2025 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=fb63c610

llvm-runtimes/libunwind: Support build with cross emerge wrapper

When cross emerge wrapper is used, using `llvm_prepend_path` without
any options, results in prepending the following path:

```
${ESYSROOT}/usr/lib/llvm/${slot}/bin
```

For example:

```
/usr/aarch64-unknown-linux-musl/usr/lib/llvm/19/bin
```

The problem is that cross emerge wrapper uses a cross clang wrapper as
a compiler, e.g. `aarch64-unknown-linux-musl-clang`. However, the file
with such name can be usually found in two places:

* `/usr/lib/llvm/19/bin/aarch64-unknown-linux-musl-clang`, which is
  a clang wrapper that calls the host clang with appropriate
  configuration. We want to call that file.
* 
`/usr/aarch64-unknown-linux-musl/usr/lib/llvm/19/bin/aarch64-unknown-linux-musl-clang`,
  which is an actual aarch64 compiler binary. We cannot execute it on
  x86_64, or other incompatible host.

However, the path added by `llvm_prepend_path` causes resolution of
`aarch64-unknown-linux-musl-clang` to the second path, therefore causing
errors like:

```
/usr/aarch64-unknown-linux-musl/usr/lib/llvm/19/bin/clang: cannot execute 
binary file: Exec format error
```

Solve that by:

* Using `LLVM_ROOT` CMake parameter to point the build to LLVM library
  artifacts.
* Using `llvm_prepend_path` with `-b` argument if we need clang, which
  is the case when either `clang` or `test` USE flags are enabled.

Signed-off-by: Michal Rostecki <vadorovsky <AT> protonmail.com>
Part-of: https://github.com/gentoo/gentoo/pull/39280
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>
Part-of: https://github.com/gentoo/gentoo/pull/39280
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 llvm-runtimes/libunwind/libunwind-19.1.7.ebuild      | 6 +++++-
 llvm-runtimes/libunwind/libunwind-20.1.8.ebuild      | 6 +++++-
 llvm-runtimes/libunwind/libunwind-21.1.0.9999.ebuild | 6 +++++-
 llvm-runtimes/libunwind/libunwind-22.0.0.9999.ebuild | 6 +++++-
 4 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/llvm-runtimes/libunwind/libunwind-19.1.7.ebuild 
b/llvm-runtimes/libunwind/libunwind-19.1.7.ebuild
index 40caf4086be6..ddaa35f281f4 100644
--- a/llvm-runtimes/libunwind/libunwind-19.1.7.ebuild
+++ b/llvm-runtimes/libunwind/libunwind-19.1.7.ebuild
@@ -45,7 +45,9 @@ python_check_deps() {
 }
 
 multilib_src_configure() {
-       llvm_prepend_path "${LLVM_MAJOR}"
+       if use clang; then
+               llvm_prepend_path -b "${LLVM_MAJOR}"
+       fi
 
        local libdir=$(get_libdir)
 
@@ -74,6 +76,8 @@ multilib_src_configure() {
        use debug || append-cppflags -DNDEBUG
 
        local mycmakeargs=(
+               -DLLVM_ROOT="${ESYSROOT}/usr/lib/llvm/${LLVM_MAJOR}"
+
                -DCMAKE_C_COMPILER_TARGET="${CTARGET}"
                -DCMAKE_CXX_COMPILER_TARGET="${CTARGET}"
                -DPython3_EXECUTABLE="${PYTHON}"

diff --git a/llvm-runtimes/libunwind/libunwind-20.1.8.ebuild 
b/llvm-runtimes/libunwind/libunwind-20.1.8.ebuild
index ed7764827321..50b05b965a37 100644
--- a/llvm-runtimes/libunwind/libunwind-20.1.8.ebuild
+++ b/llvm-runtimes/libunwind/libunwind-20.1.8.ebuild
@@ -45,7 +45,9 @@ python_check_deps() {
 }
 
 multilib_src_configure() {
-       llvm_prepend_path "${LLVM_MAJOR}"
+       if use clang; then
+               llvm_prepend_path -b "${LLVM_MAJOR}"
+       fi
 
        local libdir=$(get_libdir)
 
@@ -74,6 +76,8 @@ multilib_src_configure() {
        use debug || append-cppflags -DNDEBUG
 
        local mycmakeargs=(
+               -DLLVM_ROOT="${ESYSROOT}/usr/lib/llvm/${LLVM_MAJOR}"
+
                -DCMAKE_C_COMPILER_TARGET="${CTARGET}"
                -DCMAKE_CXX_COMPILER_TARGET="${CTARGET}"
                -DPython3_EXECUTABLE="${PYTHON}"

diff --git a/llvm-runtimes/libunwind/libunwind-21.1.0.9999.ebuild 
b/llvm-runtimes/libunwind/libunwind-21.1.0.9999.ebuild
index a41965693659..4824e494d9d1 100644
--- a/llvm-runtimes/libunwind/libunwind-21.1.0.9999.ebuild
+++ b/llvm-runtimes/libunwind/libunwind-21.1.0.9999.ebuild
@@ -44,7 +44,9 @@ python_check_deps() {
 }
 
 multilib_src_configure() {
-       llvm_prepend_path "${LLVM_MAJOR}"
+       if use clang; then
+               llvm_prepend_path -b "${LLVM_MAJOR}"
+       fi
 
        local libdir=$(get_libdir)
 
@@ -73,6 +75,8 @@ multilib_src_configure() {
        use debug || append-cppflags -DNDEBUG
 
        local mycmakeargs=(
+               -DLLVM_ROOT="${ESYSROOT}/usr/lib/llvm/${LLVM_MAJOR}"
+
                -DCMAKE_C_COMPILER_TARGET="${CTARGET}"
                -DCMAKE_CXX_COMPILER_TARGET="${CTARGET}"
                -DPython3_EXECUTABLE="${PYTHON}"

diff --git a/llvm-runtimes/libunwind/libunwind-22.0.0.9999.ebuild 
b/llvm-runtimes/libunwind/libunwind-22.0.0.9999.ebuild
index a41965693659..4824e494d9d1 100644
--- a/llvm-runtimes/libunwind/libunwind-22.0.0.9999.ebuild
+++ b/llvm-runtimes/libunwind/libunwind-22.0.0.9999.ebuild
@@ -44,7 +44,9 @@ python_check_deps() {
 }
 
 multilib_src_configure() {
-       llvm_prepend_path "${LLVM_MAJOR}"
+       if use clang; then
+               llvm_prepend_path -b "${LLVM_MAJOR}"
+       fi
 
        local libdir=$(get_libdir)
 
@@ -73,6 +75,8 @@ multilib_src_configure() {
        use debug || append-cppflags -DNDEBUG
 
        local mycmakeargs=(
+               -DLLVM_ROOT="${ESYSROOT}/usr/lib/llvm/${LLVM_MAJOR}"
+
                -DCMAKE_C_COMPILER_TARGET="${CTARGET}"
                -DCMAKE_CXX_COMPILER_TARGET="${CTARGET}"
                -DPython3_EXECUTABLE="${PYTHON}"

Reply via email to