aboutsummaryrefslogtreecommitdiffhomepage
path: root/cmd
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-05-07 20:29:31 +0900
committerOphestra <cat@gensokyo.uk>2026-05-07 20:29:31 +0900
commit145d03b36658d8716d02b0e6084b646131821728 (patch)
tree30f068991e1b0b7e38c72801c9cd363628657c9c /cmd
parent2886228d40a765c809792d9e3a181d7461018855 (diff)
cmd/mbf: optional emulated target architecture
This enables transparent cross-compilation without breaking purity. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/mbf/cache.go48
-rw-r--r--cmd/mbf/main.go4
2 files changed, 52 insertions, 0 deletions
diff --git a/cmd/mbf/cache.go b/cmd/mbf/cache.go
index 05fa7070..adbc84e2 100644
--- a/cmd/mbf/cache.go
+++ b/cmd/mbf/cache.go
@@ -4,10 +4,13 @@ import (
"context"
"os"
"path/filepath"
+ "runtime"
"testing"
"hakurei.app/check"
+ "hakurei.app/container"
"hakurei.app/internal/pkg"
+ "hakurei.app/internal/rosa"
"hakurei.app/message"
)
@@ -22,6 +25,7 @@ type cache struct {
cures, jobs int
hostAbstract, idle bool
verboseInit bool
+ arch string
base string
}
@@ -74,6 +78,50 @@ func (cache *cache) open() (err error) {
cache.jobs,
base,
)
+ if err != nil {
+ return
+ }
+ done <- struct{}{}
+
+ if cache.arch != "" && cache.arch != runtime.GOARCH {
+ var (
+ name string
+ offset byte
+ magic string
+ mask string
+ )
+ switch cache.arch {
+ case "riscv64":
+ name = "riscv64"
+ offset = 0
+ magic = "\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xf3\x00"
+ mask = "\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff"
+
+ default:
+ cache.c.Close()
+ err = pkg.UnsupportedArchError(cache.arch)
+ return
+ }
+
+ var pathname *check.Absolute
+ pathname, _, err = cache.c.Cure(rosa.Std.Load(rosa.QEMU))
+ if err != nil {
+ cache.c.Close()
+ return
+ }
+
+ pkg.RegisterArch(cache.arch, container.BinfmtEntry{
+ Offset: offset,
+ Magic: magic,
+ Mask: mask,
+ Interpreter: pathname.Append(
+ "system/bin",
+ "qemu-"+name,
+ ),
+ })
+ rosa.DropCaches(cache.arch, rosa.Flags())
+ }
+
return
}
diff --git a/cmd/mbf/main.go b/cmd/mbf/main.go
index 65d563be..a5f1807a 100644
--- a/cmd/mbf/main.go
+++ b/cmd/mbf/main.go
@@ -101,6 +101,10 @@ func main() {
"q", command.BoolFlag(false),
"Do not print cure messages",
).Flag(
+ &cm.arch,
+ "arch", command.StringFlag(runtime.GOARCH),
+ "Target architecture",
+ ).Flag(
&flagLTO,
"lto", command.BoolFlag(false),
"Enable LTO in stage2 and stage3 LLVM toolchains",