* [gentoo-dev] [PATCH 3/4] kernel-2.eclass: Use cross.eclass for figuring out CTARGET
@ 2023-08-11 3:48 Alfred Persson Forsberg
2023-08-11 3:48 ` [gentoo-dev] [PATCH 0/4] Introducing cross.eclass for Crossdev ebuilds Alfred Persson Forsberg
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Alfred Persson Forsberg @ 2023-08-11 3:48 UTC (permalink / raw
To: gentoo-dev; +Cc: sam, llvm, toolchain, cross, Alfred Persson Forsberg
Signed-off-by: Alfred Persson Forsberg <cat@catcream.org>
---
eclass/kernel-2.eclass | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/eclass/kernel-2.eclass b/eclass/kernel-2.eclass
index bdeabb9fc2dc..3d08604929eb 100644
--- a/eclass/kernel-2.eclass
+++ b/eclass/kernel-2.eclass
@@ -281,7 +281,7 @@
# If you do change them, there is a chance that we will not fix resulting bugs;
# that of course does not mean we're not willing to help.
-inherit estack multiprocessing toolchain-funcs
+inherit cross estack multiprocessing toolchain-funcs
case ${EAPI} in
7|8) ;;
@@ -293,11 +293,6 @@ esac
# I will remove it when I come up with something more reasonable.
[[ ${PROFILE_ARCH} == ppc64 ]] && CHOST="powerpc64-${CHOST#*-}"
-export CTARGET=${CTARGET:-${CHOST}}
-if [[ ${CTARGET} == ${CHOST} && ${CATEGORY/cross-} != ${CATEGORY} ]]; then
- export CTARGET=${CATEGORY/cross-}
-fi
-
HOMEPAGE="https://www.kernel.org/ https://wiki.gentoo.org/wiki/Kernel ${HOMEPAGE}"
: "${LICENSE:="GPL-2"}"
--
2.41.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [gentoo-dev] [PATCH 0/4] Introducing cross.eclass for Crossdev ebuilds
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
2023-08-11 3:48 ` [gentoo-dev] [PATCH 1/4] cross.eclass: new eclass Alfred Persson Forsberg
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Alfred Persson Forsberg @ 2023-08-11 3:48 UTC (permalink / raw
To: gentoo-dev; +Cc: sam, llvm, toolchain, cross, Alfred Persson Forsberg
Hello, I am working on LLVM/Clang support for Crossdev, and I propose
a new eclass for cross compilation. This is mostly due to boilerplate
currently shared by a lot of ebuilds.
One snippet of code that's used by basically all cross ebuilds is:
> export CBUILD=${CBUILD:-${CHOST}}
> export CTARGET=${CTARGET:-${CHOST}}
> if [[ ${CTARGET} == ${CHOST} ]] ; then
> if [[ ${CATEGORY} == cross-* ]] ; then
> export CTARGET=${CATEGORY#cross-}
> fi
> fi
and because I use cross_llvm-* for my categories it becomes even more
of a mess. Let me know if this is a good idea, the other way is to
inline all of this.
Alfred Persson Forsberg (4):
cross.eclass: new eclass
sys-libs/musl: Support LLVM/Clang crossdev
kernel-2.eclass: Use cross.eclass for figuring out CTARGET
sys-libs/compiler-rt: Support LLVM/Clang crossdev
eclass/cross.eclass | 83 +++++++++++++++++++
eclass/kernel-2.eclass | 7 +-
.../compiler-rt-17.0.0.9999.ebuild | 36 +++++++-
sys-libs/musl/musl-1.2.4.ebuild | 20 +----
4 files changed, 120 insertions(+), 26 deletions(-)
create mode 100644 eclass/cross.eclass
--
2.41.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [gentoo-dev] [PATCH 1/4] cross.eclass: new eclass
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 ` Alfred Persson Forsberg
2023-08-11 3:48 ` [gentoo-dev] [PATCH 2/4] sys-libs/musl: Support LLVM/Clang crossdev Alfred Persson Forsberg
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Alfred Persson Forsberg @ 2023-08-11 3:48 UTC (permalink / raw
To: gentoo-dev; +Cc: sam, llvm, toolchain, cross, Alfred Persson Forsberg
Signed-off-by: Alfred Persson Forsberg <cat@catcream.org>
---
eclass/cross.eclass | 83 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 83 insertions(+)
create mode 100644 eclass/cross.eclass
diff --git a/eclass/cross.eclass b/eclass/cross.eclass
new file mode 100644
index 000000000000..a7a75aac8e43
--- /dev/null
+++ b/eclass/cross.eclass
@@ -0,0 +1,83 @@
+# Copyright 1999-2023 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: cross.eclass
+# @MAINTAINER:
+# cat@catcream.org
+# @AUTHOR:
+# Alfred Persson Forsberg <cat@catcream.org> (21 Jul 2023)
+# @SUPPORTED_EAPIS: 7 8
+# @BLURB: Convenience wrappers for packages used by the Crossdev tool.
+
+inherit toolchain-funcs
+
+case ${EAPI} in
+ 7|8) ;;
+ *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
+esac
+
+if [[ -z ${_CROSS_ECLASS} ]]; then
+_CROSS_ECLASS=1
+
+# @ECLASS_VARIABLE: _CROSS_CATEGORY_PREFIX
+# @INTERNAL
+_CROSS_CATEGORY_PREFIX=""
+
+# @ECLASS_VARIABLE: _IS_CROSSPKG_LLVM
+# @INTERNAL
+_IS_CROSSPKG_LLVM=0
+if [[ ${CATEGORY} == cross_llvm-* ]] ; then
+ _IS_CROSSPKG_LLVM=1
+ _CROSS_CATEGORY_PREFIX="cross_llvm-"
+fi
+
+# @ECLASS_VARIABLE: _IS_CROSSPKG_GCC
+# @INTERNAL
+_IS_CROSSPKG_GCC=0
+if [[ ${CATEGORY} == cross-* ]] ; then
+ _IS_CROSSPKG_GCC=1
+ _CROSS_CATEGORY_PREFIX="cross-"
+fi
+
+# @ECLASS_VARIABLE: _IS_CROSSPKG
+# @INTERNAL
+[[ ${_IS_CROSSPKG_LLVM} == 1 || ${_IS_CROSSPKG_GCC} == 1 ]] && _IS_CROSSPKG=1
+
+# Default CBUILD and CTARGET to CHOST if unset.
+export CBUILD=${CBUILD:-${CHOST}}
+export CTARGET=${CTARGET:-${CHOST}}
+if [[ ${CTARGET} == ${CHOST} ]] ; then
+ # cross-aarch64-gentoo-linux-musl -> aarch64-gentoo-linux-musl
+ [[ ${_IS_CROSSPKG_GCC} == 1 ]] && export CTARGET=${CATEGORY#cross-}
+ [[ ${_IS_CROSSPKG_LLVM} == 1 ]] && export CTARGET=${CATEGORY#cross_llvm-}
+fi
+
+# @FUNCTION: is_crosscompile
+# @RETURN:
+# Shell true if we're targeting an architecture other than host
+is_crosscompile() {
+ [[ ${CHOST} != ${CTARGET} ]]
+}
+
+# @FUNCTION: is_crosspkg
+# @RETURN:
+# Shell true if package belongs to any crossdev category
+is_crosspkg() {
+ [[ ${_IS_CROSSPKG} == 1 ]]
+}
+
+# @FUNCTION: is_crosspkg_gcc
+# @RETURN:
+# Shell true if package belongs to GCC (standard) crossdev category
+is_crosspkg_gcc() {
+ [[ ${_IS_CROSSPKG_GCC} == 1 ]]
+}
+
+# @FUNCTION: is_crosspkg_llvm
+# @RETURN:
+# Shell true if package belongs to LLVM crossdev category.
+is_crosspkg_llvm() {
+ [[ ${_IS_CROSSPKG_LLVM} == 1 ]]
+}
+
+fi
--
2.41.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [gentoo-dev] [PATCH 2/4] sys-libs/musl: Support LLVM/Clang crossdev
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 ` 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 ` [gentoo-dev] [PATCH 4/4] sys-libs/compiler-rt: Support LLVM/Clang crossdev Alfred Persson Forsberg
4 siblings, 0 replies; 6+ messages in thread
From: Alfred Persson Forsberg @ 2023-08-11 3:48 UTC (permalink / raw
To: gentoo-dev; +Cc: sam, llvm, toolchain, cross, Alfred Persson Forsberg
Signed-off-by: Alfred Persson Forsberg <cat@catcream.org>
---
sys-libs/musl/musl-1.2.4.ebuild | 20 ++++----------------
1 file changed, 4 insertions(+), 16 deletions(-)
diff --git a/sys-libs/musl/musl-1.2.4.ebuild b/sys-libs/musl/musl-1.2.4.ebuild
index a0653436a844..da55b8c05fe1 100644
--- a/sys-libs/musl/musl-1.2.4.ebuild
+++ b/sys-libs/musl/musl-1.2.4.ebuild
@@ -3,7 +3,7 @@
EAPI=8
-inherit flag-o-matic toolchain-funcs prefix
+inherit cross flag-o-matic toolchain-funcs prefix
if [[ ${PV} == "9999" ]] ; then
EGIT_REPO_URI="git://git.musl-libc.org/musl"
inherit git-r3
@@ -25,14 +25,6 @@ SRC_URI+="
https://dev.gentoo.org/~blueness/musl-misc/iconv.c
"
-export CBUILD=${CBUILD:-${CHOST}}
-export CTARGET=${CTARGET:-${CHOST}}
-if [[ ${CTARGET} == ${CHOST} ]] ; then
- if [[ ${CATEGORY} == cross-* ]] ; then
- export CTARGET=${CATEGORY#cross-}
- fi
-fi
-
DESCRIPTION="Light, fast and simple C library focused on standards-conformance and safety"
HOMEPAGE="https://musl.libc.org"
@@ -49,17 +41,13 @@ QA_PRESTRIPPED="usr/lib/crtn.o"
# built as part as crossdev. Also, elide the blockers when in cross-*,
# as it doesn't make sense to block the normal CBUILD libxcrypt at all
# there when we're installing into /usr/${CHOST} anyway.
-if [[ ${CATEGORY} == cross-* ]] ; then
+if is_crosspkg ; then
IUSE="${IUSE/crypt/+crypt}"
else
RDEPEND="crypt? ( !sys-libs/libxcrypt[system] )"
PDEPEND="!crypt? ( sys-libs/libxcrypt[system] )"
fi
-is_crosscompile() {
- [[ ${CHOST} != ${CTARGET} ]]
-}
-
just_headers() {
use headers-only && is_crosscompile
}
@@ -121,7 +109,7 @@ src_compile() {
just_headers && return 0
emake
- if [[ ${CATEGORY} != cross-* ]] ; then
+ if ! is_crosspkg ; then
emake -C "${T}" getconf getent iconv \
CC="$(tc-getCC)" \
CFLAGS="${CFLAGS}" \
@@ -152,7 +140,7 @@ src_install() {
rm "${ED}/usr/$(get_libdir)/libcrypt.a" || die
fi
- if [[ ${CATEGORY} != cross-* ]] ; then
+ if ! is_crosspkg ; then
# Fish out of config:
# ARCH = ...
# SUBARCH = ...
--
2.41.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [gentoo-dev] [PATCH 3/4] kernel-2.eclass: Use cross.eclass for figuring out CTARGET
2023-08-11 3:48 [gentoo-dev] [PATCH 3/4] kernel-2.eclass: Use cross.eclass for figuring out CTARGET Alfred Persson Forsberg
` (2 preceding siblings ...)
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 ` Alfred Persson Forsberg
2023-08-11 3:48 ` [gentoo-dev] [PATCH 4/4] sys-libs/compiler-rt: Support LLVM/Clang crossdev Alfred Persson Forsberg
4 siblings, 0 replies; 6+ messages in thread
From: Alfred Persson Forsberg @ 2023-08-11 3:48 UTC (permalink / raw
To: gentoo-dev; +Cc: sam, llvm, toolchain, cross, Alfred Persson Forsberg
Signed-off-by: Alfred Persson Forsberg <cat@catcream.org>
---
eclass/kernel-2.eclass | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/eclass/kernel-2.eclass b/eclass/kernel-2.eclass
index bdeabb9fc2dc..3d08604929eb 100644
--- a/eclass/kernel-2.eclass
+++ b/eclass/kernel-2.eclass
@@ -281,7 +281,7 @@
# If you do change them, there is a chance that we will not fix resulting bugs;
# that of course does not mean we're not willing to help.
-inherit estack multiprocessing toolchain-funcs
+inherit cross estack multiprocessing toolchain-funcs
case ${EAPI} in
7|8) ;;
@@ -293,11 +293,6 @@ esac
# I will remove it when I come up with something more reasonable.
[[ ${PROFILE_ARCH} == ppc64 ]] && CHOST="powerpc64-${CHOST#*-}"
-export CTARGET=${CTARGET:-${CHOST}}
-if [[ ${CTARGET} == ${CHOST} && ${CATEGORY/cross-} != ${CATEGORY} ]]; then
- export CTARGET=${CATEGORY/cross-}
-fi
-
HOMEPAGE="https://www.kernel.org/ https://wiki.gentoo.org/wiki/Kernel ${HOMEPAGE}"
: "${LICENSE:="GPL-2"}"
--
2.41.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [gentoo-dev] [PATCH 4/4] sys-libs/compiler-rt: Support LLVM/Clang crossdev
2023-08-11 3:48 [gentoo-dev] [PATCH 3/4] kernel-2.eclass: Use cross.eclass for figuring out CTARGET Alfred Persson Forsberg
` (3 preceding siblings ...)
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
4 siblings, 0 replies; 6+ messages in thread
From: Alfred Persson Forsberg @ 2023-08-11 3:48 UTC (permalink / raw
To: gentoo-dev; +Cc: sam, llvm, toolchain, cross, Alfred Persson Forsberg
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
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-08-11 3:50 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [gentoo-dev] [PATCH 4/4] sys-libs/compiler-rt: Support LLVM/Clang crossdev Alfred Persson Forsberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox