golang: add option to skip building bootstrap

Introduce a new configuration option - GOLANG_BUILD_BOOTSTRAP - that
defaults to enabled:

- When enabled, build the local bootstrap instead of using an external
  one for host Go. If GOLANG_EXTERNAL_BOOTSTRAP_ROOT is set, skip the
  initial 1.4 step.

- When disabled, let Go auto-detect the toolchain or use the toolchain
  specified in GOLANG_EXTERNAL_BOOTSTRAP_ROOT to skip building the
  bootstrap and build host Go using that toolchain directly. Configured
  toolchain must be compatible with the current version of Go.

HOST_BUILD_DEPENDS cannot be conditional, so some Makefile juggling is
needed.

Put menu config under bootstrap only.

Remove unnecessary package-related flags from host-only bootstrap.

Signed-off-by: George Sapkin <george@sapk.in>
This commit is contained in:
George Sapkin
2026-02-02 03:11:01 +02:00
parent e30561dd11
commit 9d8ac9df17
4 changed files with 70 additions and 46 deletions

View File

@@ -1,33 +0,0 @@
menu "Configuration"
config GOLANG_EXTERNAL_BOOTSTRAP_ROOT
string "External bootstrap Go root directory"
default ""
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.
config GOLANG_BUILD_CACHE_DIR
string "Go build cache directory"
default ""
help
Store the Go build cache in this directory.
If not set, uses '$(TMP_DIR)/go-build'.
config GOLANG_MOD_CACHE_WORLD_READABLE
bool "Ensure Go module cache is world-readable"
default n
config GOLANG_SPECTRE
bool "Enable Spectre mitigations"
default n
depends on x86_64
help
Currently only available for x86-64 (amd64).
endmenu

View File

@@ -0,0 +1,47 @@
menu "Configuration"
config GOLANG_EXTERNAL_BOOTSTRAP_ROOT
string "External bootstrap Go root directory"
default ""
help
Path to a working Go tree (>= Go 1.4), with bin, pkg, and src
subdirectories and the Go compiler in bin/go.
If set, the existing Go installation will be used to compile host
(buildroot) Go.
Leave blank to compile the default bootstrap Go.
config GOLANG_BUILD_BOOTSTRAP
bool "Build bootstrap instead of using an external one"
default y
help
When enabled, build the local bootstrap instead of using an external one
for host Go. If 'External bootstrap Go root directory' is set, skip the
initial 1.4 step.
When disabled, let Go auto-detect the toolchain or use the toolchain
specified in 'External bootstrap Go root directory' to skip building the
bootstrap and build host Go using that toolchain directly. Configured
toolchain must be compatible with the current version of Go.
config GOLANG_BUILD_CACHE_DIR
string "Go build cache directory"
default ""
help
Path where Go should store its build cache.
If not set, uses '$(TMP_DIR)/go-build'.
config GOLANG_MOD_CACHE_WORLD_READABLE
bool "Ensure Go module cache is world-readable"
default n
config GOLANG_SPECTRE
bool "Enable Spectre mitigations"
default n
depends on x86_64
help
Currently only available for x86-64 (amd64).
endmenu

View File

@@ -28,10 +28,6 @@ PKG_LICENSE:=BSD-3-Clause
PKG_LICENSE_FILES:=LICENSE
PKG_CPE_ID:=cpe:/a:golang:go
PKG_BUILD_DIR:=$(BUILD_DIR)/go-$(PKG_VERSION)
PKG_BUILD_PARALLEL:=1
PKG_BUILD_FLAGS:=no-mips16
PKG_HOST_ONLY:=1
HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/go-$(PKG_VERSION)
@@ -119,9 +115,9 @@ ifeq ($(GO_TARGET_SPECTRE_SUPPORTED),1)
endif
define Package/golang-bootstrap
$(call GoPackage/GoSubMenu)
TITLE:=Go programming language (bootstrap)
DEPENDS:=$(GO_ARCH_DEPENDS)
HIDDEN:=1
endef
define Package/golang-bootstrap/description
@@ -138,7 +134,7 @@ define Package/golang-bootstrap/description
endef
define Package/golang-bootstrap/config
source "$(SOURCE)/../Config.in"
source "$(SOURCE)/Config.in"
endef
BOOTSTRAP_ROOT_DIR:=$(call qstrip,$(CONFIG_GOLANG_EXTERNAL_BOOTSTRAP_ROOT))
@@ -161,6 +157,9 @@ ifeq ($(BOOTSTRAP_ROOT_DIR),)
$(eval $(call GoCompiler/AddProfile,Bootstrap,$(BOOTSTRAP_BUILD_DIR),,bootstrap,$(GO_HOST_OS_ARCH)))
endif
# Skip configuring and downloading stages when building is not configured
ifeq ($(CONFIG_GOLANG_BUILD_BOOTSTRAP),y)
# Bootstrap 1.17
define Download/golang-bootstrap-1.17
@@ -193,6 +192,8 @@ Hooks/HostPrepare/Post+=Bootstrap-1.20/Prepare
$(eval $(call GoCompiler/AddProfile,Bootstrap-1.20,$(BOOTSTRAP_1_20_BUILD_DIR),,bootstrap-1.20,$(GO_HOST_OS_ARCH)))
endif
# Host
ifeq ($(GO_HOST_PIE_SUPPORTED),1)
@@ -202,7 +203,9 @@ endif
# When using GO_LDFLAGS to set buildmode=pie, the PIE install suffix does not
# apply (we also delete the std lib during Host/Install)
$(eval $(call GoCompiler/AddProfile,Host,$(HOST_BUILD_DIR),$(HOST_GO_PREFIX),$(HOST_GO_VERSION_ID),$(GO_HOST_OS_ARCH)))
ifeq ($(CONFIG_GOLANG_BUILD_BOOTSTRAP),y)
$(eval $(call GoCompiler/AddProfile,Host,$(HOST_BUILD_DIR),$(HOST_GO_PREFIX),$(HOST_GO_VERSION_ID),$(GO_HOST_OS_ARCH)))
endif
HOST_GO_VARS= \
GOHOSTARCH="$(GO_HOST_ARCH)" \
@@ -268,5 +271,11 @@ define Host/Uninstall
$(call GoCompiler/Host/Uninstall)
endef
$(eval $(call HostBuild))
# Skip downloading and building final bootstrap when building is not configured
ifeq ($(CONFIG_GOLANG_BUILD_BOOTSTRAP),y)
$(eval $(call HostBuild))
else
host-compile:
endif
$(eval $(call BuildPackage,golang-bootstrap))

View File

@@ -8,7 +8,11 @@ HOST_GO_PREFIX:=$(STAGING_DIR_HOSTPKG)
HOST_GO_VERSION_ID:=$(GO_VERSION_MAJOR_MINOR)
HOST_GO_ROOT:=$(HOST_GO_PREFIX)/lib/go-$(HOST_GO_VERSION_ID)
BOOTSTRAP_DIR:=$(HOST_GO_PREFIX)/lib/go-$(GO_BOOTSTRAP_VERSION)
ifeq ($(CONFIG_GOLANG_BUILD_BOOTSTRAP),y)
BOOTSTRAP_DIR:=$(HOST_GO_PREFIX)/lib/go-$(GO_BOOTSTRAP_VERSION)
else
BOOTSTRAP_DIR:=$(call qstrip,$(CONFIG_GOLANG_EXTERNAL_BOOTSTRAP_ROOT))
endif
include ../golang-compiler.mk
include ../golang-package.mk
@@ -57,6 +61,7 @@ define Package/$(PKG_NAME)
TITLE+= (compiler)
DEPENDS+= +golang$(GO_VERSION_MAJOR_MINOR)-src
EXTRA_DEPENDS:=golang$(GO_VERSION_MAJOR_MINOR)-src (=$(PKG_VERSION)-r$(PKG_RELEASE))
MDEPENDS:=+golang-bootstrap
PROVIDES:=@golang
$(if $(filter $(GO_DEFAULT_VERSION),$(GO_VERSION_MAJOR_MINOR)),DEFAULT_VARIANT:=1)
ALTERNATIVES:=\
@@ -71,10 +76,6 @@ define Package/$(PKG_NAME)/description
for the Go programming language.
endef
define Package/$(PKG_NAME)/config
source "$(SOURCE)/../Config.in"
endef
define Package/$(PKG_NAME)-doc
$(call Package/$(PKG_NAME)/Default)
TITLE+= (documentation)