From 49a2ff493b46029e5acc1a902a1e850307bc20bc Mon Sep 17 00:00:00 2001 From: Jeffery To Date: Tue, 12 May 2020 17:42:48 +0800 Subject: [PATCH] golang: Add option to use external bootstrap Go The default bootstrap Go (Go 1.4) can only be compiled on a limited number of platforms compared to newer versions of Go. This adds a config option to use an external bootstrap Go, e.g. installed through the build system's package manager or downloaded from golang.org. See: https://github.com/openwrt/packages/issues/11731 Signed-off-by: Jeffery To --- lang/golang/golang/Makefile | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/lang/golang/golang/Makefile b/lang/golang/golang/Makefile index 3df43d3de..25d1904a6 100644 --- a/lang/golang/golang/Makefile +++ b/lang/golang/golang/Makefile @@ -154,6 +154,23 @@ This package provides an assembler, compiler, linker, and compiled libraries for the Go programming language. endef +define Package/golang/config +menu "Configuration" + +config GOLANG_EXTERNAL_BOOTSTRAP_ROOT + string "External bootstrap Go root directory" + help + Path to a working Go tree (>= Go 1.4), with bin, pkg, and src + subdirectories and the Go compiler at bin/go. + + If specified, the existing Go installation will be used to + compile host (buildroot) Go. + + Leave blank to compile the default bootstrap Go. + +endmenu +endef + define Package/golang-doc $(call Package/golang/Default) TITLE+= (documentation) @@ -177,22 +194,29 @@ This package provides the Go programming language source files needed for cross-compilation. endef +EXTERNAL_BOOTSTRAP_DIR:=$(call qstrip,$(CONFIG_GOLANG_EXTERNAL_BOOTSTRAP_ROOT)) +USE_DEFAULT_BOOTSTRAP:=$(if $(EXTERNAL_BOOTSTRAP_DIR),,1) + define Download/golang-bootstrap FILE:=$(BOOTSTRAP_SOURCE) URL:=$(BOOTSTRAP_SOURCE_URL) HASH:=$(BOOTSTRAP_HASH) endef -$(eval $(call Download,golang-bootstrap)) -$(eval $(call GoCompiler/AddProfile,Bootstrap,$(BOOTSTRAP_BUILD_DIR),,bootstrap,$(GO_HOST_OS_ARCH))) $(eval $(call GoCompiler/AddProfile,Host,$(HOST_BUILD_DIR),$(HOST_GO_PREFIX),$(HOST_GO_VERSION_ID),$(GO_HOST_OS_ARCH),$(HOST_GO_INSTALL_SUFFIX))) $(eval $(call GoCompiler/AddProfile,Package,$(PKG_BUILD_DIR),$(PKG_GO_PREFIX),$(PKG_GO_VERSION_ID),$(GO_OS_ARCH),$(PKG_GO_INSTALL_SUFFIX))) -define Host/Prepare +ifeq ($(USE_DEFAULT_BOOTSTRAP),1) + $(eval $(call GoCompiler/AddProfile,Bootstrap,$(BOOTSTRAP_BUILD_DIR),,bootstrap,$(GO_HOST_OS_ARCH))) + + $(eval $(call Download,golang-bootstrap)) + + define Host/Prepare $(call Host/Prepare/Default) mkdir -p $(BOOTSTRAP_BUILD_DIR) $(BOOTSTRAP_UNPACK) -endef + endef +endif # when https://github.com/golang/go/issues/31544 is fixed, # we should be able to set GO_LDFLAGS=-buildmode=pie for host make @@ -212,7 +236,7 @@ define Host/Compile ) $(call GoCompiler/Host/Make, \ - GOROOT_BOOTSTRAP=$(BOOTSTRAP_BUILD_DIR) \ + GOROOT_BOOTSTRAP=$(if $(USE_DEFAULT_BOOTSTRAP),$(BOOTSTRAP_BUILD_DIR),$(EXTERNAL_BOOTSTRAP_DIR)) \ GOCACHE=$(HOST_GO_CACHE_DIR) \ CC=$(HOSTCC_NOCACHE) \ CXX=$(HOSTCXX_NOCACHE) \