public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: Alfred Persson Forsberg <cat@catcream.org>
To: gentoo-dev@lists.gentoo.org
Cc: sam@gentoo.org, llvm@gentoo.org, toolchain@gentoo.org,
	cross@gentoo.org, Alfred Persson Forsberg <cat@catcream.org>
Subject: [gentoo-dev] [PATCH 4/4] sys-libs/compiler-rt: Support LLVM/Clang crossdev
Date: Fri, 11 Aug 2023 05:48:23 +0200	[thread overview]
Message-ID: <20230811034823.34301-6-cat@catcream.org> (raw)
In-Reply-To: <20230811034823.34301-1-cat@catcream.org>

Signed-off-by: Alfred Persson Forsberg <cat@catcream.org>
---
 .../compiler-rt-17.0.0.9999.ebuild            | 36 ++++++++++++++++---
 1 file changed, 32 insertions(+), 4 deletions(-)

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..6075965a0991 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 cross 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 is_crosscompile || 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() {
+	is_crosscompile && 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_llvm; 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_llvm && ! 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 && ! is_crosscompile; then
 		mycmakeargs+=(
 			-DCAN_TARGET_i386=$(usex abi_x86_32)
 			-DCAN_TARGET_x86_64=$(usex abi_x86_64)
 		)
 	fi
 
+	if is_crosspkg_llvm; 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
-- 
2.41.0



      parent reply	other threads:[~2023-08-11  3:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-11  3:48 [gentoo-dev] [PATCH 3/4] kernel-2.eclass: Use cross.eclass for figuring out CTARGET Alfred Persson Forsberg
2023-08-11  3:48 ` [gentoo-dev] [PATCH 0/4] Introducing cross.eclass for Crossdev ebuilds Alfred Persson Forsberg
2023-08-11  3:48 ` [gentoo-dev] [PATCH 1/4] cross.eclass: new eclass Alfred Persson Forsberg
2023-08-11  3:48 ` [gentoo-dev] [PATCH 2/4] sys-libs/musl: Support LLVM/Clang crossdev Alfred Persson Forsberg
2023-08-11  3:48 ` [gentoo-dev] [PATCH 3/4] kernel-2.eclass: Use cross.eclass for figuring out CTARGET Alfred Persson Forsberg
2023-08-11  3:48 ` Alfred Persson Forsberg [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230811034823.34301-6-cat@catcream.org \
    --to=cat@catcream.org \
    --cc=cross@gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    --cc=llvm@gentoo.org \
    --cc=sam@gentoo.org \
    --cc=toolchain@gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox