Files
hakurei/internal/rosa/go.go
Ophestra 6ee3ed1711 internal/rosa/go: alternative bootstrap path
For targets where the bootstrap toolchain is not available.

Signed-off-by: Ophestra <cat@gensokyo.uk>
2026-02-08 01:45:21 +09:00

154 lines
3.3 KiB
Go

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", 0, []pkg.Artifact{
t.Load(Bash),
}, nil, []string{
"CGO_ENABLED=0",
}, `
mkdir -p /var/tmp/ /work/system/
cp -r /usr/src/go /work/system/
cd /work/system/go/src
chmod -R +w ..
./make.bash
`, 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, 0, 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 {
var (
bootstrapEnv []string
bootstrapExtra []pkg.Artifact
)
switch runtime.GOARCH {
case "amd64":
bootstrapExtra = append(bootstrapExtra, t.newGoBootstrap())
case "arm64":
bootstrapEnv = append(bootstrapEnv,
"GOROOT_BOOTSTRAP=/system",
)
bootstrapExtra = append(bootstrapExtra,
t.Load(Binutils),
t.Load(GMP),
t.Load(MPFR),
t.Load(MPC),
t.Load(Zlib),
t.Load(Libucontext),
t.Load(gcc),
)
default:
panic("unsupported target " + runtime.GOARCH)
}
go119 := t.newGo(
"1.19",
"9_e0aFHsIkVxWVGsp9T2RvvjOc3p4n9o9S8tkNe9Cvgzk_zI2FhRQB7ioQkeAAro",
append(bootstrapEnv, "CGO_ENABLED=0"), `
rm \
crypto/tls/handshake_client_test.go \
os/os_unix_test.go
sed -i \
's/os\.Getenv("GCCGO")$/"nonexistent"/' \
go/internal/gccgoimporter/importer_test.go
echo \
'type syscallDescriptor = int' >> \
os/rawconn_test.go
`, bootstrapExtra...)
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 \
os/os_unix_test.go
echo \
'type syscallDescriptor = int' >> \
os/rawconn_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
rm \
os/root_unix_test.go
`, go123,
)
return go125
}
func init() { artifactsF[Go] = Toolchain.newGoLatest }