From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-1570325-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 4D9EA158089
	for <garchives@archives.gentoo.org>; Mon, 13 Nov 2023 22:15:40 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 9084F2BC01F;
	Mon, 13 Nov 2023 22:15:39 +0000 (UTC)
Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4])
	(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 76C1C2BC01F
	for <gentoo-commits@lists.gentoo.org>; Mon, 13 Nov 2023 22:15:39 +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 B1BC1335D72
	for <gentoo-commits@lists.gentoo.org>; Mon, 13 Nov 2023 22:15:38 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id 1FC44132E
	for <gentoo-commits@lists.gentoo.org>; Mon, 13 Nov 2023 22:15:37 +0000 (UTC)
From: "James Le Cuirot" <chewi@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, "James Le Cuirot" <chewi@gentoo.org>
Message-ID: <1699913587.6fab286b0d2af2756716e4ba8d8c9aa569f9c6b4.chewi@gentoo>
Subject: [gentoo-commits] repo/gentoo:master commit in: dev-lang/luajit/
X-VCS-Repository: repo/gentoo
X-VCS-Files: dev-lang/luajit/luajit-2.1.0_beta3_p20220613.ebuild
X-VCS-Directories: dev-lang/luajit/
X-VCS-Committer: chewi
X-VCS-Committer-Name: James Le Cuirot
X-VCS-Revision: 6fab286b0d2af2756716e4ba8d8c9aa569f9c6b4
X-VCS-Branch: master
Date: Mon, 13 Nov 2023 22:15:37 +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: 059d002a-0d31-4844-b0ec-9e90dbe06802
X-Archives-Hash: 03557a6d2ec3e59875ac573e4c190520

commit:     6fab286b0d2af2756716e4ba8d8c9aa569f9c6b4
Author:     James Le Cuirot <chewi <AT> gentoo <DOT> org>
AuthorDate: Sat Nov  4 16:17:15 2023 +0000
Commit:     James Le Cuirot <chewi <AT> gentoo <DOT> org>
CommitDate: Mon Nov 13 22:13:07 2023 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=6fab286b

dev-lang/luajit: Fix cross-compiling from 64-bit to 32-bit

This will only work with a multilib build host toolchain, so probably
just amd64 and ppc64, but it's better than nothing.

Multilib profiles specify an explicit target rather than just -m32 in
LDFLAGS, but this should still do the right thing, and there's probably
no way to query the build profile.

Closes: https://bugs.gentoo.org/627332
Signed-off-by: James Le Cuirot <chewi <AT> gentoo.org>

 dev-lang/luajit/luajit-2.1.0_beta3_p20220613.ebuild | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/dev-lang/luajit/luajit-2.1.0_beta3_p20220613.ebuild b/dev-lang/luajit/luajit-2.1.0_beta3_p20220613.ebuild
index 24063aae5265..01c4aca8c65c 100644
--- a/dev-lang/luajit/luajit-2.1.0_beta3_p20220613.ebuild
+++ b/dev-lang/luajit/luajit-2.1.0_beta3_p20220613.ebuild
@@ -31,6 +31,21 @@ IUSE="lua52compat static-libs"
 
 S="${WORKDIR}/LuaJIT-${GIT_COMMIT}"
 
+src_configure() {
+	tc-export_build_env
+
+	# You need to use a 32-bit toolchain to build for a 32-bit architecture.
+	# Some 64-bit toolchains (like amd64 and ppc64) usually have multilib
+	# enabled, allowing you to build in 32-bit with -m32. This won't work in all
+	# cases, but it will otherwise just break, so it's worth trying anyway. If
+	# you're trying to build for 64-bit from 32-bit, then you're screwed, sorry.
+	# See https://github.com/LuaJIT/LuaJIT/issues/664 for the upstream issue.
+	if tc-is-cross-compiler && [[ $(tc-get-build-ptr-size) != 4 && $(tc-get-ptr-size) == 4 ]]; then
+		BUILD_CFLAGS+=" -m32"
+		BUILD_LDFLAGS+=" -m32"
+	fi
+}
+
 _emake() {
 	emake \
 		Q= \
@@ -55,7 +70,6 @@ _emake() {
 }
 
 src_compile() {
-	tc-export_build_env
 	_emake XCFLAGS="$(usex lua52compat "-DLUAJIT_ENABLE_LUA52COMPAT" "")"
 }