[Buildroot] [PATCH v2 1/2] package/go-bootstrap-stage4: add stage4 for go1.24 support
Christian Stewart
christian at aperture.us
Thu Apr 3 02:12:21 UTC 2025
This patch is in preparation for bumping the host-go package to go1.24, which
requires a minimum of Go1.22.6 for bootstrap.
See: https://go.dev/doc/go1.24#bootstrap
Signed-off-by: Christian Stewart <christian at aperture.us>
---
package/go/Config.in.host | 1 +
...ldvcs-false-when-building-go-bootstr.patch | 71 +++++++++++++++++++
package/go/go-bootstrap-stage4/Config.in.host | 4 ++
.../go-bootstrap-stage4.hash | 3 +
.../go-bootstrap-stage4.mk | 54 ++++++++++++++
5 files changed, 133 insertions(+)
create mode 100644 package/go/go-bootstrap-stage4/0001-cmd-dist-set-buildvcs-false-when-building-go-bootstr.patch
create mode 100644 package/go/go-bootstrap-stage4/Config.in.host
create mode 100644 package/go/go-bootstrap-stage4/go-bootstrap-stage4.hash
create mode 100644 package/go/go-bootstrap-stage4/go-bootstrap-stage4.mk
diff --git a/package/go/Config.in.host b/package/go/Config.in.host
index 7e354b3298..4fd98c2301 100644
--- a/package/go/Config.in.host
+++ b/package/go/Config.in.host
@@ -90,3 +90,4 @@ source "package/go/go-bin/Config.in.host"
source "package/go/go-bootstrap-stage1/Config.in.host"
source "package/go/go-bootstrap-stage2/Config.in.host"
source "package/go/go-bootstrap-stage3/Config.in.host"
+source "package/go/go-bootstrap-stage4/Config.in.host"
diff --git a/package/go/go-bootstrap-stage4/0001-cmd-dist-set-buildvcs-false-when-building-go-bootstr.patch b/package/go/go-bootstrap-stage4/0001-cmd-dist-set-buildvcs-false-when-building-go-bootstr.patch
new file mode 100644
index 0000000000..58f4581b02
--- /dev/null
+++ b/package/go/go-bootstrap-stage4/0001-cmd-dist-set-buildvcs-false-when-building-go-bootstr.patch
@@ -0,0 +1,71 @@
+From 6b05378097c6a386ed9912d2471976dc39504e86 Mon Sep 17 00:00:00 2001
+From: Christian Stewart <christian at aperture.us>
+Date: Thu, 27 Jul 2023 21:28:47 -0700
+Subject: [PATCH] cmd/dist: set buildvcs=false when building go-bootstrap
+
+When building go-bootstrap as part of the make.bash process, the cmd/dist
+invokes the bootstrap Go compiler to build the go_bootstrap tool:
+
+${GOROOT_BOOTSTRAP}/bin/go install -tags=math_big_pure_go compiler_bootstrap purego bootstrap/cmd/...
+
+If there is an invalid .git directory in a parent of ${GOROOT_BOOTSTRAP},
+make.bash will fail. Reproduction of the issue:
+
+ mkdir go-issue-61620
+ cd ./go-issue-61620
+ wget https://go.dev/dl/go1.19.11.src.tar.gz
+ mkdir go-bootstrap
+ tar -xf go1.19.11.src.tar.gz -C ./go-bootstrap --strip-components=1
+ cd ./go-bootstrap/src/
+ bash make.bash
+ cd ../../
+ wget https://go.dev/dl/go1.20.6.src.tar.gz
+ mkdir go
+ tar -xf go1.20.6.src.tar.gz -C ./go/ --strip-components=1
+ printf "gitdir: ../../does/not/exist/.git" > ./.git
+ cd ./go/src/
+ GOROOT_BOOTSTRAP=$(pwd)/../../go-bootstrap/ bash make.bash
+
+The build fails with the following error:
+
+ Building Go toolchain1 using [snip]/go-1.19.10.
+ error obtaining VCS status: exit status 128
+ Use -buildvcs=false to disable VCS stamping.
+ go tool dist: FAILED: [snip]/go-1.19.10/bin/go install -tags=math_big_pure_go \
+ compiler_bootstrap purego bootstrap/cmd/...: exit status 1
+
+This change unconditionally sets -buildvcs=false when compiling go-bootstrap. We
+don't need the revision information in those binaries anyway. Setting this flag
+was previously not done as we were unsure if the go-bootstrap compiler would be
+new enough to support the buildvcs build flag. Since Go 1.20.x, Go 1.19.x is the
+minimum version for go-bootstrap, and supports -buildvcs=false. We can now set
+-buildvcs=false without worrying about compatibility.
+
+Related: https://github.com/golang/go/issues/54852
+Fixes: https://github.com/golang/go/issues/61620
+
+Upstream: https://github.com/golang/go/pull/61621
+
+Signed-off-by: Christian Stewart <christian at aperture.us>
+Signed-off-by: Romain Naour <romain.naour at smile.fr>
+---
+ src/cmd/dist/buildtool.go | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/src/cmd/dist/buildtool.go b/src/cmd/dist/buildtool.go
+index a528d7aa76..3b411d6ebb 100644
+--- a/src/cmd/dist/buildtool.go
++++ b/src/cmd/dist/buildtool.go
+@@ -221,6 +221,9 @@ func bootstrapBuildTools() {
+ cmd := []string{
+ pathf("%s/bin/go", goroot_bootstrap),
+ "install",
++ // Fixes cases where an invalid .git is present in a parent of GOROOT_BOOTSTRAP.
++ // See: https://github.com/golang/go/issues/61620
++ "-buildvcs=false",
+ "-tags=math_big_pure_go compiler_bootstrap purego",
+ }
+ if vflag > 0 {
+--
+2.41.0
+
diff --git a/package/go/go-bootstrap-stage4/Config.in.host b/package/go/go-bootstrap-stage4/Config.in.host
new file mode 100644
index 0000000000..292486582c
--- /dev/null
+++ b/package/go/go-bootstrap-stage4/Config.in.host
@@ -0,0 +1,4 @@
+config BR2_PACKAGE_HOST_GO_BOOTSTRAP_STAGE4_ARCH_SUPPORTS
+ bool
+ default y
+ depends on BR2_PACKAGE_HOST_GO_BOOTSTRAP_STAGE3_ARCH_SUPPORTS
diff --git a/package/go/go-bootstrap-stage4/go-bootstrap-stage4.hash b/package/go/go-bootstrap-stage4/go-bootstrap-stage4.hash
new file mode 100644
index 0000000000..115dc10fc0
--- /dev/null
+++ b/package/go/go-bootstrap-stage4/go-bootstrap-stage4.hash
@@ -0,0 +1,3 @@
+# From https://go.dev/dl
+sha256 0ca1f1e37ea255e3ce283af3f4e628502fb444587da987a5bb96d6c6f15930d4 go1.23.8.src.tar.gz
+sha256 2d36597f7117c38b006835ae7f537487207d8ec407aa9d9980794b2030cbc067 LICENSE
diff --git a/package/go/go-bootstrap-stage4/go-bootstrap-stage4.mk b/package/go/go-bootstrap-stage4/go-bootstrap-stage4.mk
new file mode 100644
index 0000000000..e532718e52
--- /dev/null
+++ b/package/go/go-bootstrap-stage4/go-bootstrap-stage4.mk
@@ -0,0 +1,54 @@
+################################################################################
+#
+# go-bootstrap-stage4
+#
+################################################################################
+
+# Use last Go version that go-bootstrap-stage3 can build: v1.23.x
+# See https://go.dev/doc/go1.23#bootstrap
+GO_BOOTSTRAP_STAGE4_VERSION = 1.23.8
+GO_BOOTSTRAP_STAGE4_SITE = https://storage.googleapis.com/golang
+GO_BOOTSTRAP_STAGE4_SOURCE = go$(GO_BOOTSTRAP_STAGE4_VERSION).src.tar.gz
+
+GO_BOOTSTRAP_STAGE4_LICENSE = BSD-3-Clause
+GO_BOOTSTRAP_STAGE4_LICENSE_FILES = LICENSE
+
+# Use go-bootstrap-stage3 to bootstrap.
+HOST_GO_BOOTSTRAP_STAGE4_DEPENDENCIES = host-go-bootstrap-stage3
+
+HOST_GO_BOOTSTRAP_STAGE4_ROOT = $(HOST_DIR)/lib/go-$(GO_BOOTSTRAP_STAGE4_VERSION)
+
+# The go build system is not compatible with ccache, so use
+# HOSTCC_NOCCACHE. See https://github.com/golang/go/issues/11685.
+HOST_GO_BOOTSTRAP_STAGE4_MAKE_ENV = \
+ GO111MODULE=off \
+ GOCACHE=$(HOST_GO_HOST_CACHE) \
+ GOROOT_BOOTSTRAP=$(HOST_GO_BOOTSTRAP_STAGE3_ROOT) \
+ GOROOT_FINAL=$(HOST_GO_BOOTSTRAP_STAGE4_ROOT) \
+ GOROOT="$(@D)" \
+ GOBIN="$(@D)/bin" \
+ GOOS=linux \
+ CC=$(HOSTCC_NOCCACHE) \
+ CXX=$(HOSTCXX_NOCCACHE) \
+ CGO_ENABLED=0
+
+define HOST_GO_BOOTSTRAP_STAGE4_BUILD_CMDS
+ cd $(@D)/src && \
+ $(HOST_GO_BOOTSTRAP_STAGE4_MAKE_ENV) ./make.bash $(if $(VERBOSE),-v)
+endef
+
+define HOST_GO_BOOTSTRAP_STAGE4_INSTALL_CMDS
+ $(INSTALL) -D -m 0755 $(@D)/bin/go $(HOST_GO_BOOTSTRAP_STAGE4_ROOT)/bin/go
+ $(INSTALL) -D -m 0755 $(@D)/bin/gofmt $(HOST_GO_BOOTSTRAP_STAGE4_ROOT)/bin/gofmt
+
+ cp -a $(@D)/lib $(HOST_GO_BOOTSTRAP_STAGE4_ROOT)/
+
+ mkdir -p $(HOST_GO_BOOTSTRAP_STAGE4_ROOT)/pkg
+ cp -a $(@D)/pkg/include $(HOST_GO_BOOTSTRAP_STAGE4_ROOT)/pkg/
+ cp -a $(@D)/pkg/tool $(HOST_GO_BOOTSTRAP_STAGE4_ROOT)/pkg/
+
+ # The Go sources must be installed to the host/ tree for the Go stdlib.
+ cp -a $(@D)/src $(HOST_GO_BOOTSTRAP_STAGE4_ROOT)/
+endef
+
+$(eval $(host-generic-package))
--
2.39.5
More information about the buildroot
mailing list