From 9499a43f0ae6250ffc88e28d2d9dc7956278a9bb Mon Sep 17 00:00:00 2001
From: Kirill <g4s8.public@gmail.com>
Date: Wed, 9 Aug 2023 18:32:14 +0400
Subject: [PATCH] go: update to 1.21.0.

---
 srcpkgs/go/patches/fix-32bit-tests.patch | 10 ++++----
 srcpkgs/go/patches/fix-musl-tests.patch  | 32 ++++++++++++------------
 srcpkgs/go/patches/fix-tests.patch       | 27 +++++++++++++++++---
 srcpkgs/go/template                      | 19 +++++---------
 4 files changed, 51 insertions(+), 37 deletions(-)

diff --git a/srcpkgs/go/patches/fix-32bit-tests.patch b/srcpkgs/go/patches/fix-32bit-tests.patch
index f5d8083b19f..7ee2df7187e 100644
--- a/srcpkgs/go/patches/fix-32bit-tests.patch
+++ b/srcpkgs/go/patches/fix-32bit-tests.patch
@@ -1,13 +1,13 @@
-Fixes go1.19 error on i686 - 
-    runtime/cgo(.text): unknown symbol __stack_chk_fail_local in pcrel
+Fixes go1.21 error on i686 -
+  runtime/cgo(.text): unknown symbol __stack_chk_fail_local in pcrel
 
 --- a/go/src/cmd/go/script_test.go
 +++ b/go/src/cmd/go/script_test.go
-@@ -148,6 +148,7 @@ var extraEnvKeys = []string{
+@@ -285,6 +285,7 @@ var extraEnvKeys = []string{
  	"GO_TESTING_GOTOOLS", // for gccgo testing
  	"GCCGO",              // for gccgo testing
  	"GCCGOTOOLDIR",       // for gccgo testing
-+	"CGO_CFLAGS",         // for working around go1.19 "unknown symbol __stack_chk_fail_local" error on x86
++	"CGO_CFLAGS",         // for working around "unknown symbol __stack_chk_fail_local" error on x86
  }
  
- // setup sets up the test execution temporary directory and environment.
+ // updateSum runs 'go mod tidy', 'go list -mod=mod -m all', or
diff --git a/srcpkgs/go/patches/fix-musl-tests.patch b/srcpkgs/go/patches/fix-musl-tests.patch
index f70cb456857..5b300f8e5ae 100644
--- a/srcpkgs/go/patches/fix-musl-tests.patch
+++ b/srcpkgs/go/patches/fix-musl-tests.patch
@@ -1,22 +1,22 @@
-These tests fail on musl because /proc/../status doesn't contain the "Groups"
-field, because musl lacks the getgroups() syscall.
+These tests fail on musl because /proc/../status doesn't
+contain the "Groups" field, because musl lacks the getgroups() syscall.
 
+--- a/go/src/cmd/cgo/internal/test/issue1435.go
++++ b/go/src/cmd/cgo/internal/test/issue1435.go
+@@ -170,10 +170,6 @@ func test1435(t *testing.T) {
+ 		{call: "Setgid(1)", fn: func() error { return syscall.Setgid(1) }, filter: "Gid:", expect: "\t1\t1\t1\t1"},
+ 		{call: "Setgid(0)", fn: func() error { return syscall.Setgid(0) }, filter: "Gid:", expect: "\t0\t0\t0\t0"},
+ 
+-		{call: "Setgroups([]int{0,1,2,3})", fn: func() error { return syscall.Setgroups([]int{0, 1, 2, 3}) }, filter: "Groups:", expect: "\t0 1 2 3"},
+-		{call: "Setgroups(nil)", fn: func() error { return syscall.Setgroups(nil) }, filter: "Groups:", expect: ""},
+-		{call: "Setgroups([]int{0})", fn: func() error { return syscall.Setgroups([]int{0}) }, filter: "Groups:", expect: "\t0"},
+-
+ 		{call: "Setregid(101,0)", fn: func() error { return syscall.Setregid(101, 0) }, filter: "Gid:", expect: "\t101\t0\t0\t0"},
+ 		{call: "Setregid(0,102)", fn: func() error { return syscall.Setregid(0, 102) }, filter: "Gid:", expect: "\t0\t102\t102\t102"},
+ 		{call: "Setregid(0,0)", fn: func() error { return syscall.Setregid(0, 0) }, filter: "Gid:", expect: "\t0\t0\t0\t0"},
 --- a/go/src/syscall/syscall_linux_test.go
 +++ b/go/src/syscall/syscall_linux_test.go
-@@ -530,10 +530,6 @@ func TestSetuidEtc(t *testing.T) {
- 		{call: "Setgid(1)", fn: func() error { return syscall.Setgid(1) }, filter: "Gid:", expect: "\t1\t1\t1\t1"},
- 		{call: "Setgid(0)", fn: func() error { return syscall.Setgid(0) }, filter: "Gid:", expect: "\t0\t0\t0\t0"},
- 
--		{call: "Setgroups([]int{0,1,2,3})", fn: func() error { return syscall.Setgroups([]int{0, 1, 2, 3}) }, filter: "Groups:", expect: "\t0 1 2 3"},
--		{call: "Setgroups(nil)", fn: func() error { return syscall.Setgroups(nil) }, filter: "Groups:", expect: ""},
--		{call: "Setgroups([]int{0})", fn: func() error { return syscall.Setgroups([]int{0}) }, filter: "Groups:", expect: "\t0"},
--
- 		{call: "Setregid(101,0)", fn: func() error { return syscall.Setregid(101, 0) }, filter: "Gid:", expect: "\t101\t0\t0\t0"},
- 		{call: "Setregid(0,102)", fn: func() error { return syscall.Setregid(0, 102) }, filter: "Gid:", expect: "\t0\t102\t102\t102"},
- 		{call: "Setregid(0,0)", fn: func() error { return syscall.Setregid(0, 0) }, filter: "Gid:", expect: "\t0\t0\t0\t0"},
---- a/go/misc/cgo/test/issue1435.go
-+++ b/go/misc/cgo/test/issue1435.go
-@@ -165,10 +165,6 @@ func test1435(t *testing.T) {
+@@ -533,10 +533,6 @@ func TestSetuidEtc(t *testing.T) {
  		{call: "Setgid(1)", fn: func() error { return syscall.Setgid(1) }, filter: "Gid:", expect: "\t1\t1\t1\t1"},
  		{call: "Setgid(0)", fn: func() error { return syscall.Setgid(0) }, filter: "Gid:", expect: "\t0\t0\t0\t0"},
  
diff --git a/srcpkgs/go/patches/fix-tests.patch b/srcpkgs/go/patches/fix-tests.patch
index c9341561141..c4e8397d33d 100644
--- a/srcpkgs/go/patches/fix-tests.patch
+++ b/srcpkgs/go/patches/fix-tests.patch
@@ -1,13 +1,26 @@
-Inside user namespaces, if GID == OVERFLOWGID (65534), then chown won't work.
-https://github.com/golang/go/issues/42525
+Inside user namespaces, if GID == OVERFLOWGID (65534), then
+chown won't work. https://github.com/golang/go/issues/42525
 
 --- a/go/src/os/os_unix_test.go
 +++ b/go/src/os/os_unix_test.go
-@@ -39,144 +39,6 @@ func checkUidGid(t *testing.T, path string, uid, gid int) {
+@@ -7,7 +7,6 @@
+ package os_test
+ 
+ import (
+-	"internal/testenv"
+ 	"io"
+ 	. "os"
+ 	"path/filepath"
+@@ -39,157 +38,6 @@ func checkUidGid(t *testing.T, path string, uid, gid int) {
  	}
  }
  
 -func TestChown(t *testing.T) {
+-	if runtime.GOOS == "wasip1" {
+-		t.Skip("file ownership not supported on " + runtime.GOOS)
+-	}
+-	t.Parallel()
+-
 -	// Use TempDir() to make sure we're on a local file system,
 -	// so that the group ids returned by Getgroups will be allowed
 -	// on the file. On NFS, the Getgroups groups are
@@ -51,6 +64,11 @@ https://github.com/golang/go/issues/42525
 -}
 -
 -func TestFileChown(t *testing.T) {
+-	if runtime.GOOS == "wasip1" {
+-		t.Skip("file ownership not supported on " + runtime.GOOS)
+-	}
+-	t.Parallel()
+-
 -	// Use TempDir() to make sure we're on a local file system,
 -	// so that the group ids returned by Getgroups will be allowed
 -	// on the file. On NFS, the Getgroups groups are
@@ -94,6 +112,9 @@ https://github.com/golang/go/issues/42525
 -}
 -
 -func TestLchown(t *testing.T) {
+-	testenv.MustHaveSymlink(t)
+-	t.Parallel()
+-
 -	// Use TempDir() to make sure we're on a local file system,
 -	// so that the group ids returned by Getgroups will be allowed
 -	// on the file. On NFS, the Getgroups groups are
diff --git a/srcpkgs/go/template b/srcpkgs/go/template
index 6a8bed6ad01..dea0969cdb0 100644
--- a/srcpkgs/go/template
+++ b/srcpkgs/go/template
@@ -1,6 +1,6 @@
 # Template file for 'go'
 pkgname=go
-version=1.20.7
+version=1.21.0
 revision=1
 create_wrksrc=yes
 build_wrksrc=go
@@ -12,7 +12,7 @@ license="BSD-3-Clause"
 homepage="https://go.dev/"
 changelog="https://go.dev/doc/devel/release.html"
 distfiles="https://go.dev/dl/go${version}.src.tar.gz"
-checksum=2c5ee9c9ec1e733b0dbbc2bdfed3f62306e51d8172bf38f4f4e542b27520f597
+checksum=818d46ede85682dd551ad378ef37a4d247006f12ec59b5b755601d2ce114369a
 nostrip=yes
 noverifyrdeps=yes
 # on CI it tries to use `git submodule`, which is not part of chroot-git
@@ -55,7 +55,6 @@ do_build() {
 
 	export GOROOT_BOOTSTRAP="/usr/lib/go1.17.13"
 	export GOROOT=$PWD
-	export GOROOT_FINAL="/usr/lib/go"
 	export GOARCH=${_goarch}
 
 	cd "src"
@@ -83,21 +82,15 @@ do_install() {
 
 	vmkdir usr/bin
 	vmkdir usr/lib/go
+	vmkdir usr/lib/go/bin
 	vmkdir usr/share/go
-	cp -d --preserve=all ${bindir}/* ${DESTDIR}/usr/bin || true
+	cp -d --preserve=all ${bindir}/* ${DESTDIR}/usr/lib/go/bin || true
 	cp -a pkg src lib ${DESTDIR}/usr/lib/go
 	cp -r doc misc -t ${DESTDIR}/usr/share/go
 	ln -s /usr/share/go/doc ${DESTDIR}/usr/lib/go/doc
 	cp VERSION ${DESTDIR}/usr/lib/go/VERSION
-
-	# This is to make go get code.google.com/p/go-tour/gotour and
-	# then running the gotour executable work out of the box.
-	#
-	# Also, /usr/bin is the place for system-wide executables,
-	# not /usr/lib/go/bin. Users should use different paths by
-	# setting the appropriate environment variables.
-	#
-	ln -sf /usr/bin ${DESTDIR}/usr/lib/go/bin
+	# GOROOT_FINAL doesn't work anymore, see: https://github.com/golang/go/issues/61921
+	ln -sfr ${DESTDIR}/usr/lib/go/bin/* ${DESTDIR}/usr/bin
 
 	# <dominikh> sigh. well, someone fix the template and add
 	# a symlink, usr/lib/go/misc -> /usr/share/go/misc