mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-13 16:06:59 +02:00
eclass/go-env: Sync with Gentoo
It's from Gentoo commit 29f0721c4bc11ef3b9d94590016c25a190bc0f20.
This commit is contained in:
parent
3f14fa91b7
commit
805040e95a
@ -1,48 +1,131 @@
|
|||||||
# Copyright 2023 Gentoo Authors
|
# Copyright 2023-2024 Gentoo Authors
|
||||||
# Distributed under the terms of the GNU General Public License v2
|
# Distributed under the terms of the GNU General Public License v2
|
||||||
|
|
||||||
# @ECLASS: go-env.eclass
|
# @ECLASS: go-env.eclass
|
||||||
# @MAINTAINER:
|
# @MAINTAINER:
|
||||||
# Flatcar Maintainers <infra@flatcar.org>
|
# Flatcar Linux Maintainers <infra@flatcar-linux.org>
|
||||||
# @AUTHOR:
|
# @AUTHOR:
|
||||||
# Flatcar Maintainers <infra@flatcar.org>
|
# Flatcar Linux Maintainers <infra@flatcar-linux.org>
|
||||||
|
# @SUPPORTED_EAPIS: 7 8
|
||||||
# @BLURB: Helper eclass for setting the Go compile environment. Required for cross-compiling.
|
# @BLURB: Helper eclass for setting the Go compile environment. Required for cross-compiling.
|
||||||
# @DESCRIPTION:
|
# @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.
|
# Intended to be called by other Go eclasses in an early build stage, e.g. src_unpack.
|
||||||
|
|
||||||
|
case ${EAPI} in
|
||||||
|
7|8) ;;
|
||||||
|
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
if [[ -z ${_GO_ENV_ECLASS} ]]; then
|
if [[ -z ${_GO_ENV_ECLASS} ]]; then
|
||||||
_GO_ENV_ECLASS=1
|
_GO_ENV_ECLASS=1
|
||||||
|
|
||||||
inherit toolchain-funcs
|
inherit flag-o-matic toolchain-funcs
|
||||||
|
|
||||||
# @FUNCTION: go-env_set_compile_environment
|
# @FUNCTION: go-env_set_compile_environment
|
||||||
# @DESCRIPTION:
|
# @DESCRIPTION:
|
||||||
# Set up basic compile environment: CC, CXX, and GOARCH.
|
# 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.
|
# Also carry over CFLAGS, LDFLAGS and friends.
|
||||||
# Required for cross-compiling with crossdev.
|
# Required for cross-compiling with crossdev.
|
||||||
# If not set, host defaults will be used and the resulting binaries are host arch.
|
# If not set, host defaults will be used and the resulting binaries are host arch.
|
||||||
# (e.g. "emerge-aarch64-cross-linux-gnu foo" run on x86_64 will emerge "foo" for x86_64
|
# (e.g. "emerge-aarch64-cross-linux-gnu foo" run on x86_64 will emerge "foo" for x86_64
|
||||||
# instead of aarch64)
|
# instead of aarch64)
|
||||||
go-env_set_compile_environment() {
|
go-env_set_compile_environment() {
|
||||||
local arch=$(tc-arch "${CHOST}}")
|
tc-export CC CXX PKG_CONFIG
|
||||||
case "${arch}" in
|
|
||||||
x86) GOARCH="386" ;;
|
export GOARCH="$(go-env_goarch)"
|
||||||
x64-*) GOARCH="amd64" ;;
|
use arm && export GOARM=$(go-env_goarm)
|
||||||
ppc64) if [[ "$(tc-endian "${${CHOST}}")" = "big" ]] ; then
|
use x86 && export GO386=$(go-env_go386)
|
||||||
GOARCH="ppc64"
|
|
||||||
else
|
# XXX: Hack for checking ICE (bug #912152, gcc PR113204)
|
||||||
GOARCH="ppc64le"
|
has_version -b "sys-devel/gcc[debug]" && filter-lto
|
||||||
fi ;;
|
|
||||||
*) GOARCH="${arch}" ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
tc-export CC CXX
|
|
||||||
export GOARCH
|
|
||||||
export CGO_CFLAGS="${CGO_CFLAGS:-$CFLAGS}"
|
export CGO_CFLAGS="${CGO_CFLAGS:-$CFLAGS}"
|
||||||
export CGO_CPPFLAGS="${CGO_CPPFLAGS:-$CPPFLAGS}"
|
export CGO_CPPFLAGS="${CGO_CPPFLAGS:-$CPPFLAGS}"
|
||||||
export CGO_CXXFLAGS="${CGO_CXXFLAGS:-$CXXFLAGS}"
|
export CGO_CXXFLAGS="${CGO_CXXFLAGS:-$CXXFLAGS}"
|
||||||
export CGO_LDFLAGS="${CGO_LDFLAGS:-$LDFLAGS}"
|
export CGO_LDFLAGS="${CGO_LDFLAGS:-$LDFLAGS}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# @FUNCTION: go-env_goos
|
||||||
|
# @USAGE: [toolchain prefix]
|
||||||
|
# @DESCRIPTION:
|
||||||
|
# Returns the appropriate GOOS setting for the target operating system.
|
||||||
|
go-env_goos() {
|
||||||
|
local target=${1:-${CHOST}}
|
||||||
|
case "${target}" in
|
||||||
|
*-linux*) echo linux ;;
|
||||||
|
*-darwin*) echo darwin ;;
|
||||||
|
*-freebsd*) echo freebsd ;;
|
||||||
|
*-netbsd*) echo netbsd ;;
|
||||||
|
*-openbsd*) echo openbsd ;;
|
||||||
|
*-solaris*) echo solaris ;;
|
||||||
|
*-cygwin*|*-interix*|*-winnt*) echo windows ;;
|
||||||
|
*) die "unknown GOOS for ${target}" ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# @FUNCTION: go-env_goarch
|
||||||
|
# @USAGE: [toolchain prefix]
|
||||||
|
# @DESCRIPTION:
|
||||||
|
# Returns the appropriate GOARCH setting for the target architecture.
|
||||||
|
go-env_goarch() {
|
||||||
|
local target=${1:-${CHOST}}
|
||||||
|
# Some Portage arch names match Go.
|
||||||
|
local arch=$(tc-arch "${target}") cpu=${target%%-*}
|
||||||
|
case "${arch}" in
|
||||||
|
x86) echo 386 ;;
|
||||||
|
loong) echo loong64 ;;
|
||||||
|
*) case "${cpu}" in
|
||||||
|
aarch64*be) echo arm64be ;;
|
||||||
|
arm64) echo arm64 ;;
|
||||||
|
arm*b*) echo armbe ;;
|
||||||
|
mips64*l*) echo mips64le ;;
|
||||||
|
mips*l*) echo mipsle ;;
|
||||||
|
powerpc64le*) echo ppc64le ;;
|
||||||
|
arm64|s390x) echo "${cpu}" ;;
|
||||||
|
mips64*|riscv64*|sparc64*) echo "${arch}64" ;;
|
||||||
|
*) echo "${arch}" ;;
|
||||||
|
esac ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# @FUNCTION: go-env_go386
|
||||||
|
# @DESCRIPTION:
|
||||||
|
# Returns the appropriate GO386 setting for the CFLAGS in use.
|
||||||
|
go-env_go386() {
|
||||||
|
# Piggy-back off any existing CPU_FLAGS_X86 usage in the ebuild if
|
||||||
|
# it's there.
|
||||||
|
if in_iuse cpu_flags_x86_sse2 && use cpu_flags_x86_sse2 ; then
|
||||||
|
echo 'sse2'
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
if tc-cpp-is-true "defined(__SSE2__)" ${CFLAGS} ${CXXFLAGS} ; then
|
||||||
|
echo 'sse2'
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Go 1.16 dropped explicit support for 386 FP and relies on software
|
||||||
|
# emulation instead in the absence of SSE2.
|
||||||
|
echo 'softfloat'
|
||||||
|
}
|
||||||
|
|
||||||
|
# @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
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user