aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/rosa/go.go
blob: 69987101516a4da9f68c7b51f6491cee02c4cc28 (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
package rosa

import (
	"runtime"
	"slices"

	"hakurei.app/internal/pkg"
)

// newGoBootstrap returns the Go bootstrap toolchain.
func (t Toolchain) newGoBootstrap() pkg.Artifact {
	const checksum = "8o9JL_ToiQKadCTb04nvBDkp8O1xiWOolAxVEqaTGodieNe4lOFEjlOxN3bwwe23"
	return t.New("go1.4-bootstrap", []pkg.Artifact{
		t.Load(Bash),
	}, nil, []string{
		"CGO_ENABLED=0",
	}, `
mkdir -p /var/tmp
cp -r /usr/src/go /work
cd /work/go/src
chmod -R +w ..

ln -s ../system/bin/busybox /bin/pwd
cat << EOF > /bin/hostname
#!/bin/sh
echo cure
EOF
chmod +x /bin/hostname

rm \
	cmd/objdump/objdump_test.go \
	syscall/creds_test.go \
	net/multicast_test.go

./all.bash
cd /work/
mkdir system/
mv go/ system/
`, pkg.Path(AbsUsrSrc.Append("go"), false, pkg.NewHTTPGetTar(
		nil, "https://dl.google.com/go/go1.4-bootstrap-20171003.tar.gz",
		mustDecode(checksum),
		pkg.TarGzip,
	)))
}

// newGo returns a specific version of the Go toolchain.
func (t Toolchain) newGo(
	version, checksum string,
	env []string,
	script string,
	extra ...pkg.Artifact,
) pkg.Artifact {
	return t.New("go"+version, slices.Concat([]pkg.Artifact{
		t.Load(Bash),
	}, extra), nil, slices.Concat([]string{
		"CC=cc",
		"GOCACHE=/tmp/gocache",
		"GOROOT_BOOTSTRAP=/system/go",
		"TMPDIR=/dev/shm/go",
	}, env), `
mkdir /work/system "${TMPDIR}"
cp -r /usr/src/go /work/system
cd /work/system/go/src
chmod -R +w ..
`+script+`
./all.bash

mkdir /work/system/bin
ln -s \
	../go/bin/go \
	../go/bin/gofmt \
	/work/system/bin
`, pkg.Path(AbsUsrSrc.Append("go"), false, pkg.NewHTTPGetTar(
		nil, "https://go.dev/dl/go"+version+".src.tar.gz",
		mustDecode(checksum),
		pkg.TarGzip,
	)))
}

func (t Toolchain) newGoLatest() pkg.Artifact {
	go119 := t.newGo(
		"1.19",
		"9_e0aFHsIkVxWVGsp9T2RvvjOc3p4n9o9S8tkNe9Cvgzk_zI2FhRQB7ioQkeAAro",
		[]string{"CGO_ENABLED=0"}, `
rm \
	crypto/tls/handshake_client_test.go
`, t.newGoBootstrap(),
	)

	go121 := t.newGo(
		"1.21.13",
		"YtrDka402BOAEwywx03Vz4QlVwoBiguJHzG7PuythMCPHXS8CVMLvzmvgEbu4Tzu",
		[]string{"CGO_ENABLED=0"}, `
sed -i \
	's,/lib/ld-musl-`+linuxArch()+`.so.1,/system/bin/linker,' \
	cmd/link/internal/`+runtime.GOARCH+`/obj.go

rm \
	crypto/tls/handshake_client_test.go \
	crypto/tls/handshake_server_test.go
`, go119,
	)

	go123 := t.newGo(
		"1.23.12",
		"wcI32bl1tkqbgcelGtGWPI4RtlEddd-PTd76Eb-k7nXA5LbE9yTNdIL9QSOOxMOs",
		nil, `
sed -i \
	's,/lib/ld-musl-`+linuxArch()+`.so.1,/system/bin/linker,' \
	cmd/link/internal/`+runtime.GOARCH+`/obj.go
`, go121,
	)

	go125 := t.newGo(
		"1.25.6",
		"x0z430qoDvQbbw_fftjW0rh_GSoh0VJhPzttWk_0hj9yz9AKOjuwRMupF_Q0dbt7",
		nil, `
sed -i \
	's,/lib/ld-musl-`+linuxArch()+`.so.1,/system/bin/linker,' \
	cmd/link/internal/`+runtime.GOARCH+`/obj.go
`, go123,
	)

	return go125
}
func init() { artifactsF[Go] = Toolchain.newGoLatest }