commit:     3bc0eebf391b1811343f454314c82402ebc6b38c
Author:     Alfred Persson Forsberg <cat <AT> catcream <DOT> org>
AuthorDate: Tue Aug  1 22:33:30 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Aug 22 18:03:37 2023 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=3bc0eebf

sys-libs/compiler-rt: Support LLVM/Clang crossdev

This adds functionality to cross compile compiler-rt for a target
architecture. Needed for LLVM/Clang crossdev.

Thanks wikky for help!

Signed-off-by: Alfred Persson Forsberg <cat <AT> catcream.org>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 sys-libs/compiler-rt/compiler-rt-16.0.6.ebuild     | 36 +++++++++++++++++++---
 .../compiler-rt/compiler-rt-17.0.0.9999.ebuild     | 36 +++++++++++++++++++---
 sys-libs/compiler-rt/compiler-rt-17.0.0_rc1.ebuild | 36 +++++++++++++++++++---
 sys-libs/compiler-rt/compiler-rt-17.0.0_rc2.ebuild | 36 +++++++++++++++++++---
 .../compiler-rt/compiler-rt-18.0.0.9999.ebuild     | 36 +++++++++++++++++++---
 .../compiler-rt-18.0.0_pre20230803.ebuild          | 36 +++++++++++++++++++---
 .../compiler-rt-18.0.0_pre20230810.ebuild          | 36 +++++++++++++++++++---
 .../compiler-rt-18.0.0_pre20230820.ebuild          | 36 +++++++++++++++++++---
 8 files changed, 256 insertions(+), 32 deletions(-)

diff --git a/sys-libs/compiler-rt/compiler-rt-16.0.6.ebuild 
b/sys-libs/compiler-rt/compiler-rt-16.0.6.ebuild
index 50726932b7b2..855c52056bcb 100644
--- a/sys-libs/compiler-rt/compiler-rt-16.0.6.ebuild
+++ b/sys-libs/compiler-rt/compiler-rt-16.0.6.ebuild
@@ -4,7 +4,7 @@
 EAPI=8
 
 PYTHON_COMPAT=( python3_{10..12} )
-inherit cmake flag-o-matic llvm llvm.org python-any-r1 toolchain-funcs
+inherit cmake crossdev flag-o-matic llvm llvm.org python-any-r1 toolchain-funcs
 
 DESCRIPTION="Compiler runtime library for clang (built-in part)"
 HOMEPAGE="https://llvm.org/";
@@ -52,10 +52,18 @@ pkg_setup() {
        if [[ ${CHOST} != *-darwin* ]] || has_version sys-devel/llvm; then
                LLVM_MAX_SLOT=${LLVM_MAJOR} llvm_pkg_setup
        fi
+
+       if target_is_not_host || tc-is-cross-compiler ; then
+               # strips vars like CFLAGS="-march=x86_64-v3" for non-x86 
architectures
+               CHOST=${CTARGET} strip-unsupported-flags
+               # overrides host docs otherwise
+               DOCS=()
+       fi
        python-any-r1_pkg_setup
 }
 
 test_compiler() {
+       target_is_not_host && return
        $(tc-getCC) ${CFLAGS} ${LDFLAGS} "${@}" -o /dev/null -x c - \
                <<<'int main() { return 0; }' &>/dev/null
 }
@@ -67,7 +75,7 @@ src_configure() {
        # pre-set since we need to pass it to cmake
        BUILD_DIR=${WORKDIR}/${P}_build
 
-       if use clang; then
+       if use clang && ! is_crosspkg; then
                # Only do this conditionally to allow overriding with
                # e.g. CC=clang-13 in case of breakage
                if ! tc-is-clang ; then
@@ -78,7 +86,7 @@ src_configure() {
                strip-unsupported-flags
        fi
 
-       if ! test_compiler; then
+       if ! is_crosspkg && ! test_compiler ; then
                local nolib_flags=( -nodefaultlibs -lc )
 
                if test_compiler "${nolib_flags[@]}"; then
@@ -108,13 +116,33 @@ src_configure() {
                -DPython3_EXECUTABLE="${PYTHON}"
        )
 
-       if use amd64; then
+       if use amd64 && ! target_is_not_host; then
                mycmakeargs+=(
                        -DCAN_TARGET_i386=$(usex abi_x86_32)
                        -DCAN_TARGET_x86_64=$(usex abi_x86_64)
                )
        fi
 
+       if is_crosspkg; then
+               # Needed to target built libc headers
+               export CFLAGS="${CFLAGS} -isystem /usr/${CTARGET}/usr/include"
+               mycmakeargs+=(
+                       # Without this, the compiler will compile a test program
+                       # and fail due to no builtins.
+                       -DCMAKE_C_COMPILER_WORKS=1
+                       -DCMAKE_CXX_COMPILER_WORKS=1
+
+                       # Without this, compiler-rt install location is not 
unique
+                       # to target triples, only to architecture.
+                       # Needed if you want to target multiple libcs for one 
arch.
+                       -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
+
+                       -DCMAKE_ASM_COMPILER_TARGET="${CTARGET}"
+                       -DCMAKE_C_COMPILER_TARGET="${CTARGET}"
+                       -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
+               )
+       fi
+
        if use prefix && [[ "${CHOST}" == *-darwin* ]] ; then
                mycmakeargs+=(
                        # setting -isysroot is disabled with 
compiler-rt-prefix-paths.patch

diff --git a/sys-libs/compiler-rt/compiler-rt-17.0.0.9999.ebuild 
b/sys-libs/compiler-rt/compiler-rt-17.0.0.9999.ebuild
index f31c17f1962a..f5ece0834a5e 100644
--- a/sys-libs/compiler-rt/compiler-rt-17.0.0.9999.ebuild
+++ b/sys-libs/compiler-rt/compiler-rt-17.0.0.9999.ebuild
@@ -4,7 +4,7 @@
 EAPI=8
 
 PYTHON_COMPAT=( python3_{10..12} )
-inherit cmake flag-o-matic llvm llvm.org python-any-r1 toolchain-funcs
+inherit cmake crossdev flag-o-matic llvm llvm.org python-any-r1 toolchain-funcs
 
 DESCRIPTION="Compiler runtime library for clang (built-in part)"
 HOMEPAGE="https://llvm.org/";
@@ -52,10 +52,18 @@ pkg_setup() {
        if [[ ${CHOST} != *-darwin* ]] || has_version sys-devel/llvm; then
                LLVM_MAX_SLOT=${LLVM_MAJOR} llvm_pkg_setup
        fi
+
+       if target_is_not_host || tc-is-cross-compiler ; then
+               # strips vars like CFLAGS="-march=x86_64-v3" for non-x86 
architectures
+               CHOST=${CTARGET} strip-unsupported-flags
+               # overrides host docs otherwise
+               DOCS=()
+       fi
        python-any-r1_pkg_setup
 }
 
 test_compiler() {
+       target_is_not_host && return
        $(tc-getCC) ${CFLAGS} ${LDFLAGS} "${@}" -o /dev/null -x c - \
                <<<'int main() { return 0; }' &>/dev/null
 }
@@ -67,7 +75,7 @@ src_configure() {
        # pre-set since we need to pass it to cmake
        BUILD_DIR=${WORKDIR}/${P}_build
 
-       if use clang; then
+       if use clang && ! is_crosspkg; then
                # Only do this conditionally to allow overriding with
                # e.g. CC=clang-13 in case of breakage
                if ! tc-is-clang ; then
@@ -78,7 +86,7 @@ src_configure() {
                strip-unsupported-flags
        fi
 
-       if ! test_compiler; then
+       if ! is_crosspkg && ! test_compiler ; then
                local nolib_flags=( -nodefaultlibs -lc )
 
                if test_compiler "${nolib_flags[@]}"; then
@@ -108,13 +116,33 @@ src_configure() {
                -DPython3_EXECUTABLE="${PYTHON}"
        )
 
-       if use amd64; then
+       if use amd64 && ! target_is_not_host; then
                mycmakeargs+=(
                        -DCAN_TARGET_i386=$(usex abi_x86_32)
                        -DCAN_TARGET_x86_64=$(usex abi_x86_64)
                )
        fi
 
+       if is_crosspkg; then
+               # Needed to target built libc headers
+               export CFLAGS="${CFLAGS} -isystem /usr/${CTARGET}/usr/include"
+               mycmakeargs+=(
+                       # Without this, the compiler will compile a test program
+                       # and fail due to no builtins.
+                       -DCMAKE_C_COMPILER_WORKS=1
+                       -DCMAKE_CXX_COMPILER_WORKS=1
+
+                       # Without this, compiler-rt install location is not 
unique
+                       # to target triples, only to architecture.
+                       # Needed if you want to target multiple libcs for one 
arch.
+                       -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
+
+                       -DCMAKE_ASM_COMPILER_TARGET="${CTARGET}"
+                       -DCMAKE_C_COMPILER_TARGET="${CTARGET}"
+                       -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
+               )
+       fi
+
        if use prefix && [[ "${CHOST}" == *-darwin* ]] ; then
                mycmakeargs+=(
                        # setting -isysroot is disabled with 
compiler-rt-prefix-paths.patch

diff --git a/sys-libs/compiler-rt/compiler-rt-17.0.0_rc1.ebuild 
b/sys-libs/compiler-rt/compiler-rt-17.0.0_rc1.ebuild
index f31c17f1962a..f5ece0834a5e 100644
--- a/sys-libs/compiler-rt/compiler-rt-17.0.0_rc1.ebuild
+++ b/sys-libs/compiler-rt/compiler-rt-17.0.0_rc1.ebuild
@@ -4,7 +4,7 @@
 EAPI=8
 
 PYTHON_COMPAT=( python3_{10..12} )
-inherit cmake flag-o-matic llvm llvm.org python-any-r1 toolchain-funcs
+inherit cmake crossdev flag-o-matic llvm llvm.org python-any-r1 toolchain-funcs
 
 DESCRIPTION="Compiler runtime library for clang (built-in part)"
 HOMEPAGE="https://llvm.org/";
@@ -52,10 +52,18 @@ pkg_setup() {
        if [[ ${CHOST} != *-darwin* ]] || has_version sys-devel/llvm; then
                LLVM_MAX_SLOT=${LLVM_MAJOR} llvm_pkg_setup
        fi
+
+       if target_is_not_host || tc-is-cross-compiler ; then
+               # strips vars like CFLAGS="-march=x86_64-v3" for non-x86 
architectures
+               CHOST=${CTARGET} strip-unsupported-flags
+               # overrides host docs otherwise
+               DOCS=()
+       fi
        python-any-r1_pkg_setup
 }
 
 test_compiler() {
+       target_is_not_host && return
        $(tc-getCC) ${CFLAGS} ${LDFLAGS} "${@}" -o /dev/null -x c - \
                <<<'int main() { return 0; }' &>/dev/null
 }
@@ -67,7 +75,7 @@ src_configure() {
        # pre-set since we need to pass it to cmake
        BUILD_DIR=${WORKDIR}/${P}_build
 
-       if use clang; then
+       if use clang && ! is_crosspkg; then
                # Only do this conditionally to allow overriding with
                # e.g. CC=clang-13 in case of breakage
                if ! tc-is-clang ; then
@@ -78,7 +86,7 @@ src_configure() {
                strip-unsupported-flags
        fi
 
-       if ! test_compiler; then
+       if ! is_crosspkg && ! test_compiler ; then
                local nolib_flags=( -nodefaultlibs -lc )
 
                if test_compiler "${nolib_flags[@]}"; then
@@ -108,13 +116,33 @@ src_configure() {
                -DPython3_EXECUTABLE="${PYTHON}"
        )
 
-       if use amd64; then
+       if use amd64 && ! target_is_not_host; then
                mycmakeargs+=(
                        -DCAN_TARGET_i386=$(usex abi_x86_32)
                        -DCAN_TARGET_x86_64=$(usex abi_x86_64)
                )
        fi
 
+       if is_crosspkg; then
+               # Needed to target built libc headers
+               export CFLAGS="${CFLAGS} -isystem /usr/${CTARGET}/usr/include"
+               mycmakeargs+=(
+                       # Without this, the compiler will compile a test program
+                       # and fail due to no builtins.
+                       -DCMAKE_C_COMPILER_WORKS=1
+                       -DCMAKE_CXX_COMPILER_WORKS=1
+
+                       # Without this, compiler-rt install location is not 
unique
+                       # to target triples, only to architecture.
+                       # Needed if you want to target multiple libcs for one 
arch.
+                       -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
+
+                       -DCMAKE_ASM_COMPILER_TARGET="${CTARGET}"
+                       -DCMAKE_C_COMPILER_TARGET="${CTARGET}"
+                       -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
+               )
+       fi
+
        if use prefix && [[ "${CHOST}" == *-darwin* ]] ; then
                mycmakeargs+=(
                        # setting -isysroot is disabled with 
compiler-rt-prefix-paths.patch

diff --git a/sys-libs/compiler-rt/compiler-rt-17.0.0_rc2.ebuild 
b/sys-libs/compiler-rt/compiler-rt-17.0.0_rc2.ebuild
index f31c17f1962a..f5ece0834a5e 100644
--- a/sys-libs/compiler-rt/compiler-rt-17.0.0_rc2.ebuild
+++ b/sys-libs/compiler-rt/compiler-rt-17.0.0_rc2.ebuild
@@ -4,7 +4,7 @@
 EAPI=8
 
 PYTHON_COMPAT=( python3_{10..12} )
-inherit cmake flag-o-matic llvm llvm.org python-any-r1 toolchain-funcs
+inherit cmake crossdev flag-o-matic llvm llvm.org python-any-r1 toolchain-funcs
 
 DESCRIPTION="Compiler runtime library for clang (built-in part)"
 HOMEPAGE="https://llvm.org/";
@@ -52,10 +52,18 @@ pkg_setup() {
        if [[ ${CHOST} != *-darwin* ]] || has_version sys-devel/llvm; then
                LLVM_MAX_SLOT=${LLVM_MAJOR} llvm_pkg_setup
        fi
+
+       if target_is_not_host || tc-is-cross-compiler ; then
+               # strips vars like CFLAGS="-march=x86_64-v3" for non-x86 
architectures
+               CHOST=${CTARGET} strip-unsupported-flags
+               # overrides host docs otherwise
+               DOCS=()
+       fi
        python-any-r1_pkg_setup
 }
 
 test_compiler() {
+       target_is_not_host && return
        $(tc-getCC) ${CFLAGS} ${LDFLAGS} "${@}" -o /dev/null -x c - \
                <<<'int main() { return 0; }' &>/dev/null
 }
@@ -67,7 +75,7 @@ src_configure() {
        # pre-set since we need to pass it to cmake
        BUILD_DIR=${WORKDIR}/${P}_build
 
-       if use clang; then
+       if use clang && ! is_crosspkg; then
                # Only do this conditionally to allow overriding with
                # e.g. CC=clang-13 in case of breakage
                if ! tc-is-clang ; then
@@ -78,7 +86,7 @@ src_configure() {
                strip-unsupported-flags
        fi
 
-       if ! test_compiler; then
+       if ! is_crosspkg && ! test_compiler ; then
                local nolib_flags=( -nodefaultlibs -lc )
 
                if test_compiler "${nolib_flags[@]}"; then
@@ -108,13 +116,33 @@ src_configure() {
                -DPython3_EXECUTABLE="${PYTHON}"
        )
 
-       if use amd64; then
+       if use amd64 && ! target_is_not_host; then
                mycmakeargs+=(
                        -DCAN_TARGET_i386=$(usex abi_x86_32)
                        -DCAN_TARGET_x86_64=$(usex abi_x86_64)
                )
        fi
 
+       if is_crosspkg; then
+               # Needed to target built libc headers
+               export CFLAGS="${CFLAGS} -isystem /usr/${CTARGET}/usr/include"
+               mycmakeargs+=(
+                       # Without this, the compiler will compile a test program
+                       # and fail due to no builtins.
+                       -DCMAKE_C_COMPILER_WORKS=1
+                       -DCMAKE_CXX_COMPILER_WORKS=1
+
+                       # Without this, compiler-rt install location is not 
unique
+                       # to target triples, only to architecture.
+                       # Needed if you want to target multiple libcs for one 
arch.
+                       -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
+
+                       -DCMAKE_ASM_COMPILER_TARGET="${CTARGET}"
+                       -DCMAKE_C_COMPILER_TARGET="${CTARGET}"
+                       -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
+               )
+       fi
+
        if use prefix && [[ "${CHOST}" == *-darwin* ]] ; then
                mycmakeargs+=(
                        # setting -isysroot is disabled with 
compiler-rt-prefix-paths.patch

diff --git a/sys-libs/compiler-rt/compiler-rt-18.0.0.9999.ebuild 
b/sys-libs/compiler-rt/compiler-rt-18.0.0.9999.ebuild
index f31c17f1962a..f5ece0834a5e 100644
--- a/sys-libs/compiler-rt/compiler-rt-18.0.0.9999.ebuild
+++ b/sys-libs/compiler-rt/compiler-rt-18.0.0.9999.ebuild
@@ -4,7 +4,7 @@
 EAPI=8
 
 PYTHON_COMPAT=( python3_{10..12} )
-inherit cmake flag-o-matic llvm llvm.org python-any-r1 toolchain-funcs
+inherit cmake crossdev flag-o-matic llvm llvm.org python-any-r1 toolchain-funcs
 
 DESCRIPTION="Compiler runtime library for clang (built-in part)"
 HOMEPAGE="https://llvm.org/";
@@ -52,10 +52,18 @@ pkg_setup() {
        if [[ ${CHOST} != *-darwin* ]] || has_version sys-devel/llvm; then
                LLVM_MAX_SLOT=${LLVM_MAJOR} llvm_pkg_setup
        fi
+
+       if target_is_not_host || tc-is-cross-compiler ; then
+               # strips vars like CFLAGS="-march=x86_64-v3" for non-x86 
architectures
+               CHOST=${CTARGET} strip-unsupported-flags
+               # overrides host docs otherwise
+               DOCS=()
+       fi
        python-any-r1_pkg_setup
 }
 
 test_compiler() {
+       target_is_not_host && return
        $(tc-getCC) ${CFLAGS} ${LDFLAGS} "${@}" -o /dev/null -x c - \
                <<<'int main() { return 0; }' &>/dev/null
 }
@@ -67,7 +75,7 @@ src_configure() {
        # pre-set since we need to pass it to cmake
        BUILD_DIR=${WORKDIR}/${P}_build
 
-       if use clang; then
+       if use clang && ! is_crosspkg; then
                # Only do this conditionally to allow overriding with
                # e.g. CC=clang-13 in case of breakage
                if ! tc-is-clang ; then
@@ -78,7 +86,7 @@ src_configure() {
                strip-unsupported-flags
        fi
 
-       if ! test_compiler; then
+       if ! is_crosspkg && ! test_compiler ; then
                local nolib_flags=( -nodefaultlibs -lc )
 
                if test_compiler "${nolib_flags[@]}"; then
@@ -108,13 +116,33 @@ src_configure() {
                -DPython3_EXECUTABLE="${PYTHON}"
        )
 
-       if use amd64; then
+       if use amd64 && ! target_is_not_host; then
                mycmakeargs+=(
                        -DCAN_TARGET_i386=$(usex abi_x86_32)
                        -DCAN_TARGET_x86_64=$(usex abi_x86_64)
                )
        fi
 
+       if is_crosspkg; then
+               # Needed to target built libc headers
+               export CFLAGS="${CFLAGS} -isystem /usr/${CTARGET}/usr/include"
+               mycmakeargs+=(
+                       # Without this, the compiler will compile a test program
+                       # and fail due to no builtins.
+                       -DCMAKE_C_COMPILER_WORKS=1
+                       -DCMAKE_CXX_COMPILER_WORKS=1
+
+                       # Without this, compiler-rt install location is not 
unique
+                       # to target triples, only to architecture.
+                       # Needed if you want to target multiple libcs for one 
arch.
+                       -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
+
+                       -DCMAKE_ASM_COMPILER_TARGET="${CTARGET}"
+                       -DCMAKE_C_COMPILER_TARGET="${CTARGET}"
+                       -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
+               )
+       fi
+
        if use prefix && [[ "${CHOST}" == *-darwin* ]] ; then
                mycmakeargs+=(
                        # setting -isysroot is disabled with 
compiler-rt-prefix-paths.patch

diff --git a/sys-libs/compiler-rt/compiler-rt-18.0.0_pre20230803.ebuild 
b/sys-libs/compiler-rt/compiler-rt-18.0.0_pre20230803.ebuild
index f31c17f1962a..f5ece0834a5e 100644
--- a/sys-libs/compiler-rt/compiler-rt-18.0.0_pre20230803.ebuild
+++ b/sys-libs/compiler-rt/compiler-rt-18.0.0_pre20230803.ebuild
@@ -4,7 +4,7 @@
 EAPI=8
 
 PYTHON_COMPAT=( python3_{10..12} )
-inherit cmake flag-o-matic llvm llvm.org python-any-r1 toolchain-funcs
+inherit cmake crossdev flag-o-matic llvm llvm.org python-any-r1 toolchain-funcs
 
 DESCRIPTION="Compiler runtime library for clang (built-in part)"
 HOMEPAGE="https://llvm.org/";
@@ -52,10 +52,18 @@ pkg_setup() {
        if [[ ${CHOST} != *-darwin* ]] || has_version sys-devel/llvm; then
                LLVM_MAX_SLOT=${LLVM_MAJOR} llvm_pkg_setup
        fi
+
+       if target_is_not_host || tc-is-cross-compiler ; then
+               # strips vars like CFLAGS="-march=x86_64-v3" for non-x86 
architectures
+               CHOST=${CTARGET} strip-unsupported-flags
+               # overrides host docs otherwise
+               DOCS=()
+       fi
        python-any-r1_pkg_setup
 }
 
 test_compiler() {
+       target_is_not_host && return
        $(tc-getCC) ${CFLAGS} ${LDFLAGS} "${@}" -o /dev/null -x c - \
                <<<'int main() { return 0; }' &>/dev/null
 }
@@ -67,7 +75,7 @@ src_configure() {
        # pre-set since we need to pass it to cmake
        BUILD_DIR=${WORKDIR}/${P}_build
 
-       if use clang; then
+       if use clang && ! is_crosspkg; then
                # Only do this conditionally to allow overriding with
                # e.g. CC=clang-13 in case of breakage
                if ! tc-is-clang ; then
@@ -78,7 +86,7 @@ src_configure() {
                strip-unsupported-flags
        fi
 
-       if ! test_compiler; then
+       if ! is_crosspkg && ! test_compiler ; then
                local nolib_flags=( -nodefaultlibs -lc )
 
                if test_compiler "${nolib_flags[@]}"; then
@@ -108,13 +116,33 @@ src_configure() {
                -DPython3_EXECUTABLE="${PYTHON}"
        )
 
-       if use amd64; then
+       if use amd64 && ! target_is_not_host; then
                mycmakeargs+=(
                        -DCAN_TARGET_i386=$(usex abi_x86_32)
                        -DCAN_TARGET_x86_64=$(usex abi_x86_64)
                )
        fi
 
+       if is_crosspkg; then
+               # Needed to target built libc headers
+               export CFLAGS="${CFLAGS} -isystem /usr/${CTARGET}/usr/include"
+               mycmakeargs+=(
+                       # Without this, the compiler will compile a test program
+                       # and fail due to no builtins.
+                       -DCMAKE_C_COMPILER_WORKS=1
+                       -DCMAKE_CXX_COMPILER_WORKS=1
+
+                       # Without this, compiler-rt install location is not 
unique
+                       # to target triples, only to architecture.
+                       # Needed if you want to target multiple libcs for one 
arch.
+                       -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
+
+                       -DCMAKE_ASM_COMPILER_TARGET="${CTARGET}"
+                       -DCMAKE_C_COMPILER_TARGET="${CTARGET}"
+                       -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
+               )
+       fi
+
        if use prefix && [[ "${CHOST}" == *-darwin* ]] ; then
                mycmakeargs+=(
                        # setting -isysroot is disabled with 
compiler-rt-prefix-paths.patch

diff --git a/sys-libs/compiler-rt/compiler-rt-18.0.0_pre20230810.ebuild 
b/sys-libs/compiler-rt/compiler-rt-18.0.0_pre20230810.ebuild
index f31c17f1962a..f5ece0834a5e 100644
--- a/sys-libs/compiler-rt/compiler-rt-18.0.0_pre20230810.ebuild
+++ b/sys-libs/compiler-rt/compiler-rt-18.0.0_pre20230810.ebuild
@@ -4,7 +4,7 @@
 EAPI=8
 
 PYTHON_COMPAT=( python3_{10..12} )
-inherit cmake flag-o-matic llvm llvm.org python-any-r1 toolchain-funcs
+inherit cmake crossdev flag-o-matic llvm llvm.org python-any-r1 toolchain-funcs
 
 DESCRIPTION="Compiler runtime library for clang (built-in part)"
 HOMEPAGE="https://llvm.org/";
@@ -52,10 +52,18 @@ pkg_setup() {
        if [[ ${CHOST} != *-darwin* ]] || has_version sys-devel/llvm; then
                LLVM_MAX_SLOT=${LLVM_MAJOR} llvm_pkg_setup
        fi
+
+       if target_is_not_host || tc-is-cross-compiler ; then
+               # strips vars like CFLAGS="-march=x86_64-v3" for non-x86 
architectures
+               CHOST=${CTARGET} strip-unsupported-flags
+               # overrides host docs otherwise
+               DOCS=()
+       fi
        python-any-r1_pkg_setup
 }
 
 test_compiler() {
+       target_is_not_host && return
        $(tc-getCC) ${CFLAGS} ${LDFLAGS} "${@}" -o /dev/null -x c - \
                <<<'int main() { return 0; }' &>/dev/null
 }
@@ -67,7 +75,7 @@ src_configure() {
        # pre-set since we need to pass it to cmake
        BUILD_DIR=${WORKDIR}/${P}_build
 
-       if use clang; then
+       if use clang && ! is_crosspkg; then
                # Only do this conditionally to allow overriding with
                # e.g. CC=clang-13 in case of breakage
                if ! tc-is-clang ; then
@@ -78,7 +86,7 @@ src_configure() {
                strip-unsupported-flags
        fi
 
-       if ! test_compiler; then
+       if ! is_crosspkg && ! test_compiler ; then
                local nolib_flags=( -nodefaultlibs -lc )
 
                if test_compiler "${nolib_flags[@]}"; then
@@ -108,13 +116,33 @@ src_configure() {
                -DPython3_EXECUTABLE="${PYTHON}"
        )
 
-       if use amd64; then
+       if use amd64 && ! target_is_not_host; then
                mycmakeargs+=(
                        -DCAN_TARGET_i386=$(usex abi_x86_32)
                        -DCAN_TARGET_x86_64=$(usex abi_x86_64)
                )
        fi
 
+       if is_crosspkg; then
+               # Needed to target built libc headers
+               export CFLAGS="${CFLAGS} -isystem /usr/${CTARGET}/usr/include"
+               mycmakeargs+=(
+                       # Without this, the compiler will compile a test program
+                       # and fail due to no builtins.
+                       -DCMAKE_C_COMPILER_WORKS=1
+                       -DCMAKE_CXX_COMPILER_WORKS=1
+
+                       # Without this, compiler-rt install location is not 
unique
+                       # to target triples, only to architecture.
+                       # Needed if you want to target multiple libcs for one 
arch.
+                       -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
+
+                       -DCMAKE_ASM_COMPILER_TARGET="${CTARGET}"
+                       -DCMAKE_C_COMPILER_TARGET="${CTARGET}"
+                       -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
+               )
+       fi
+
        if use prefix && [[ "${CHOST}" == *-darwin* ]] ; then
                mycmakeargs+=(
                        # setting -isysroot is disabled with 
compiler-rt-prefix-paths.patch

diff --git a/sys-libs/compiler-rt/compiler-rt-18.0.0_pre20230820.ebuild 
b/sys-libs/compiler-rt/compiler-rt-18.0.0_pre20230820.ebuild
index f31c17f1962a..f5ece0834a5e 100644
--- a/sys-libs/compiler-rt/compiler-rt-18.0.0_pre20230820.ebuild
+++ b/sys-libs/compiler-rt/compiler-rt-18.0.0_pre20230820.ebuild
@@ -4,7 +4,7 @@
 EAPI=8
 
 PYTHON_COMPAT=( python3_{10..12} )
-inherit cmake flag-o-matic llvm llvm.org python-any-r1 toolchain-funcs
+inherit cmake crossdev flag-o-matic llvm llvm.org python-any-r1 toolchain-funcs
 
 DESCRIPTION="Compiler runtime library for clang (built-in part)"
 HOMEPAGE="https://llvm.org/";
@@ -52,10 +52,18 @@ pkg_setup() {
        if [[ ${CHOST} != *-darwin* ]] || has_version sys-devel/llvm; then
                LLVM_MAX_SLOT=${LLVM_MAJOR} llvm_pkg_setup
        fi
+
+       if target_is_not_host || tc-is-cross-compiler ; then
+               # strips vars like CFLAGS="-march=x86_64-v3" for non-x86 
architectures
+               CHOST=${CTARGET} strip-unsupported-flags
+               # overrides host docs otherwise
+               DOCS=()
+       fi
        python-any-r1_pkg_setup
 }
 
 test_compiler() {
+       target_is_not_host && return
        $(tc-getCC) ${CFLAGS} ${LDFLAGS} "${@}" -o /dev/null -x c - \
                <<<'int main() { return 0; }' &>/dev/null
 }
@@ -67,7 +75,7 @@ src_configure() {
        # pre-set since we need to pass it to cmake
        BUILD_DIR=${WORKDIR}/${P}_build
 
-       if use clang; then
+       if use clang && ! is_crosspkg; then
                # Only do this conditionally to allow overriding with
                # e.g. CC=clang-13 in case of breakage
                if ! tc-is-clang ; then
@@ -78,7 +86,7 @@ src_configure() {
                strip-unsupported-flags
        fi
 
-       if ! test_compiler; then
+       if ! is_crosspkg && ! test_compiler ; then
                local nolib_flags=( -nodefaultlibs -lc )
 
                if test_compiler "${nolib_flags[@]}"; then
@@ -108,13 +116,33 @@ src_configure() {
                -DPython3_EXECUTABLE="${PYTHON}"
        )
 
-       if use amd64; then
+       if use amd64 && ! target_is_not_host; then
                mycmakeargs+=(
                        -DCAN_TARGET_i386=$(usex abi_x86_32)
                        -DCAN_TARGET_x86_64=$(usex abi_x86_64)
                )
        fi
 
+       if is_crosspkg; then
+               # Needed to target built libc headers
+               export CFLAGS="${CFLAGS} -isystem /usr/${CTARGET}/usr/include"
+               mycmakeargs+=(
+                       # Without this, the compiler will compile a test program
+                       # and fail due to no builtins.
+                       -DCMAKE_C_COMPILER_WORKS=1
+                       -DCMAKE_CXX_COMPILER_WORKS=1
+
+                       # Without this, compiler-rt install location is not 
unique
+                       # to target triples, only to architecture.
+                       # Needed if you want to target multiple libcs for one 
arch.
+                       -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
+
+                       -DCMAKE_ASM_COMPILER_TARGET="${CTARGET}"
+                       -DCMAKE_C_COMPILER_TARGET="${CTARGET}"
+                       -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
+               )
+       fi
+
        if use prefix && [[ "${CHOST}" == *-darwin* ]] ; then
                mycmakeargs+=(
                        # setting -isysroot is disabled with 
compiler-rt-prefix-paths.patch

Reply via email to