From a7f7ce17959ccf36201338faeecdbf85d404fe7d Mon Sep 17 00:00:00 2001 From: Ophestra Date: Tue, 14 Apr 2026 00:19:33 +0900 Subject: [PATCH] internal/rosa/llvm: migrate compiler-rt The newLLVM family of functions predate the package system. This change migrates compiler-rt without changing any resulting artifacts. Signed-off-by: Ophestra --- cmd/mbf/main.go | 11 +++--- internal/rosa/llvm.go | 86 +++++++++++++++++++++-------------------- internal/rosa/rosa.go | 4 +- internal/rosa/stage0.go | 4 +- 4 files changed, 54 insertions(+), 51 deletions(-) diff --git a/cmd/mbf/main.go b/cmd/mbf/main.go index 74b1bd7f..96e00ef8 100644 --- a/cmd/mbf/main.go +++ b/cmd/mbf/main.go @@ -396,9 +396,9 @@ func main() { rosa.SetGentooStage3(flagGentoo, checksum) } - _, _, _, stage1 := (t - 2).NewLLVM() - _, _, _, stage2 := (t - 1).NewLLVM() - _, _, _, stage3 := t.NewLLVM() + _, _, stage1 := (t - 2).NewLLVM() + _, _, stage2 := (t - 1).NewLLVM() + _, _, stage3 := t.NewLLVM() var ( pathname *check.Absolute checksum [2]unique.Handle[pkg.Checksum] @@ -577,8 +577,9 @@ func main() { root = rosa.Std.AppendPresets(root, presets...) if flagWithToolchain { - musl, compilerRT, runtimes, clang := (rosa.Std - 1).NewLLVM() - root = append(root, musl, compilerRT, runtimes, clang) + boot := rosa.Std - 1 + musl, runtimes, clang := boot.NewLLVM() + root = append(root, musl, boot.Load(rosa.LLVMCompilerRT), runtimes, clang) } else { root = append(root, rosa.Std.Load(rosa.Musl)) } diff --git a/internal/rosa/llvm.go b/internal/rosa/llvm.go index 773aec52..d0498744 100644 --- a/internal/rosa/llvm.go +++ b/internal/rosa/llvm.go @@ -68,34 +68,12 @@ func (t Toolchain) newLLVMVariant(variant string, attr *llvmAttr) pkg.Artifact { ) } -// newLLVM returns LLVM toolchain across multiple [pkg.Artifact]. -func (t Toolchain) newLLVM() (musl, compilerRT, runtimes, clang pkg.Artifact) { - target := "'AArch64;RISCV;X86'" - if t.isStage0() { - switch runtime.GOARCH { - case "386", "amd64": - target = "X86" - case "arm64": - target = "AArch64" - case "riscv64": - target = "RISCV" - - default: - panic("unsupported target " + runtime.GOARCH) - } - } - - minimalDeps := []KV{ - {"LLVM_ENABLE_ZLIB", "OFF"}, - {"LLVM_ENABLE_ZSTD", "OFF"}, - {"LLVM_ENABLE_LIBXML2", "OFF"}, - } - +func (t Toolchain) newCompilerRT() (pkg.Artifact, string) { muslHeaders, _ := t.newMusl(true, []string{ "CC=clang", }) - compilerRT = t.newLLVMVariant("compiler-rt", &llvmAttr{ + return t.newLLVMVariant("compiler-rt", &llvmAttr{ env: stage0ExclConcat(t, []string{}, "LDFLAGS="+earlyLDFLAGS(false), ), @@ -137,7 +115,42 @@ ln -s \ "clang_rt.crtend-` + linuxArch() + `.o" \ "/work/system/lib/${ROSA_TRIPLE}/crtendS.o" `, - }) + }), llvmVersion +} +func init() { + artifactsM[LLVMCompilerRT] = Metadata{ + f: Toolchain.newCompilerRT, + + Name: "llvm-compiler-rt", + Description: "LLVM runtime: compiler-rt", + Website: "https://llvm.org/", + } +} + +// newLLVM returns LLVM toolchain across multiple [pkg.Artifact]. +func (t Toolchain) newLLVM() (musl, runtimes, clang pkg.Artifact) { + target := "'AArch64;RISCV;X86'" + if t.isStage0() { + switch runtime.GOARCH { + case "386", "amd64": + target = "X86" + case "arm64": + target = "AArch64" + case "riscv64": + target = "RISCV" + + default: + panic("unsupported target " + runtime.GOARCH) + } + } + + minimalDeps := []KV{ + {"LLVM_ENABLE_ZLIB", "OFF"}, + {"LLVM_ENABLE_ZSTD", "OFF"}, + {"LLVM_ENABLE_LIBXML2", "OFF"}, + } + + compilerRT := t.Load(LLVMCompilerRT) musl, _ = t.newMusl(false, stage0ExclConcat(t, []string{ "CC=clang", @@ -227,20 +240,9 @@ ninja check-all return } func init() { - artifactsM[LLVMCompilerRT] = Metadata{ - f: func(t Toolchain) (pkg.Artifact, string) { - _, compilerRT, _, _ := t.newLLVM() - return compilerRT, llvmVersion - }, - - Name: "llvm-compiler-rt", - Description: "LLVM runtime: compiler-rt", - Website: "https://llvm.org/", - } - artifactsM[LLVMRuntimes] = Metadata{ f: func(t Toolchain) (pkg.Artifact, string) { - _, _, runtimes, _ := t.newLLVM() + _, runtimes, _ := t.newLLVM() return runtimes, llvmVersion }, @@ -251,7 +253,7 @@ func init() { artifactsM[LLVMClang] = Metadata{ f: func(t Toolchain) (pkg.Artifact, string) { - _, _, _, clang := t.newLLVM() + _, _, clang := t.newLLVM() return clang, llvmVersion }, @@ -286,15 +288,15 @@ func init() { var ( // llvm stores the result of Toolchain.newLLVM. - llvm [_toolchainEnd][4]pkg.Artifact + llvm [_toolchainEnd][3]pkg.Artifact // llvmOnce is for lazy initialisation of llvm. llvmOnce [_toolchainEnd]sync.Once ) // NewLLVM returns LLVM toolchain across multiple [pkg.Artifact]. -func (t Toolchain) NewLLVM() (musl, compilerRT, runtimes, clang pkg.Artifact) { +func (t Toolchain) NewLLVM() (musl, runtimes, clang pkg.Artifact) { llvmOnce[t].Do(func() { - llvm[t][0], llvm[t][1], llvm[t][2], llvm[t][3] = t.newLLVM() + llvm[t][0], llvm[t][1], llvm[t][2] = t.newLLVM() }) - return llvm[t][0], llvm[t][1], llvm[t][2], llvm[t][3] + return llvm[t][0], llvm[t][1], llvm[t][2] } diff --git a/internal/rosa/rosa.go b/internal/rosa/rosa.go index c70774d2..89f1c900 100644 --- a/internal/rosa/rosa.go +++ b/internal/rosa/rosa.go @@ -329,13 +329,13 @@ mkdir -vp /work/system/bin } boot := t - 1 - musl, compilerRT, runtimes, clang := boot.NewLLVM() + musl, runtimes, clang := boot.NewLLVM() toybox := Toybox if flag&TEarly != 0 { toybox = toyboxEarly } std := []pkg.Artifact{cureEtc{newIANAEtc()}, musl} - toolchain := []pkg.Artifact{compilerRT, runtimes, clang} + toolchain := []pkg.Artifact{boot.Load(LLVMCompilerRT), runtimes, clang} utils := []pkg.Artifact{ boot.Load(Mksh), boot.Load(toybox), diff --git a/internal/rosa/stage0.go b/internal/rosa/stage0.go index 0fc0f8f7..ae5dc611 100644 --- a/internal/rosa/stage0.go +++ b/internal/rosa/stage0.go @@ -7,10 +7,10 @@ import ( ) func (t Toolchain) newStage0() (pkg.Artifact, string) { - musl, compilerRT, runtimes, clang := t.NewLLVM() + musl, runtimes, clang := t.NewLLVM() return t.New("rosa-stage0", 0, []pkg.Artifact{ musl, - compilerRT, + t.Load(LLVMCompilerRT), runtimes, clang,