From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-1677328-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits))
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id 7EFDD15807A
	for <garchives@archives.gentoo.org>; Mon,  7 Oct 2024 04:13:05 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 169A3E29A9;
	Mon,  7 Oct 2024 04:13:04 +0000 (UTC)
Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id EE524E29A9
	for <gentoo-commits@lists.gentoo.org>; Mon,  7 Oct 2024 04:13:03 +0000 (UTC)
Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id E8ADC343155
	for <gentoo-commits@lists.gentoo.org>; Mon,  7 Oct 2024 04:13:02 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id 36EDA16EF
	for <gentoo-commits@lists.gentoo.org>; Mon,  7 Oct 2024 04:13:01 +0000 (UTC)
From: "Sam James" <sam@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" <sam@gentoo.org>
Message-ID: <1728274361.434a6775ce93a15ef517478565a938aa73d1d528.sam@gentoo>
Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/
X-VCS-Repository: repo/gentoo
X-VCS-Files: eclass/toolchain.eclass
X-VCS-Directories: eclass/
X-VCS-Committer: sam
X-VCS-Committer-Name: Sam James
X-VCS-Revision: 434a6775ce93a15ef517478565a938aa73d1d528
X-VCS-Branch: master
Date: Mon,  7 Oct 2024 04:13:01 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply
X-Archives-Salt: 85816c6f-5081-44cb-9efc-6a3dc92b07bb
X-Archives-Hash: 32af5e4afd9dd2e727460293325bdf73

commit:     434a6775ce93a15ef517478565a938aa73d1d528
Author:     Andrei Horodniceanu <a.horodniceanu <AT> proton <DOT> me>
AuthorDate: Fri Oct  4 04:10:04 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Oct  7 04:12:41 2024 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=434a6775

toolchain.eclass: Support cross GDC

While the D use flags is masked by crossdev the build used to work, on
my limited number of machines, up until recently with the D code
refactors.

When building sys-devel/gcc or cross-${TARGET}/gcc natively the
appropriate gdc compiler is installed under /usr/${CHOST}/gcc-bin and is
provided by sys-devel/gcc[d].

When building sys-devel/gcc or cross-${CTARGET}/gcc for another system
the appropriate gdc binary is under /usr/${CBUILD}/${CHOST}/gcc-bin and
is provided by cross-${CHOST}/gcc[d].

Also use the full ${CHOST}-gdc executable names since plain gdc is only
present on native builds.

Signed-off-by: Andrei Horodniceanu <a.horodniceanu <AT> proton.me>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 eclass/toolchain.eclass | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/eclass/toolchain.eclass b/eclass/toolchain.eclass
index 0d46d6f3a799..19357b4dfb2d 100644
--- a/eclass/toolchain.eclass
+++ b/eclass/toolchain.eclass
@@ -1000,8 +1000,17 @@ toolchain_setup_ada() {
 # Determine the most suitable GDC (D compiler) for bootstrapping
 # and setup the environment for building.
 toolchain_setup_d() {
-	local latest_gcc=$(best_version -b "sys-devel/gcc")
-	latest_gcc="${latest_gcc#sys-devel/gcc-}"
+	local gcc_pkg gcc_bin_base
+	if tc-is-cross-compiler ; then
+		gcc_pkg=cross-${CHOST}/gcc
+		gcc_bin_base=${BROOT}/usr/${CBUILD}/${CHOST}/gcc-bin
+	else
+		gcc_pkg=sys-devel/gcc
+		gcc_bin_base=${BROOT}/usr/${CHOST}/gcc-bin
+	fi
+
+	local latest_gcc=$(best_version -b "${gcc_pkg}")
+	latest_gcc="${latest_gcc#${gcc_pkg}-}"
 	latest_gcc=$(ver_cut 1 ${latest_gcc})
 
 	local d_bootstrap
@@ -1011,10 +1020,10 @@ toolchain_setup_d() {
 	# 2) Iterate downwards from the version being built;
 	# 3) Iterate upwards from the version being built to the greatest version installed.
 	for d_candidate in ${SLOT} $(seq $((${SLOT} - 1)) -1 10) $(seq $((${SLOT} + 1)) ${latest_gcc}) ; do
-		has_version -b "sys-devel/gcc:${d_candidate}" || continue
+		has_version -b "${gcc_pkg}:${d_candidate}" || continue
 
-		ebegin "Testing sys-devel/gcc:${d_candidate} for D"
-		if has_version -b "sys-devel/gcc:${d_candidate}[d(-)]" ; then
+		ebegin "Testing ${gcc_pkg}:${d_candidate} for D"
+		if has_version -b "${gcc_pkg}:${d_candidate}[d(-)]" ; then
 			d_bootstrap=${d_candidate}
 
 			eend 0
@@ -1024,7 +1033,7 @@ toolchain_setup_d() {
 	done
 
 	if [[ -n ${d_bootstrap} ]] ; then
-		export GDC="${BROOT}/usr/${CTARGET}/gcc-bin/${d_bootstrap}/gdc"
+		export GDC=${gcc_bin_base}/${d_bootstrap}/${CHOST}-gdc
 	fi
 }