Openembedded Core Discussions
 help / color / mirror / Atom feed
* [PATCH] go: Allow bootstrapping using host go compiler
@ 2019-04-12 12:30 Daniel Thompson
  2019-04-12 12:39 ` Richard Purdie
  2019-04-12 19:45 ` Adrian Bunk
  0 siblings, 2 replies; 9+ messages in thread
From: Daniel Thompson @ 2019-04-12 12:30 UTC (permalink / raw)
  To: openembedded-core

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@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



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

end of thread, other threads:[~2019-04-24 14:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-12 12:30 [PATCH] go: Allow bootstrapping using host go compiler Daniel Thompson
2019-04-12 12:39 ` Richard Purdie
2019-04-12 13:16   ` Daniel Thompson
2019-04-12 13:34     ` richard.purdie
2019-04-12 14:08       ` Daniel Thompson
2019-04-12 18:26     ` Randy MacLeod
2019-04-12 19:10       ` Adrian Bunk
2019-04-12 19:45 ` Adrian Bunk
2019-04-24 14:36   ` Daniel Thompson

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