internal/rosa: wrap per-arch values
All checks were successful
Test / Create distribution (push) Successful in 1m16s
Test / Sandbox (push) Successful in 3m12s
Test / Hakurei (push) Successful in 4m35s
Test / ShareFS (push) Successful in 4m38s
Test / Sandbox (race detector) (push) Successful in 5m52s
Test / Hakurei (race detector) (push) Successful in 7m9s
Test / Flake checks (push) Successful in 1m31s

This is cleaner syntax in some specific cases.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-04-13 02:59:55 +09:00
parent 46be0b0dc8
commit 8541bdd858
2 changed files with 17 additions and 15 deletions

View File

@@ -69,6 +69,18 @@ func triplet() string {
return linuxArch() + "-rosa-linux-musl" return linuxArch() + "-rosa-linux-musl"
} }
// perArch is a value that differs per architecture.
type perArch[T any] map[string]T
// unwrap returns the value for the current architecture.
func (p perArch[T]) unwrap() T {
v, ok := p[runtime.GOARCH]
if !ok {
panic("unsupported target " + runtime.GOARCH)
}
return v
}
const ( const (
// EnvTriplet holds the return value of triplet. // EnvTriplet holds the return value of triplet.
EnvTriplet = "ROSA_TRIPLE" EnvTriplet = "ROSA_TRIPLE"

View File

@@ -1,7 +1,6 @@
package rosa package rosa
import ( import (
"runtime"
"sync" "sync"
"hakurei.app/internal/pkg" "hakurei.app/internal/pkg"
@@ -61,23 +60,14 @@ var (
// NewStage0 returns a stage0 distribution created from curing [Stage0]. // NewStage0 returns a stage0 distribution created from curing [Stage0].
func NewStage0() pkg.Artifact { func NewStage0() pkg.Artifact {
stage0Once.Do(func() { stage0Once.Do(func() {
var seed string
switch runtime.GOARCH {
case "amd64":
seed = "tqM1Li15BJ-uFG8zU-XjgFxoN_kuzh1VxrSDVUVa0vGmo-NeWapSftH739sY8EAg"
case "arm64":
seed = "CJj3ZSnRyLmFHlWIQtTPQD9oikOZY4cD_mI3v_-LIYc2hhg-cq_CZFBLzQBAkFIn"
case "riscv64":
seed = "FcszJjcVWdKAnn-bt8qmUn5GUUTjv_xQjXOWkUpOplRkG3Ckob3StUoAi5KQ5-QF"
default:
panic("unsupported target " + runtime.GOARCH)
}
stage0 = pkg.NewHTTPGetTar( stage0 = pkg.NewHTTPGetTar(
nil, "https://hakurei.app/seed/20260210/"+ nil, "https://hakurei.app/seed/20260210/"+
"stage0-"+triplet()+".tar.bz2", "stage0-"+triplet()+".tar.bz2",
mustDecode(seed), mustDecode(perArch[string]{
"amd64": "tqM1Li15BJ-uFG8zU-XjgFxoN_kuzh1VxrSDVUVa0vGmo-NeWapSftH739sY8EAg",
"arm64": "CJj3ZSnRyLmFHlWIQtTPQD9oikOZY4cD_mI3v_-LIYc2hhg-cq_CZFBLzQBAkFIn",
"riscv64": "FcszJjcVWdKAnn-bt8qmUn5GUUTjv_xQjXOWkUpOplRkG3Ckob3StUoAi5KQ5-QF",
}.unwrap()),
pkg.TarBzip2, pkg.TarBzip2,
) )
}) })