aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-04-14 02:06:08 +0900
committerOphestra <cat@gensokyo.uk>2026-04-14 02:07:13 +0900
commite97f6a393f90c9a194dc9d19abf23b62fa17c987 (patch)
tree74d899ebca362caad5f8c573d188a5cb98e17fdf
parenteeffefd22b45b458af89f19e371fcac2179e1900 (diff)
internal/rosa/llvm: migrate runtimes and clang
This eliminates most newLLVM family of functions. Signed-off-by: Ophestra <cat@gensokyo.uk>
-rw-r--r--cmd/mbf/main.go42
-rw-r--r--internal/rosa/llvm.go161
-rw-r--r--internal/rosa/rosa.go19
-rw-r--r--internal/rosa/stage0.go5
4 files changed, 115 insertions, 112 deletions
diff --git a/cmd/mbf/main.go b/cmd/mbf/main.go
index e593c33b..c69ba0a6 100644
--- a/cmd/mbf/main.go
+++ b/cmd/mbf/main.go
@@ -396,24 +396,27 @@ func main() {
rosa.SetGentooStage3(flagGentoo, checksum)
}
- _, stage1 := (t - 2).NewLLVM()
- _, stage2 := (t - 1).NewLLVM()
- _, stage3 := t.NewLLVM()
var (
pathname *check.Absolute
checksum [2]unique.Handle[pkg.Checksum]
)
- if pathname, _, err = cache.Cure(stage1); err != nil {
+ if pathname, _, err = cache.Cure(
+ (t - 2).Load(rosa.LLVMClang),
+ ); err != nil {
return err
}
log.Println("stage1:", pathname)
- if pathname, checksum[0], err = cache.Cure(stage2); err != nil {
+ if pathname, checksum[0], err = cache.Cure(
+ (t - 1).Load(rosa.LLVMClang),
+ ); err != nil {
return err
}
log.Println("stage2:", pathname)
- if pathname, checksum[1], err = cache.Cure(stage3); err != nil {
+ if pathname, checksum[1], err = cache.Cure(
+ t.Load(rosa.LLVMClang),
+ ); err != nil {
return err
}
log.Println("stage3:", pathname)
@@ -565,7 +568,7 @@ func main() {
"shell",
"Interactive shell in the specified Rosa OS environment",
func(args []string) error {
- presets := make([]rosa.PArtifact, len(args))
+ presets := make([]rosa.PArtifact, len(args)+3)
for i, arg := range args {
p, ok := rosa.ResolveName(arg)
if !ok {
@@ -573,25 +576,20 @@ func main() {
}
presets[i] = p
}
- root := make(pkg.Collect, 0, 6+len(args))
- root = rosa.Std.AppendPresets(root, presets...)
- if flagWithToolchain {
- boot := rosa.Std - 1
- runtimes, clang := boot.NewLLVM()
- root = append(root,
- boot.Load(rosa.Musl),
- boot.Load(rosa.LLVMCompilerRT),
- runtimes, clang,
- )
- } else {
- root = append(root, rosa.Std.Load(rosa.Musl))
+ base := rosa.LLVMClang
+ if !flagWithToolchain {
+ base = rosa.Musl
}
- root = append(root,
- rosa.Std.Load(rosa.Mksh),
- rosa.Std.Load(rosa.Toybox),
+ presets = append(presets,
+ base,
+ rosa.Mksh,
+ rosa.Toybox,
)
+ root := make(pkg.Collect, 0, 6+len(args))
+ root = rosa.Std.AppendPresets(root, presets...)
+
if _, _, err := cache.Cure(&root); err == nil {
return errors.New("unreachable")
} else if !pkg.IsCollected(err) {
diff --git a/internal/rosa/llvm.go b/internal/rosa/llvm.go
index 18db52a2..74d0cdc9 100644
--- a/internal/rosa/llvm.go
+++ b/internal/rosa/llvm.go
@@ -3,7 +3,6 @@ package rosa
import (
"runtime"
"slices"
- "sync"
"hakurei.app/internal/pkg"
)
@@ -130,40 +129,26 @@ func init() {
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() (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"},
+ Dependencies: P{
+ Musl,
+ },
}
+}
- compilerRT := t.Load(LLVMCompilerRT)
- musl := t.Load(Musl)
-
- runtimes = t.newLLVMVariant("runtimes", &llvmAttr{
- env: stage0ExclConcat(t, []string{},
+func (t Toolchain) newLLVMRuntimes() (pkg.Artifact, string) {
+ return t.NewPackage("llvm", llvmVersion, llvmSource, &PackageAttr{
+ Patches: llvmPatches,
+ NonStage0: t.AppendPresets(nil, LLVMCompilerRT),
+ Env: stage0ExclConcat(t, []string{},
"LDFLAGS="+earlyLDFLAGS(false),
),
- cmake: slices.Concat([]KV{
+ Flag: TExclusive,
+ }, &CMakeHelper{
+ Variant: "runtimes",
+ Append: []string{"runtimes"},
+
+ Cache: []KV{
{"CMAKE_BUILD_TYPE", "Release"},
{"LLVM_HOST_TRIPLE", `"${ROSA_TRIPLE}"`},
@@ -181,21 +166,61 @@ func (t Toolchain) newLLVM() (runtimes, clang pkg.Artifact) {
{"LIBCXX_HAS_ATOMIC_LIB", "OFF"},
{"LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL", "OFF"},
- }, minimalDeps),
- append: []string{"runtimes"},
- nonStage0: []pkg.Artifact{
- compilerRT,
- musl,
+
+ {"LLVM_ENABLE_ZLIB", "OFF"},
+ {"LLVM_ENABLE_ZSTD", "OFF"},
+ {"LLVM_ENABLE_LIBXML2", "OFF"},
},
- })
+ },
+ Python,
+
+ KernelHeaders,
+ ), llvmVersion
+}
+func init() {
+ artifactsM[LLVMRuntimes] = Metadata{
+ f: Toolchain.newLLVMRuntimes,
- clang = t.newLLVMVariant("clang", &llvmAttr{
- env: stage0ExclConcat(t, []string{},
+ Name: "llvm-runtimes",
+ Description: "LLVM runtimes: libunwind, libcxx, libcxxabi",
+ Website: "https://llvm.org/",
+
+ Dependencies: P{
+ LLVMCompilerRT,
+ },
+ }
+}
+
+func (t Toolchain) newLLVMClang() (pkg.Artifact, string) {
+ 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)
+ }
+ }
+
+ return t.NewPackage("llvm", llvmVersion, llvmSource, &PackageAttr{
+ Patches: llvmPatches,
+ NonStage0: t.AppendPresets(nil, LLVMRuntimes),
+ Env: stage0ExclConcat(t, []string{},
"CFLAGS="+earlyCFLAGS,
"CXXFLAGS="+earlyCXXFLAGS(),
"LDFLAGS="+earlyLDFLAGS(false),
),
- cmake: slices.Concat([]KV{
+ Flag: TExclusive,
+ }, &CMakeHelper{
+ Variant: "clang",
+ Append: []string{"llvm"},
+
+ Cache: []KV{
{"CMAKE_BUILD_TYPE", "Release"},
{"LLVM_HOST_TRIPLE", `"${ROSA_TRIPLE}"`},
@@ -218,13 +243,12 @@ func (t Toolchain) newLLVM() (runtimes, clang pkg.Artifact) {
{"LLVM_TARGETS_TO_BUILD", target},
{"CMAKE_CROSSCOMPILING", "OFF"},
{"CXX_SUPPORTS_CUSTOM_LINKER", "ON"},
- }, minimalDeps),
- nonStage0: []pkg.Artifact{
- musl,
- compilerRT,
- runtimes,
+
+ {"LLVM_ENABLE_ZLIB", "OFF"},
+ {"LLVM_ENABLE_ZSTD", "OFF"},
+ {"LLVM_ENABLE_LIBXML2", "OFF"},
},
- script: `
+ Script: `
ln -s ld.lld /work/system/bin/ld
ln -s clang /work/system/bin/cc
@@ -232,32 +256,30 @@ ln -s clang++ /work/system/bin/c++
ninja check-all
`,
- })
+ },
+ Python,
+ Perl,
+ Diffutils,
+ Bash,
+ Gawk,
+ Coreutils,
+ Findutils,
- return
+ KernelHeaders,
+ ), llvmVersion
}
func init() {
- artifactsM[LLVMRuntimes] = Metadata{
- f: func(t Toolchain) (pkg.Artifact, string) {
- runtimes, _ := t.newLLVM()
- return runtimes, llvmVersion
- },
-
- Name: "llvm-runtimes",
- Description: "LLVM runtimes: libunwind, libcxx, libcxxabi",
- Website: "https://llvm.org/",
- }
-
artifactsM[LLVMClang] = Metadata{
- f: func(t Toolchain) (pkg.Artifact, string) {
- _, clang := t.newLLVM()
- return clang, llvmVersion
- },
+ f: Toolchain.newLLVMClang,
Name: "clang",
Description: `an "LLVM native" C/C++/Objective-C compiler`,
Website: "https://llvm.org/",
+ Dependencies: P{
+ LLVMRuntimes,
+ },
+
ID: 1830,
}
@@ -282,18 +304,3 @@ func init() {
Website: "https://libclc.llvm.org/",
}
}
-
-var (
- // llvm stores the result of Toolchain.newLLVM.
- llvm [_toolchainEnd][2]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() (runtimes, clang pkg.Artifact) {
- llvmOnce[t].Do(func() {
- llvm[t][0], llvm[t][1] = t.newLLVM()
- })
- return llvm[t][0], llvm[t][1]
-}
diff --git a/internal/rosa/rosa.go b/internal/rosa/rosa.go
index b2ae683b..8e6d6063 100644
--- a/internal/rosa/rosa.go
+++ b/internal/rosa/rosa.go
@@ -328,24 +328,23 @@ mkdir -vp /work/system/bin
name += "-std"
}
- boot := t - 1
- runtimes, clang := boot.NewLLVM()
toybox := Toybox
if flag&TEarly != 0 {
toybox = toyboxEarly
}
- std := []pkg.Artifact{cureEtc{newIANAEtc()}, boot.Load(Musl)}
- toolchain := []pkg.Artifact{boot.Load(LLVMCompilerRT), runtimes, clang}
- utils := []pkg.Artifact{
- boot.Load(Mksh),
- boot.Load(toybox),
- }
+ base := LLVMClang
if flag&TNoToolchain != 0 {
- toolchain = nil
+ base = Musl
}
- support = slices.Concat(extra, std, toolchain, utils)
+ support = slices.Concat(extra, (t-1).AppendPresets([]pkg.Artifact{
+ cureEtc{newIANAEtc()},
+ },
+ base,
+ Mksh,
+ toybox,
+ ))
env = fixupEnviron(env, []string{
EnvTriplet + "=" + triplet(),
lcMessages,
diff --git a/internal/rosa/stage0.go b/internal/rosa/stage0.go
index d147440e..f4a2edc5 100644
--- a/internal/rosa/stage0.go
+++ b/internal/rosa/stage0.go
@@ -7,12 +7,11 @@ import (
)
func (t Toolchain) newStage0() (pkg.Artifact, string) {
- runtimes, clang := t.NewLLVM()
return t.New("rosa-stage0", 0, []pkg.Artifact{
t.Load(Musl),
t.Load(LLVMCompilerRT),
- runtimes,
- clang,
+ t.Load(LLVMRuntimes),
+ t.Load(LLVMClang),
t.Load(Zlib),
t.Load(Bzip2),