aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/rosa
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-05-07 18:04:59 +0900
committerOphestra <cat@gensokyo.uk>2026-05-07 19:43:06 +0900
commit8d72b9e5bd8d99cbd32ce0ebe2f5da8e9b1d88ce (patch)
tree403a00ccd0d1ed98795a4e739b72f2de12b34102 /internal/rosa
parent8a3c3d145a560b91da1d9bce9070c20289b63502 (diff)
internal/pkg: optionally register binfmt
This transparently supports curing foreign exec artifacts. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/rosa')
-rw-r--r--internal/rosa/all.go14
-rw-r--r--internal/rosa/all_test.go6
-rw-r--r--internal/rosa/busybox.go2
-rw-r--r--internal/rosa/rosa.go2
-rw-r--r--internal/rosa/rosa_test.go8
5 files changed, 22 insertions, 10 deletions
diff --git a/internal/rosa/all.go b/internal/rosa/all.go
index 8fee7867..c8eddd7f 100644
--- a/internal/rosa/all.go
+++ b/internal/rosa/all.go
@@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"net/http"
+ "runtime"
"strconv"
"sync"
@@ -347,6 +348,9 @@ var (
// artifactsOnce is for lazy initialisation of artifacts.
artifactsOnce [_toolchainEnd][len(artifactsM)]sync.Once
+ // arch is the target architecture.
+ arch = runtime.GOARCH
+
// presetOpts globally modifies behaviour of presets.
presetOpts int
)
@@ -358,6 +362,9 @@ const (
OptLLVMNoLTO
)
+// Arch returns the target architecture.
+func Arch() string { return arch }
+
// Flags returns the current preset flags
func Flags() int { return presetOpts }
@@ -367,7 +374,12 @@ func zero[T any](p *T) { var v T; *p = v }
// DropCaches arranges for all cached [pkg.Artifact] to be freed some time after
// it returns. Must not be used concurrently with any other function from this
// package.
-func DropCaches(flags int) {
+func DropCaches(targetArch string, flags int) {
+ if targetArch == "" {
+ targetArch = runtime.GOARCH
+ }
+
+ arch = targetArch
presetOpts = flags
zero(&artifacts)
zero(&artifactsOnce)
diff --git a/internal/rosa/all_test.go b/internal/rosa/all_test.go
index 52eabf39..8f86201a 100644
--- a/internal/rosa/all_test.go
+++ b/internal/rosa/all_test.go
@@ -20,8 +20,8 @@ func TestLoad(t *testing.T) {
}
func BenchmarkAll(b *testing.B) {
- flags := rosa.Flags()
- b.Cleanup(func() { rosa.DropCaches(flags) })
+ arch, flags := rosa.Arch(), rosa.Flags()
+ b.Cleanup(func() { rosa.DropCaches(arch, flags) })
for b.Loop() {
for i := range rosa.PresetEnd {
@@ -29,7 +29,7 @@ func BenchmarkAll(b *testing.B) {
}
b.StopTimer()
- rosa.DropCaches(0)
+ rosa.DropCaches("", 0)
b.StartTimer()
}
}
diff --git a/internal/rosa/busybox.go b/internal/rosa/busybox.go
index 14247f05..437e05e4 100644
--- a/internal/rosa/busybox.go
+++ b/internal/rosa/busybox.go
@@ -105,7 +105,7 @@ func newBusyboxBin() pkg.Artifact {
}
return pkg.NewExec(
- "busybox-bin-"+version, nil, pkg.ExecTimeoutMax, false,
+ "busybox-bin-"+version, arch, nil, pkg.ExecTimeoutMax, false,
fhs.AbsRoot, []string{
"PATH=/system/bin",
},
diff --git a/internal/rosa/rosa.go b/internal/rosa/rosa.go
index e1d20407..fb4e8a4b 100644
--- a/internal/rosa/rosa.go
+++ b/internal/rosa/rosa.go
@@ -327,7 +327,7 @@ mkdir -vp /work/system/bin
}
return pkg.NewExec(
- name, knownChecksum, pkg.ExecTimeoutMax, flag&TExclusive != 0,
+ name, arch, knownChecksum, pkg.ExecTimeoutMax, flag&TExclusive != 0,
fhs.AbsRoot, env,
AbsSystem.Append("bin", "sh"),
[]string{"sh", absCureScript.String()},
diff --git a/internal/rosa/rosa_test.go b/internal/rosa/rosa_test.go
index b9f8206a..0eef8334 100644
--- a/internal/rosa/rosa_test.go
+++ b/internal/rosa/rosa_test.go
@@ -28,7 +28,7 @@ var (
)
func TestMain(m *testing.M) {
- rosa.DropCaches(rosa.OptLLVMNoLTO)
+ rosa.DropCaches("", rosa.OptLLVMNoLTO)
container.TryArgv0(nil)
code := m.Run()
@@ -94,14 +94,14 @@ func TestCureAll(t *testing.T) {
}
func BenchmarkStage3(b *testing.B) {
- flags := rosa.Flags()
- b.Cleanup(func() { rosa.DropCaches(flags) })
+ arch, flags := rosa.Arch(), rosa.Flags()
+ b.Cleanup(func() { rosa.DropCaches(arch, flags) })
for b.Loop() {
rosa.Std.Load(rosa.LLVM)
b.StopTimer()
- rosa.DropCaches(0)
+ rosa.DropCaches("", 0)
b.StartTimer()
}
}