From e3520835bb0e896eda86132cad2ba9bc4ac4765f Mon Sep 17 00:00:00 2001 From: Ophestra Date: Fri, 8 May 2026 13:29:23 +0900 Subject: [PATCH] cmd/mbf: optionally register all targets This enables non-native cures from the daemon. Signed-off-by: Ophestra --- cmd/mbf/cache.go | 64 ++++++++++++++++------------------------- cmd/mbf/main.go | 19 +++++++++++- internal/rosa/stage0.go | 9 ++++++ 3 files changed, 52 insertions(+), 40 deletions(-) diff --git a/cmd/mbf/cache.go b/cmd/mbf/cache.go index 9a7d2ce6..0452a3e1 100644 --- a/cmd/mbf/cache.go +++ b/cmd/mbf/cache.go @@ -4,13 +4,11 @@ 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,10 +20,15 @@ type cache struct { // Should generally not be used directly. c *pkg.Cache - cures, jobs int - hostAbstract, idle bool - verboseInit bool - arch string + cures, jobs int + // Primarily to work around missing landlock LSM. + hostAbstract bool + // Set SCHED_IDLE. + idle bool + // Unset [pkg.CSuppressInit]. + verboseInit bool + // Loaded artifact of [rosa.QEMU]. + qemu pkg.Artifact base string } @@ -83,49 +86,32 @@ func (cache *cache) open() (err error) { } 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" - - case "arm64": - name = "aarch64" - offset = 0 - magic = "\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00" - mask = "\xff\xff\xff\xff\xff\xff\xff\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff" - - default: - cache.c.Close() - err = pkg.UnsupportedArchError(cache.arch) - return - } - + if cache.qemu != nil { var pathname *check.Absolute - pathname, _, err = cache.c.Cure(rosa.Std.Load(rosa.QEMU)) + pathname, _, err = cache.c.Cure(cache.qemu) if err != nil { cache.c.Close() return } - pkg.RegisterArch(cache.arch, container.BinfmtEntry{ - Offset: offset, - Magic: magic, - Mask: mask, + pkg.RegisterArch("riscv64", container.BinfmtEntry{ + 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", Interpreter: pathname.Append( "system/bin", - "qemu-"+name, + "qemu-riscv64", + ), + }) + pkg.RegisterArch("arm64", container.BinfmtEntry{ + Offset: 0, + Magic: "\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00", + Mask: "\xff\xff\xff\xff\xff\xff\xff\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff", + Interpreter: pathname.Append( + "system/bin", + "qemu-aarch64", ), }) - rosa.DropCaches(cache.arch, rosa.Flags()) } return diff --git a/cmd/mbf/main.go b/cmd/mbf/main.go index a5f1807a..e9cd8f4f 100644 --- a/cmd/mbf/main.go +++ b/cmd/mbf/main.go @@ -67,6 +67,8 @@ func main() { var ( flagQuiet bool + flagQEMU bool + flagArch string flagCheck bool flagLTO bool @@ -94,6 +96,17 @@ func main() { flags |= rosa.OptLLVMNoLTO } rosa.DropCaches("", flags) + cross := flagArch != "" && flagArch != runtime.GOARCH + if flagQEMU || cross { + cm.qemu = rosa.Std.Load(rosa.QEMU) + } + + if cross { + rosa.DropCaches(flagArch, rosa.Flags()) + if !rosa.HasStage0() { + return pkg.UnsupportedArchError(flagArch) + } + } return nil }).Flag( @@ -101,7 +114,11 @@ func main() { "q", command.BoolFlag(false), "Do not print cure messages", ).Flag( - &cm.arch, + &flagQEMU, + "register", command.BoolFlag(false), + "Enable additional target architectures", + ).Flag( + &flagArch, "arch", command.StringFlag(runtime.GOARCH), "Target architecture", ).Flag( diff --git a/internal/rosa/stage0.go b/internal/rosa/stage0.go index 1862e47a..65274885 100644 --- a/internal/rosa/stage0.go +++ b/internal/rosa/stage0.go @@ -49,3 +49,12 @@ func init() { Description: "Rosa OS stage0 bootstrap seed", } } + +// HasStage0 returns whether a stage0 distribution is available. +func HasStage0() (ok bool) { + func() { + defer func() { ok = recover() == nil }() + toolchainStage0.Load(stage0Dist) + }() + return +}