* [gentoo-dev] [PATCH V2 0/4] eclass/go-env.eclass: add helper to enable cross compiling
@ 2023-11-19 12:30 James Le Cuirot
2023-11-19 12:30 ` [gentoo-dev] [PATCH 1/4] eclass/go-env.eclass: add helper to set compile env James Le Cuirot
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: James Le Cuirot @ 2023-11-19 12:30 UTC (permalink / raw)
To: gentoo-dev
See the GitHub link for earlier discussion. This still doesn't work for cross-prefix
builds, unless you set CGO_ENABLED=1, but fixing that involves different code and can
be done later.
https://github.com/gentoo/gentoo/pull/33539
^ permalink raw reply [flat|nested] 5+ messages in thread
* [gentoo-dev] [PATCH 1/4] eclass/go-env.eclass: add helper to set compile env
2023-11-19 12:30 [gentoo-dev] [PATCH V2 0/4] eclass/go-env.eclass: add helper to enable cross compiling James Le Cuirot
@ 2023-11-19 12:30 ` James Le Cuirot
2023-11-19 12:30 ` [gentoo-dev] [PATCH 2/4] eclass/go-module.eclass: export compile env in src_unpack James Le Cuirot
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: James Le Cuirot @ 2023-11-19 12:30 UTC (permalink / raw)
To: gentoo-dev; +Cc: Thilo Fromm, James Le Cuirot
From: Thilo Fromm <thilo.alexander@gmail.com>
This change adds a helper function to explicitly set CC, CXX, and
GOARCH, and carrying over CFLAGS, LDFLAGS and friends to CGO
equivalents, to provide a minimal sane compile environment for Go.
It enables Go builds to play nice with crossdev's wrappers for
emerge/ebuild etc. Previously, Go ebuilds emitted binaries for the host
architecture.
For example, when running on an x86_64 host:
emerge-aarch64-cross-linux-gnu foo
will now correctly emerge Go package "foo" for aarch64 instead of
x86_64.
The eclass provides a single helper function
go-env_set_compile_environment()
intended to be called by other Go eclasses in an early build stage.
Ebuilds may also explicitly call this function.
Signed-off-by: Thilo Fromm <thilo.alexander@gmail.com>
Signed-off-by: James Le Cuirot <chewi@gentoo.org>
---
eclass/go-env.eclass | 48 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
create mode 100644 eclass/go-env.eclass
diff --git a/eclass/go-env.eclass b/eclass/go-env.eclass
new file mode 100644
index 000000000000..ba4f6c3fbb59
--- /dev/null
+++ b/eclass/go-env.eclass
@@ -0,0 +1,48 @@
+# Copyright 2023 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: go-env.eclass
+# @MAINTAINER:
+# Flatcar Linux Maintainers <infra@flatcar-linux.org>
+# @AUTHOR:
+# 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.
+# Intended to be called by other Go eclasses in an early build stage, e.g. src_unpack.
+
+if [[ -z ${_GO_ENV_ECLASS} ]]; then
+_GO_ENV_ECLASS=1
+
+inherit toolchain-funcs
+
+# @FUNCTION: go-env_set_compile_environment
+# @DESCRIPTION:
+# Set up basic compile environment: CC, CXX, and GOARCH.
+# 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.
+# (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 CGO_CFLAGS="${CGO_CFLAGS:-$CFLAGS}"
+ export CGO_CPPFLAGS="${CGO_CPPFLAGS:-$CPPFLAGS}"
+ export CGO_CXXFLAGS="${CGO_CXXFLAGS:-$CXXFLAGS}"
+ export CGO_LDFLAGS="${CGO_LDFLAGS:-$LDFLAGS}"
+}
+
+fi
--
2.42.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [gentoo-dev] [PATCH 2/4] eclass/go-module.eclass: export compile env in src_unpack
2023-11-19 12:30 [gentoo-dev] [PATCH V2 0/4] eclass/go-env.eclass: add helper to enable cross compiling James Le Cuirot
2023-11-19 12:30 ` [gentoo-dev] [PATCH 1/4] eclass/go-env.eclass: add helper to set compile env James Le Cuirot
@ 2023-11-19 12:30 ` James Le Cuirot
2023-11-19 12:30 ` [gentoo-dev] [PATCH 3/4] eclass/golang-vcs-snapshot.eclass: set up compile env James Le Cuirot
2023-11-19 12:30 ` [gentoo-dev] [PATCH 4/4] eclass/golang-vcs.eclass: " James Le Cuirot
3 siblings, 0 replies; 5+ messages in thread
From: James Le Cuirot @ 2023-11-19 12:30 UTC (permalink / raw)
To: gentoo-dev; +Cc: Thilo Fromm, James Le Cuirot
From: Thilo Fromm <thilo.alexander@gmail.com>
This change calls go-env_set_compile_environment in go-module's
src_unpack to set up a sane compile environment early in the go build
process. This un-breaks cross compiling of all golang ebuilds that
inherit go-module.
Signed-off-by: Thilo Fromm <thilo.alexander@gmail.com>
Signed-off-by: James Le Cuirot <chewi@gentoo.org>
---
eclass/go-module.eclass | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/eclass/go-module.eclass b/eclass/go-module.eclass
index 6c58d7f26f07..701d36e012e2 100644
--- a/eclass/go-module.eclass
+++ b/eclass/go-module.eclass
@@ -68,7 +68,7 @@ esac
if [[ -z ${_GO_MODULE_ECLASS} ]]; then
_GO_MODULE_ECLASS=1
-inherit multiprocessing toolchain-funcs
+inherit multiprocessing toolchain-funcs go-env
if [[ ! ${GO_OPTIONAL} ]]; then
BDEPEND=">=dev-lang/go-1.18"
@@ -363,6 +363,7 @@ go-module_setup_proxy() {
# local go proxy. This mode is deprecated.
# 2. Otherwise, if EGO_VENDOR is set, bail out, as this functionality was removed.
# 3. Otherwise, call 'ego mod verify' and then do a normal unpack.
+# Set compile env via go-env.
go-module_src_unpack() {
if use amd64 || use arm || use arm64 ||
( use ppc64 && [[ $(tc-endian) == "little" ]] ) || use s390 || use x86; then
@@ -386,6 +387,8 @@ go-module_src_unpack() {
${nf} ego mod verify
fi
fi
+
+ go-env_set_compile_environment
}
# @FUNCTION: _go-module_src_unpack_gosum
--
2.42.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [gentoo-dev] [PATCH 3/4] eclass/golang-vcs-snapshot.eclass: set up compile env
2023-11-19 12:30 [gentoo-dev] [PATCH V2 0/4] eclass/go-env.eclass: add helper to enable cross compiling James Le Cuirot
2023-11-19 12:30 ` [gentoo-dev] [PATCH 1/4] eclass/go-env.eclass: add helper to set compile env James Le Cuirot
2023-11-19 12:30 ` [gentoo-dev] [PATCH 2/4] eclass/go-module.eclass: export compile env in src_unpack James Le Cuirot
@ 2023-11-19 12:30 ` James Le Cuirot
2023-11-19 12:30 ` [gentoo-dev] [PATCH 4/4] eclass/golang-vcs.eclass: " James Le Cuirot
3 siblings, 0 replies; 5+ messages in thread
From: James Le Cuirot @ 2023-11-19 12:30 UTC (permalink / raw)
To: gentoo-dev; +Cc: Thilo Fromm, James Le Cuirot
From: Thilo Fromm <thilo.alexander@gmail.com>
This change calls go-env_set_compile_environment in
golang-vcs-snapshot's src_unpack to set up a sane compile environment
early in the go build process. This un-breaks cross compiling of all
golang ebuilds that inherit golang-vcs-snapshot.
Signed-off-by: Thilo Fromm <thilo.alexander@gmail.com>
Signed-off-by: James Le Cuirot <chewi@gentoo.org>
---
eclass/golang-vcs-snapshot.eclass | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/eclass/golang-vcs-snapshot.eclass b/eclass/golang-vcs-snapshot.eclass
index 9c199bbbd8c5..d34b8a6e913d 100644
--- a/eclass/golang-vcs-snapshot.eclass
+++ b/eclass/golang-vcs-snapshot.eclass
@@ -52,7 +52,7 @@ esac
if [[ -z ${_GOLANG_VCS_SNAPSHOT_ECLASS} ]]; then
_GOLANG_VCS_SNAPSHOT_ECLASS=1
-inherit golang-base
+inherit golang-base go-env
# @ECLASS_VARIABLE: EGO_VENDOR
# @DESCRIPTION:
@@ -92,6 +92,7 @@ _golang-vcs-snapshot_dovendor() {
# @FUNCTION: golang-vcs-snapshot_src_unpack
# @DESCRIPTION:
# Extract the first archive from ${A} to the appropriate location for GOPATH.
+# Set compile env via go-env.
golang-vcs-snapshot_src_unpack() {
local lib vendor_path x
ego_pn_check
@@ -117,6 +118,8 @@ golang-vcs-snapshot_src_unpack() {
fi
done
fi
+
+ go-env_set_compile_environment
}
fi
--
2.42.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [gentoo-dev] [PATCH 4/4] eclass/golang-vcs.eclass: set up compile env
2023-11-19 12:30 [gentoo-dev] [PATCH V2 0/4] eclass/go-env.eclass: add helper to enable cross compiling James Le Cuirot
` (2 preceding siblings ...)
2023-11-19 12:30 ` [gentoo-dev] [PATCH 3/4] eclass/golang-vcs-snapshot.eclass: set up compile env James Le Cuirot
@ 2023-11-19 12:30 ` James Le Cuirot
3 siblings, 0 replies; 5+ messages in thread
From: James Le Cuirot @ 2023-11-19 12:30 UTC (permalink / raw)
To: gentoo-dev; +Cc: Thilo Fromm, James Le Cuirot
From: Thilo Fromm <thilo.alexander@gmail.com>
This change calls go-env_set_compile_environment in golang-vcs's
src_unpack to set up a sane compile environment early in the go build
process. This un-breaks cross compiling of all golang ebuilds that
inherit golang-vcs.
Signed-off-by: Thilo Fromm <thilo.alexander@gmail.com>
Closes: https://github.com/gentoo/gentoo/pull/33539
Signed-off-by: James Le Cuirot <chewi@gentoo.org>
---
eclass/golang-vcs.eclass | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/eclass/golang-vcs.eclass b/eclass/golang-vcs.eclass
index 7558db4776cb..6f7a837bc15f 100644
--- a/eclass/golang-vcs.eclass
+++ b/eclass/golang-vcs.eclass
@@ -20,7 +20,7 @@ esac
if [[ -z ${_GOLANG_VCS_ECLASS} ]]; then
_GOLANG_VCS_ECLASS=1
-inherit estack golang-base
+inherit estack golang-base go-env
PROPERTIES+=" live"
@@ -63,6 +63,7 @@ PROPERTIES+=" live"
# @INTERNAL
# @DESCRIPTION:
# Create EGO_STORE_DIR if necessary.
+# Set compile env via go-env.
_golang-vcs_env_setup() {
debug-print-function ${FUNCNAME} "$@"
@@ -84,6 +85,8 @@ _golang-vcs_env_setup() {
mkdir -p "${WORKDIR}/${P}/src" ||
die "${ECLASS}: unable to create ${WORKDIR}/${P}"
return 0
+
+ go-env_set_compile_environment
}
# @FUNCTION: _golang-vcs_fetch
--
2.42.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-11-19 12:35 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-19 12:30 [gentoo-dev] [PATCH V2 0/4] eclass/go-env.eclass: add helper to enable cross compiling James Le Cuirot
2023-11-19 12:30 ` [gentoo-dev] [PATCH 1/4] eclass/go-env.eclass: add helper to set compile env James Le Cuirot
2023-11-19 12:30 ` [gentoo-dev] [PATCH 2/4] eclass/go-module.eclass: export compile env in src_unpack James Le Cuirot
2023-11-19 12:30 ` [gentoo-dev] [PATCH 3/4] eclass/golang-vcs-snapshot.eclass: set up compile env James Le Cuirot
2023-11-19 12:30 ` [gentoo-dev] [PATCH 4/4] eclass/golang-vcs.eclass: " James Le Cuirot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox