From: WANG Xuerui <xen0n@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Cc: WANG Xuerui <xen0n@gentoo.org>,
Thilo Fromm <thilo.alexander@gmail.com>,
Flatcar Linux Maintainers <infra@flatcar-linux.org>
Subject: [gentoo-dev] [PATCH 1/2] go-env.eclass: unify GOARCH mapping logic with dev-lang/go
Date: Thu, 23 Nov 2023 17:31:58 +0800 [thread overview]
Message-ID: <20231123093159.1228864-2-xen0n@gentoo.org> (raw)
In-Reply-To: <20231123093159.1228864-1-xen0n@gentoo.org>
Previously the eclass featured its own GOARCH mapping, that took care
of less cases than the dev-lang/go ebuild did, and broke Go packages on
arches like loong (GOARCH=loong64), mips (4 GOARCHes supported in total)
or riscv (GOARCH=riscv64).
This patch adds a copy of the go_arch() helper from dev-lang/go to the
eclass and switches the go-env_set_compile_environment() function to use
that, to fix the problem at hand.
Fixes: 878d04daaf34765e6224e58139a9c45921d7a0c3
Closes: https://bugs.gentoo.org/917750
Signed-off-by: WANG Xuerui <xen0n@gentoo.org>
---
eclass/go-env.eclass | 40 ++++++++++++++++++++++++++--------------
1 file changed, 26 insertions(+), 14 deletions(-)
diff --git a/eclass/go-env.eclass b/eclass/go-env.eclass
index ba4f6c3fbb59..08e3cf498a70 100644
--- a/eclass/go-env.eclass
+++ b/eclass/go-env.eclass
@@ -8,7 +8,7 @@
# Flatcar Linux Maintainers <infra@flatcar-linux.org>
# @BLURB: Helper eclass for setting the Go compile environment. Required for cross-compiling.
# @DESCRIPTION:
-# This eclass includes a helper function for setting the compile environment for Go ebuilds.
+# This eclass includes helper functions for setting the compile environment for Go ebuilds.
# Intended to be called by other Go eclasses in an early build stage, e.g. src_unpack.
if [[ -z ${_GO_ENV_ECLASS} ]]; then
@@ -25,24 +25,36 @@ inherit toolchain-funcs
# (e.g. "emerge-aarch64-cross-linux-gnu foo" run on x86_64 will emerge "foo" for x86_64
# instead of aarch64)
go-env_set_compile_environment() {
- local arch="$(tc-arch)"
- case "${arch}" in
- x86) GOARCH="386" ;;
- x64-*) GOARCH="amd64" ;;
- ppc64) if [[ "$(tc-endian)" == "big" ]] ; then
- GOARCH="ppc64"
- else
- GOARCH="ppc64le"
- fi ;;
- *) GOARCH="${arch}" ;;
- esac
-
tc-export CC CXX
- export GOARCH
+
+ export GOARCH="$(go-env_goarch)"
export CGO_CFLAGS="${CGO_CFLAGS:-$CFLAGS}"
export CGO_CPPFLAGS="${CGO_CPPFLAGS:-$CPPFLAGS}"
export CGO_CXXFLAGS="${CGO_CXXFLAGS:-$CXXFLAGS}"
export CGO_LDFLAGS="${CGO_LDFLAGS:-$LDFLAGS}"
}
+# @FUNCTION: go-env_goarch
+# @USAGE: [toolchain prefix]
+# @DESCRIPTION:
+# Returns the appropriate GOARCH setting for the target architecture.
+go-env_goarch() {
+ # By chance most portage arch names match Go
+ local tc_arch=$(tc-arch $@)
+ case "${tc_arch}" in
+ x86) echo 386;;
+ x64-*) echo amd64;;
+ loong) echo loong64;;
+ mips) if use abi_mips_o32; then
+ [[ $(tc-endian $@) = big ]] && echo mips || echo mipsle
+ elif use abi_mips_n64; then
+ [[ $(tc-endian $@) = big ]] && echo mips64 || echo mips64le
+ fi ;;
+ ppc64) [[ $(tc-endian $@) = big ]] && echo ppc64 || echo ppc64le ;;
+ riscv) echo riscv64 ;;
+ s390) echo s390x ;;
+ *) echo "${tc_arch}";;
+ esac
+}
+
fi
--
2.42.1
next prev parent reply other threads:[~2023-11-23 9:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-23 9:31 [gentoo-dev] [PATCH 0/2] go-env.eclass: niche platform fixes WANG Xuerui
2023-11-23 9:31 ` WANG Xuerui [this message]
2023-11-23 9:31 ` [gentoo-dev] [PATCH 2/2] go-env.eclass: also set GOARM & GO386 when applicable WANG Xuerui
2023-11-23 23:01 ` Ionen Wolkens
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=20231123093159.1228864-2-xen0n@gentoo.org \
--to=xen0n@gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
--cc=infra@flatcar-linux.org \
--cc=thilo.alexander@gmail.com \
/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