[OE-core] [PATCH] go: Allow bootstrapping using host go compiler

Daniel Thompson daniel.thompson at linaro.org
Fri Apr 12 12:30:46 UTC 2019


Currently go-native bootstraps without any dependency on the host go
compiler by building go-1.4 (the last version written in C) and using
that to build a more recent version of go. This does not work on host
architectures, such as arm64, that are not supported by go-1.4. To
support these host architectures we must rely on an existing host go
compiler and use that to build go-native instead.

Rather than add arm64 specific code that forces the use of the host go
compiler, we use an architecture neutral approach based on adopting the
host go compiler if it is both recent enough and the output of `go env
GOROOT` passes basic sanity testing.

Signed-off-by: Daniel Thompson <daniel.thompson at linaro.org>
---
 meta/conf/bitbake.conf                 |  4 +++
 meta/recipes-devtools/go/go-native.inc | 38 ++++++++++++++++++++++++--
 2 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf
index 7f8b043cc4..61a3069579 100644
--- a/meta/conf/bitbake.conf
+++ b/meta/conf/bitbake.conf
@@ -514,6 +514,10 @@ HOSTTOOLS_NONFATAL += "bzr"
 # Used by ssh fetcher
 HOSTTOOLS_NONFATAL += "scp"
 
+# Used to bootstrap go more quickly (and to support host architectures not
+# supported by go-1.4)
+HOSTTOOLS_NONFATAL += "go"
+
 CCACHE ??= ""
 
 TOOLCHAIN_OPTIONS = " --sysroot=${STAGING_DIR_TARGET}"
diff --git a/meta/recipes-devtools/go/go-native.inc b/meta/recipes-devtools/go/go-native.inc
index 207708745e..adf1666e29 100644
--- a/meta/recipes-devtools/go/go-native.inc
+++ b/meta/recipes-devtools/go/go-native.inc
@@ -10,14 +10,46 @@ CC = "${@d.getVar('BUILD_CC').strip()}"
 
 GOMAKEARGS ?= "--no-banner"
 
+check_host_go () {
+	local GOROOT="`go env GOROOT`"
+	if [ ! -x "$GOROOT/bin/go" ]
+	then
+		return 1
+	fi
+
+	local GOVERSION=`$GOROOT/bin/go version | tr ' ' '\n' | grep ^go[0-9] | cut -b3-`
+	local GOMAJOR=`echo $GOVERSION | cut -d. -f 1`
+	local GOMINOR=`echo $GOVERSION | cut -d. -f 2`
+	if [ "`echo $GOMAJOR.$GOMINOR | tr -d 0-9`" != "." ] || \
+	   [ "$GOMAJOR" -lt 1 ] || \
+	   [ "$GOMAJOR" -eq 1 -a "$GOMINOR" -lt 4 ]
+	then
+		return 1
+	fi
+
+	return 0
+}
+
 do_configure() {
-	cd ${WORKDIR}/go1.4/go/src
-	CGO_ENABLED=0 GOROOT=${WORKDIR}/go1.4/go ./make.bash
+	if check_host_go
+	then
+		bbplain "Bootstrap using host go compiler: `go env GOROOT`"
+	else
+		cd ${WORKDIR}/go1.4/go/src
+		CGO_ENABLED=0 GOROOT=${WORKDIR}/go1.4/go ./make.bash
+	fi
 }
+do_configure[cleandirs] =+ "${GOTMPDIR}"
 
 do_compile() {
 	export GOROOT_FINAL="${libdir_native}/go"
-	export GOROOT_BOOTSTRAP="${WORKDIR}/go1.4/go"
+
+	if check_host_go
+	then
+		export GOROOT_BOOTSTRAP="`go env GOROOT`"
+	else
+		export GOROOT_BOOTSTRAP="${WORKDIR}/go1.4/go"
+	fi
 
 	cd src
 	./make.bash ${GOMAKEARGS}
-- 
2.20.1



More information about the Openembedded-core mailing list