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_co