Skip to content

Commit

Permalink
package/go: use host compiler when go-bootstrap unsupported
Browse files Browse the repository at this point in the history
All Go compiler versions > 1.4.x (old) are written in Go, and require a existing
compiled Go version to use to build from source.

https://golang.org/doc/install/source#bootstrapFromSource

The process for "bootstrapping" the Go compiler in Buildroot is:

1. Compile a C/C++ cross-compiler (gcc) as the host toolchain.
2. Build go-bootstrap (which is Go 1.4.x and written in C)
3. Build go 1.16.x (written in Go) using go-bootstrap.

The problem is that step 2 - build go-bootstrap - does not work on 64-bit arm.
The Go compiler from 1.4.x is compatible with x86, x86_64, and arm (32 bit).

This means that arm64 host machines will skip building Go and all go-based
packages like Docker.

This patch instead uses the host Go compiler to bootstrap host-go when
BR2_PACKAGE_HOST_GO_BOOTSTRAP_ARCH_SUPPORTS is not set. This is similar to how
the host GCC is used to bootstrap the Buildroot toolchain.

Signed-off-by: Christian Stewart <christian@paral.in>

---

WIP:

https://patchwork.ozlabs.org/project/buildroot/patch/20210622024337.3009417-1-christian@paral.in/
  • Loading branch information
paralin committed Jun 22, 2021
1 parent aea53e3 commit 2df564c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 6 additions & 0 deletions package/go-bootstrap/go-bootstrap.mk
Expand Up @@ -19,7 +19,13 @@ GO_BOOTSTRAP_LICENSE_FILES = LICENSE
# host-go-bootstrap.
HOST_GO_BOOTSTRAP_DEPENDENCIES = toolchain

# If we do not support this architecture with go-bootstrap, depend on the host
# Go compiler to bootstrap the host-go compiler instead.
ifeq ($(BR2_PACKAGE_HOST_GO_BOOTSTRAP_ARCH_SUPPORTS),y)
HOST_GO_BOOTSTRAP_ROOT = $(HOST_DIR)/lib/go-$(GO_BOOTSTRAP_VERSION)
else
HOST_GO_BOOTSTRAP_ROOT = /usr/lib/go
endif

# The go build system is not compatable with ccache, so use HOSTCC_NOCCACHE
# here. See https://github.com/golang/go/issues/11685.
Expand Down
2 changes: 0 additions & 2 deletions package/go/Config.in.host
Expand Up @@ -2,7 +2,6 @@
config BR2_PACKAGE_HOST_GO_TARGET_ARCH_SUPPORTS
bool
default y
depends on BR2_PACKAGE_HOST_GO_BOOTSTRAP_ARCH_SUPPORTS
depends on (BR2_arm && BR2_TOOLCHAIN_SUPPORTS_PIE) || BR2_aarch64 \
|| BR2_i386 || BR2_x86_64 || BR2_powerpc64le \
|| BR2_mips64 || BR2_mips64el || BR2_riscv || BR2_s390x
Expand All @@ -28,4 +27,3 @@ config BR2_PACKAGE_HOST_GO_TARGET_CGO_LINKING_SUPPORTS
config BR2_PACKAGE_HOST_GO_HOST_ARCH_SUPPORTS
bool
default y
depends on BR2_PACKAGE_HOST_GO_BOOTSTRAP_ARCH_SUPPORTS
6 changes: 5 additions & 1 deletion package/go/go.mk
Expand Up @@ -12,7 +12,11 @@ GO_LICENSE = BSD-3-Clause
GO_LICENSE_FILES = LICENSE
GO_CPE_ID_VENDOR = golang

HOST_GO_DEPENDENCIES = host-go-bootstrap
# Depend on the host Go compiler if go-bootstrap is not available.
ifeq ($(BR2_PACKAGE_HOST_GO_BOOTSTRAP_ARCH_SUPPORTS),y)
HOST_GO_DEPENDENCIES += host-go-bootstrap
endif

HOST_GO_GOPATH = $(HOST_DIR)/usr/share/go-path
HOST_GO_HOST_CACHE = $(HOST_DIR)/usr/share/host-go-cache
HOST_GO_ROOT = $(HOST_DIR)/lib/go
Expand Down

0 comments on commit 2df564c

Please sign in to comment.