public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH 0/2] go-env.eclass: niche platform fixes
@ 2023-11-23  9:31 WANG Xuerui
  2023-11-23  9:31 ` [gentoo-dev] [PATCH 1/2] go-env.eclass: unify GOARCH mapping logic with dev-lang/go WANG Xuerui
  2023-11-23  9:31 ` [gentoo-dev] [PATCH 2/2] go-env.eclass: also set GOARM & GO386 when applicable WANG Xuerui
  0 siblings, 2 replies; 4+ messages in thread
From: WANG Xuerui @ 2023-11-23  9:31 UTC (permalink / raw)
  To: gentoo-dev; +Cc: WANG Xuerui, Thilo Fromm, Flatcar Linux Maintainers

Hi,

Here are some fixes to the recently added go-env.eclass that broke Go
ebuilds on several arches (loong and riscv confirmed). I've tested on
loong to confirm.

You can also view this series on GitHub [1], should you prefer that.

[1]: https://github.com/gentoo/gentoo/pull/33941

WANG Xuerui (2):
  go-env.eclass: unify GOARCH mapping logic with dev-lang/go
  go-env.eclass: also set GOARM & GO386 when applicable

 eclass/go-env.eclass | 61 ++++++++++++++++++++++++++++++++++----------
 1 file changed, 47 insertions(+), 14 deletions(-)

-- 
2.42.1



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [gentoo-dev] [PATCH 1/2] go-env.eclass: unify GOARCH mapping logic with dev-lang/go
  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
  2023-11-23  9:31 ` [gentoo-dev] [PATCH 2/2] go-env.eclass: also set GOARM & GO386 when applicable WANG Xuerui
  1 sibling, 0 replies; 4+ messages in thread
From: WANG Xuerui @ 2023-11-23  9:31 UTC (permalink / raw)
  To: gentoo-dev; +Cc: WANG Xuerui, Thilo Fromm, Flatcar Linux Maintainers

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



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [gentoo-dev] [PATCH 2/2] go-env.eclass: also set GOARM & GO386 when applicable
  2023-11-23  9:31 [gentoo-dev] [PATCH 0/2] go-env.eclass: niche platform fixes WANG Xuerui
  2023-11-23  9:31 ` [gentoo-dev] [PATCH 1/2] go-env.eclass: unify GOARCH mapping logic with dev-lang/go WANG Xuerui
@ 2023-11-23  9:31 ` WANG Xuerui
  2023-11-23 23:01   ` Ionen Wolkens
  1 sibling, 1 reply; 4+ messages in thread
From: WANG Xuerui @ 2023-11-23  9:31 UTC (permalink / raw)
  To: gentoo-dev; +Cc: WANG Xuerui, Thilo Fromm, Flatcar Linux Maintainers

This is necessary for the build artifact to conform to the configured
ISA level and features on those arches. The logic is also taken from
the dev-lang/go ebuild.

Signed-off-by: WANG Xuerui <xen0n@gentoo.org>
---
 eclass/go-env.eclass | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/eclass/go-env.eclass b/eclass/go-env.eclass
index 08e3cf498a70..4bc8c4b15c65 100644
--- a/eclass/go-env.eclass
+++ b/eclass/go-env.eclass
@@ -19,6 +19,8 @@ inherit toolchain-funcs
 # @FUNCTION: go-env_set_compile_environment
 # @DESCRIPTION:
 # Set up basic compile environment: CC, CXX, and GOARCH.
+# Necessary platform-specific settings such as GOARM or GO386 are also set
+# according to the Portage configuration when building for those architectures.
 # Also carry over CFLAGS, LDFLAGS and friends.
 # Required for cross-compiling with crossdev.
 # If not set, host defaults will be used and the resulting binaries are host arch.
@@ -28,6 +30,9 @@ go-env_set_compile_environment() {
 	tc-export CC CXX
 
 	export GOARCH="$(go-env_goarch)"
+	use arm && export GOARM=$(go-env_goarm)
+	use x86 && export GO386=$(usex cpu_flags_x86_sse2 '' 'softfloat')
+
 	export CGO_CFLAGS="${CGO_CFLAGS:-$CFLAGS}"
 	export CGO_CPPFLAGS="${CGO_CPPFLAGS:-$CPPFLAGS}"
 	export CGO_CXXFLAGS="${CGO_CXXFLAGS:-$CXXFLAGS}"
@@ -57,4 +62,20 @@ go-env_goarch() {
 	esac
 }
 
+# @FUNCTION: go-env_goarm
+# @USAGE: [CHOST-value]
+# @DESCRIPTION:
+# Returns the appropriate GOARM setting for the CHOST given, or the default
+# CHOST.
+go-env_goarm() {
+	case "${1:-${CHOST}}" in
+		armv5*)	echo 5;;
+		armv6*)	echo 6;;
+		armv7*)	echo 7;;
+		*)
+			die "unknown GOARM for ${1:-${CHOST}}"
+			;;
+	esac
+}
+
 fi
-- 
2.42.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [gentoo-dev] [PATCH 2/2] go-env.eclass: also set GOARM & GO386 when applicable
  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
  0 siblings, 0 replies; 4+ messages in thread
From: Ionen Wolkens @ 2023-11-23 23:01 UTC (permalink / raw)
  To: gentoo-dev; +Cc: WANG Xuerui, Thilo Fromm, Flatcar Linux Maintainers

[-- Attachment #1: Type: text/plain, Size: 2225 bytes --]

On Thu, Nov 23, 2023 at 05:31:59PM +0800, WANG Xuerui wrote:
> This is necessary for the build artifact to conform to the configured
> ISA level and features on those arches. The logic is also taken from
> the dev-lang/go ebuild.
> 
> Signed-off-by: WANG Xuerui <xen0n@gentoo.org>
> ---
>  eclass/go-env.eclass | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
> 
> diff --git a/eclass/go-env.eclass b/eclass/go-env.eclass
> index 08e3cf498a70..4bc8c4b15c65 100644
> --- a/eclass/go-env.eclass
> +++ b/eclass/go-env.eclass
> @@ -19,6 +19,8 @@ inherit toolchain-funcs
>  # @FUNCTION: go-env_set_compile_environment
>  # @DESCRIPTION:
>  # Set up basic compile environment: CC, CXX, and GOARCH.
> +# Necessary platform-specific settings such as GOARM or GO386 are also set
> +# according to the Portage configuration when building for those architectures.
>  # Also carry over CFLAGS, LDFLAGS and friends.
>  # Required for cross-compiling with crossdev.
>  # If not set, host defaults will be used and the resulting binaries are host arch.
> @@ -28,6 +30,9 @@ go-env_set_compile_environment() {
>  	tc-export CC CXX
>  
>  	export GOARCH="$(go-env_goarch)"
> +	use arm && export GOARM=$(go-env_goarm)
> +	use x86 && export GO386=$(usex cpu_flags_x86_sse2 '' 'softfloat')

cpu_flags_x86_sse2 is not an IUSE_IMPLICIT, meaning that emerging a
package without it in IUSE for x86 will result in:

 * ERROR: x11-terms/kitty-0.31.0::gentoo failed (compile phase):
 *   USE Flag 'cpu_flags_x86_sse2' not in IUSE for x11-terms/kitty-0.31.0

> +
>  	export CGO_CFLAGS="${CGO_CFLAGS:-$CFLAGS}"
>  	export CGO_CPPFLAGS="${CGO_CPPFLAGS:-$CPPFLAGS}"
>  	export CGO_CXXFLAGS="${CGO_CXXFLAGS:-$CXXFLAGS}"
> @@ -57,4 +62,20 @@ go-env_goarch() {
>  	esac
>  }
>  
> +# @FUNCTION: go-env_goarm
> +# @USAGE: [CHOST-value]
> +# @DESCRIPTION:
> +# Returns the appropriate GOARM setting for the CHOST given, or the default
> +# CHOST.
> +go-env_goarm() {
> +	case "${1:-${CHOST}}" in
> +		armv5*)	echo 5;;
> +		armv6*)	echo 6;;
> +		armv7*)	echo 7;;
> +		*)
> +			die "unknown GOARM for ${1:-${CHOST}}"
> +			;;
> +	esac
> +}
> +
>  fi
> -- 
> 2.42.1
> 
> 

-- 
ionen

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-11-23 23:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-23  9:31 [gentoo-dev] [PATCH 0/2] go-env.eclass: niche platform fixes WANG Xuerui
2023-11-23  9:31 ` [gentoo-dev] [PATCH 1/2] go-env.eclass: unify GOARCH mapping logic with dev-lang/go WANG Xuerui
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox