From 0914569e62089f2a9545243c529d238c662d4b04 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Thu, 21 May 2026 19:47:55 +0900 Subject: [PATCH] internal/rosa/go: migrate to generic helper The go toolchain predates all abstractions currently available. This migration causes rebuilds due to internal cleanups affecting the final build script. Signed-off-by: Ophestra --- internal/rosa/go.go | 203 +++++++++++++++++++++------------------ internal/rosa/hakurei.go | 4 +- internal/rosa/rosa.go | 5 +- 3 files changed, 114 insertions(+), 98 deletions(-) diff --git a/internal/rosa/go.go b/internal/rosa/go.go index e1acbaff..bc11af9a 100644 --- a/internal/rosa/go.go +++ b/internal/rosa/go.go @@ -8,89 +8,111 @@ import ( var _go = H("go") -// newGoBootstrap returns the Go bootstrap toolchain. -func (t Toolchain) newGoBootstrap() pkg.Artifact { - const checksum = "8o9JL_ToiQKadCTb04nvBDkp8O1xiWOolAxVEqaTGodieNe4lOFEjlOxN3bwwe23" - return t.New("go1.4-bootstrap", 0, t.Append(nil, - _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, newTar( - "https://dl.google.com/go/go1.4-bootstrap-20171003.tar.gz", - 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, + boot pkg.Artifact, ) pkg.Artifact { - name := "all" - if t.opts&OptSkipCheck != 0 { - name = "make" - } - return t.New("go"+version, 0, t.Append(extra, - _bash, - ), 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 + return t.NewPackage("go", version, newTar( + "https://go.dev/dl/go"+version+".src.tar.gz", + checksum, + pkg.TarGzip, + ), &PackageAttr{ + EnterSource: true, + Env: slices.Concat([]string{ + "CC=cc", + "GOCACHE=/tmp/gocache", + "GOROOT_BOOTSTRAP=/system/go", + "TMPDIR=/dev/shm/go", + }, env), + + Extra: []pkg.Artifact{boot}, + }, &GenericHelper{ + InPlace: true, + Build: ` +mkdir /work/system/ "${TMPDIR}" +cp -r . /work/system/go +cd /work/system/go/src/ chmod -R +w .. -`+script+` -./`+name+`.bash +` + script + ` +set +u +. ./make.bash "$@" --no-banner +set -u +`, + Check: "bash run.bash --no-rebuild\n", + Install: ` +../bin/go tool dist banner # print build info mkdir /work/system/bin ln -s \ ../go/bin/go \ ../go/bin/gofmt \ /work/system/bin -`, pkg.Path(AbsUsrSrc.Append("go"), false, newTar( - "https://go.dev/dl/go"+version+".src.tar.gz", - checksum, - pkg.TarGzip, - ))) +`, + }, + _bash, + ) } -func (t Toolchain) newGoLatest() (pkg.Artifact, string) { - var ( - bootstrapEnv []string - bootstrapExtra []pkg.Artifact - - finalEnv []string +func init() { + const ( + version = "1.26.3" + checksum = "lEiFocZFnN5fKvZzmwVdqc9pYUjAuhzqZGbuiOqxUP4XdcY8yECisKcqsQ_eNn1N" ) - switch t.arch { - case "amd64": - bootstrapExtra = append(bootstrapExtra, t.newGoBootstrap()) + meta := Metadata{ + Name: "go", + Description: "the Go programming language toolchain", + Website: "https://go.dev", + Version: version, - case "arm64", "riscv64": - bootstrapEnv = append(bootstrapEnv, "GOROOT_BOOTSTRAP=/system") - bootstrapExtra = t.Append(bootstrapExtra, H("gcc")) - finalEnv = append(finalEnv, "CGO_ENABLED=0") - - default: - panic("unsupported target " + t.arch) + ID: 1227, } + native.MustRegister(meta.Name, func(t Toolchain) (*Metadata, pkg.Artifact) { + var ( + bootstrapEnv []string + bootstrapEarly pkg.Artifact - go119 := t.newGo( - "1.19", - "9_e0aFHsIkVxWVGsp9T2RvvjOc3p4n9o9S8tkNe9Cvgzk_zI2FhRQB7ioQkeAAro", - append(bootstrapEnv, "CGO_ENABLED=0"), ` + finalEnv []string + ) + switch t.arch { + case "amd64": + bootstrapEarly = t.NewPackage("go", "1.4-bootstrap", newTar( + "https://dl.google.com/go/go1.4-bootstrap-20171003.tar.gz", + "8o9JL_ToiQKadCTb04nvBDkp8O1xiWOolAxVEqaTGodieNe4lOFEjlOxN3bwwe23", + pkg.TarGzip, + ), &PackageAttr{ + EnterSource: true, + Env: []string{ + "CGO_ENABLED=0", + }, + }, &GenericHelper{ + InPlace: true, + Build: ` +mkdir /work/system/ +cp -r . /work/system/go +cd /work/system/go/src/ +mkdir -p /var/tmp/ +./make.bash +`, + }, + _bash, + ) + + case "arm64", "riscv64": + bootstrapEnv = append(bootstrapEnv, "GOROOT_BOOTSTRAP=/system") + _, bootstrapEarly = t.MustLoad(H("gcc")) + finalEnv = append(finalEnv, "CGO_ENABLED=0") + + default: + panic("unsupported target " + t.arch) + } + + go119 := t.newGo( + "1.19", + "9_e0aFHsIkVxWVGsp9T2RvvjOc3p4n9o9S8tkNe9Cvgzk_zI2FhRQB7ioQkeAAro", + append(bootstrapEnv, "CGO_ENABLED=0"), ` rm \ crypto/tls/handshake_client_test.go \ cmd/pprof/pprof_test.go \ @@ -101,12 +123,12 @@ sed -i \ echo \ 'type syscallDescriptor = int' >> \ os/rawconn_test.go -`, bootstrapExtra...) +`, bootstrapEarly) - go121 := t.newGo( - "1.21.13", - "YtrDka402BOAEwywx03Vz4QlVwoBiguJHzG7PuythMCPHXS8CVMLvzmvgEbu4Tzu", - []string{"CGO_ENABLED=0"}, ` + go121 := t.newGo( + "1.21.13", + "YtrDka402BOAEwywx03Vz4QlVwoBiguJHzG7PuythMCPHXS8CVMLvzmvgEbu4Tzu", + []string{"CGO_ENABLED=0"}, ` sed -i \ 's,/lib/ld-musl-`+t.linuxArch()+`.so.1,/system/bin/linker,' \ cmd/link/internal/`+t.arch+`/obj.go @@ -119,22 +141,22 @@ echo \ 'type syscallDescriptor = int' >> \ os/rawconn_test.go `, go119, - ) + ) - go123 := t.newGo( - "1.23.12", - "wcI32bl1tkqbgcelGtGWPI4RtlEddd-PTd76Eb-k7nXA5LbE9yTNdIL9QSOOxMOs", - []string{"CGO_ENABLED=0"}, ` + go123 := t.newGo( + "1.23.12", + "wcI32bl1tkqbgcelGtGWPI4RtlEddd-PTd76Eb-k7nXA5LbE9yTNdIL9QSOOxMOs", + []string{"CGO_ENABLED=0"}, ` sed -i \ 's,/lib/ld-musl-`+t.linuxArch()+`.so.1,/system/bin/linker,' \ cmd/link/internal/`+t.arch+`/obj.go `, go121, - ) + ) - go125 := t.newGo( - "1.25.10", - "TwKwatkpwal-j9U2sDSRPEdM3YesI4Gm88YgGV59wtU-L85K9gA7UPy9SCxn6PMb", - []string{"CGO_ENABLED=0"}, ` + go125 := t.newGo( + "1.25.10", + "TwKwatkpwal-j9U2sDSRPEdM3YesI4Gm88YgGV59wtU-L85K9gA7UPy9SCxn6PMb", + []string{"CGO_ENABLED=0"}, ` sed -i \ 's,/lib/ld-musl-`+t.linuxArch()+`.so.1,/system/bin/linker,' \ cmd/link/internal/`+t.arch+`/obj.go @@ -143,16 +165,12 @@ rm \ os/root_unix_test.go \ net/smtp/smtp_test.go `, go123, - ) + ) - const ( - version = "1.26.3" - checksum = "lEiFocZFnN5fKvZzmwVdqc9pYUjAuhzqZGbuiOqxUP4XdcY8yECisKcqsQ_eNn1N" - ) - return t.newGo( - version, - checksum, - finalEnv, ` + return &meta, t.newGo( + version, + checksum, + finalEnv, ` sed -i \ 's,/lib/ld-musl-`+t.linuxArch()+`.so.1,/system/bin/linker,' \ cmd/link/internal/`+t.arch+`/obj.go @@ -165,14 +183,7 @@ rm \ cmd/cgo/internal/testsanitizers/tsan_test.go \ cmd/cgo/internal/testsanitizers/cshared_test.go `, go125, - ), version -} -func init() { - native.mustRegister(Toolchain.newGoLatest, &Metadata{ - Name: "go", - Description: "the Go programming language toolchain", - Website: "https://go.dev/", + ) - ID: 1227, }) } diff --git a/internal/rosa/hakurei.go b/internal/rosa/hakurei.go index 6fb289bd..ff56c1ea 100644 --- a/internal/rosa/hakurei.go +++ b/internal/rosa/hakurei.go @@ -18,7 +18,8 @@ go build -o /bin/hostname /usr/src/hostname/main.go return t.NewPackage(name, hakureiVersion, t.NewPatchedSource( "hakurei-"+hakureiVersion, hakureiSource, false, hakureiPatches..., ), &PackageAttr{ - Writable: true, + EnterSource: true, + Writable: true, Env: []string{ "CGO_ENABLED=1", "GOCACHE=/tmp/gocache", @@ -42,6 +43,7 @@ func main() { `), ))}, }, &GenericHelper{ + InPlace: true, Build: hostname + ` HAKUREI_VERSION='v` + hakureiVersion + `' ` + build, diff --git a/internal/rosa/rosa.go b/internal/rosa/rosa.go index d3ee5f03..5d75735a 100644 --- a/internal/rosa/rosa.go +++ b/internal/rosa/rosa.go @@ -413,6 +413,8 @@ type PackageAttr struct { // Passed to [Toolchain.NewPatchedSource]. Patches []KV + // Unregistered extras. + Extra []pkg.Artifact // Passed through to [Toolchain.New], before source. Paths []pkg.ExecPath // Passed through to [Toolchain.New]. @@ -481,7 +483,8 @@ func (t Toolchain) NewPackage( rn = name + "-" + version } wantsChmod, wantsWrite := helper.wantsChmod(), helper.wantsWrite() - extraRes := make([]pkg.Artifact, 0, 1<<3+len(extra)) + extraRes := make([]pkg.Artifact, 0, 1<<3+len(attr.Extra)+len(extra)) + extraRes = append(extraRes, attr.Extra...) { pv := paGet() for _, p := range helper.extra(attr.Flag) {