aboutsummaryrefslogtreecommitdiffstats
path: root/community/go/APKBUILD
blob: c57f8d980eb804e915b1cc207315e9d84f6115af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Contributor: Eivind Uggedal <eu@eju.no>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=go
# go binaries are statically linked, security updates require rebuilds
pkgver=1.16
pkgrel=0
pkgdesc="Go programming language compiler"
url="https://golang.org/"
arch="all"
license="BSD-3-Clause"
depends="binutils gcc musl-dev"
makedepends="bash"
checkdepends="binutils-gold"
subpackages="$pkgname-doc"
source="https://golang.org/dl/go${pkgver/_/}.src.tar.gz
	disable-flaky-sync-test.patch
	disable-flaky-gc-test.patch
	"
case "$CARCH" in
	arm*|aarch64) depends="binutils-gold";;
	riscv64)
		# Gold does not support RISC-V
		checkdepends=""
		;;
esac

# secfixes:
#   1.15.7-r0:
#     - CVE-2021-3114
#     - CVE-2021-3115
#   1.15.5-r0:
#     - CVE-2020-28362
#     - CVE-2020-28366
#     - CVE-2020-28367
#   1.15.2-r0:
#     - CVE-2020-24553
#   1.15-r0:
#     - CVE-2020-16845
#   1.14.5-r0:
#     - CVE-2020-15586
#   1.13.7-r0:
#     - CVE-2020-7919
#   1.13.2-r0:
#     - CVE-2019-17596
#   1.13.1-r0:
#     - CVE-2019-16276
#   1.12.8-r0:
#     - CVE-2019-9512
#     - CVE-2019-9514
#     - CVE-2019-14809
#   1.11.5-r0:
#     - CVE-2019-6486
#   1.9.4-r0:
#     - CVE-2018-6574

if [ "$CBUILD" = "$CTARGET" ]; then
	makedepends="go-bootstrap $makedepends"
	provides="go-bootstrap=$pkgver-r$pkgrel"
	subpackages="$subpackages"
else
	pkgname="go-bootstrap"
	makedepends="go $makedepends"
	# Go expect host linker instead of the cross-compiler
	export CC_FOR_TARGET="$CC"
	export CC="${HOSTLD:-gcc}"
	export CXX="${HOSTLD:-g++}"
	export LD="${HOSTLD:-ld}"
fi

case "$CTARGET_ARCH" in
aarch64)export GOARCH="arm64" ;;
armel)  export GOARCH="arm" GOARM=5 ;;
armhf)  export GOARCH="arm" GOARM=6 ;;
armv7)  export GOARCH="arm" GOARM=7 ;;
s390x)  export GOARCH="s390x" ;;
x86)    export GOARCH="386" ;;
x86_64) export GOARCH="amd64" ;;
ppc64)	export GOARCH="ppc64" ;;
ppc64le) export GOARCH="ppc64le" ;;
mips)   export GOARCH="mips" GOMIPS=softfloat ;;
mips64) export GOARCH="mips64" GOMIPS64=softfloat ;;
mips64el) export GOARCH="mips64le" GOMIPS64=softfloat ;;
mipsel) export GOARCH="mipsle" GOMIPS=softfloat ;;
riscv64) export GOARCH="riscv64" ;;
*)      export GOARCH="unsupported";;
esac

# compile go itself as a PIE on supported arches.
case "$CARCH" in
x86_64|s390x|aarch64) export GO_LDFLAGS=-buildmode=pie ;;
esac

builddir="$srcdir"/go
build() {
	cd "$builddir/src"

	export GOOS="linux"
	export GOPATH="$srcdir"
	export GOROOT="$builddir"
	export GOBIN="$GOROOT"/bin
	export GOROOT_FINAL=/usr/lib/go
	local p; for p in /usr/lib/go-bootstrap /usr/lib/go-linux-$GOARCH-bootstrap /usr/lib/go; do
		if [ -d "$p" ]; then
			export GOROOT_BOOTSTRAP="$p"
			break
		fi
	done

	./make.bash -v

	# copied from bootstrap.bash to fixup cross-built bootstrap go
	if [ "$CBUILD" != "$CTARGET" ]; then
		local gohostos="$(../bin/go env GOHOSTOS)"
		local gohostarch="$(../bin/go env GOHOSTARCH)"
		mv ../bin/*_*/* ../bin
		rmdir ../bin/*_*
		rm -rf "../pkg/${gohostos}_$gohostarch"* "../pkg/tool/${gohostos}_$gohostarch"*
		rm -rf ../pkg/bootstrap ../pkg/obj
	fi
}

check() {
	cd "$builddir/src"
	# TODO: cgo_test fails due to https://github.com/golang/go/issues/39857
	PATH="$builddir/bin:$PATH" ./run.bash -no-rebuild -run='!(^cgo_test$)'
}

package() {
	mkdir -p "$pkgdir"/usr/bin "$pkgdir"/usr/lib/go/bin "$pkgdir"/usr/share/doc/go

	for binary in go gofmt; do
		install -Dm755 bin/"$binary" "$pkgdir"/usr/lib/go/bin/"$binary"
		ln -s /usr/lib/go/bin/"$binary" "$pkgdir"/usr/bin/
	done

	cp -a pkg lib "$pkgdir"/usr/lib/go
	cp -r doc misc "$pkgdir"/usr/share/doc/go
	rm -rf "$pkgdir"/usr/lib/go/pkg/obj
	rm -rf "$pkgdir"/usr/lib/go/pkg/bootstrap
	rm -f  "$pkgdir"/usr/lib/go/pkg/tool/*/api

	mkdir -p "$pkgdir"/usr/lib/go/
	cp -a "$builddir"/src "$pkgdir"/usr/lib/go

	# Remove tests from /usr/lib/go/src to reduce package size,
	# these should not be needed at run-time by any program.
	find "$pkgdir"/usr/lib/go/src \( -type f -a -name "*_test.go" \) \
		-exec rm -rf \{\} \+
	find "$pkgdir"/usr/lib/go/src \( -type d -a -name "testdata" \) \
		-exec rm -rf \{\} \+

	# Remove rc (plan 9) and bat scripts (windows) to reduce package
	# size further. The bash scripts are actually needed at run-time.
	#
	# See: https://gitlab.alpinelinux.org/alpine/aports/issues/11091
	find "$pkgdir"/usr/lib/go/src -type f -a \( -name "*.rc" -o -name "*.bat" \) \
		-exec rm -rf \{\} \+
}

sha512sums="9c43e0ebb2d35c694b652cae8d4040ce3f3c8c014abd9496c92c78cc015ecea5b5331e7c2acf098d0c24dec222454ea09d834df4b6bc90d46e9feeac0ac578bf  go1.16.src.tar.gz
988a436727aefc5124702bd70cb01bb457a921affcdd03e17f78937685482e899080d95baf125e054d1f634dae5c747d05a3662f1f4f462b87965b06270c788f  disable-flaky-sync-test.patch
ab4aa83d8a9bf10bbb93ad029095b47c6eea7d5532703d84449884039116e07897871649feb1df8128f10257cbdb5d7eb03820ab0f1a3f60315e195302f6e516  disable-flaky-gc-test.patch"