aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/rosa/llvm.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/rosa/llvm.go')
-rw-r--r--internal/rosa/llvm.go30
1 files changed, 23 insertions, 7 deletions
diff --git a/internal/rosa/llvm.go b/internal/rosa/llvm.go
index a577df41..3144c4bd 100644
--- a/internal/rosa/llvm.go
+++ b/internal/rosa/llvm.go
@@ -5,6 +5,7 @@ import (
"slices"
"strconv"
"strings"
+ "sync"
"hakurei.app/container/check"
"hakurei.app/internal/pkg"
@@ -72,8 +73,8 @@ func llvmFlagName(flag int) string {
}
}
-// newLLVM returns a [pkg.Artifact] containing a LLVM variant.
-func (t Toolchain) newLLVM(variant string, attr *llvmAttr) pkg.Artifact {
+// newLLVMVariant returns a [pkg.Artifact] containing a LLVM variant.
+func (t Toolchain) newLLVMVariant(variant string, attr *llvmAttr) pkg.Artifact {
const (
version = "21.1.8"
checksum = "8SUpqDkcgwOPsqHVtmf9kXfFeVmjVxl4LMn-qSE1AI_Xoeju-9HaoPNGtidyxyka"
@@ -219,8 +220,8 @@ cat /usr/src/llvm-patches/* | patch -p 1
})
}
-// NewLLVM returns LLVM toolchain across multiple [pkg.Artifact].
-func (t Toolchain) NewLLVM() (musl, compilerRT, runtimes, clang pkg.Artifact) {
+// newLLVM returns LLVM toolchain across multiple [pkg.Artifact].
+func (t Toolchain) newLLVM() (musl, compilerRT, runtimes, clang pkg.Artifact) {
var target string
switch runtime.GOARCH {
case "386", "amd64":
@@ -236,7 +237,7 @@ func (t Toolchain) NewLLVM() (musl, compilerRT, runtimes, clang pkg.Artifact) {
{"LLVM_ENABLE_LIBXML2", "OFF"},
}
- compilerRT = t.newLLVM("compiler-rt", &llvmAttr{
+ compilerRT = t.newLLVMVariant("compiler-rt", &llvmAttr{
env: stage3ExclConcat(t, []string{},
"LDFLAGS="+earlyLDFLAGS(false),
),
@@ -291,7 +292,7 @@ ln -s \
),
})
- runtimes = t.newLLVM("runtimes", &llvmAttr{
+ runtimes = t.newLLVMVariant("runtimes", &llvmAttr{
env: stage3ExclConcat(t, []string{},
"LDFLAGS="+earlyLDFLAGS(false),
),
@@ -310,7 +311,7 @@ ln -s \
},
})
- clang = t.newLLVM("clang", &llvmAttr{
+ clang = t.newLLVMVariant("clang", &llvmAttr{
flags: llvmProjectClang | llvmProjectLld,
env: stage3ExclConcat(t, []string{},
"CFLAGS="+earlyCFLAGS,
@@ -459,3 +460,18 @@ index 64324a3f8b01..15ce70b68217 100644
return
}
+
+var (
+ // llvm stores the result of Toolchain.newLLVM.
+ llvm [_toolchainEnd][4]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) {
+ llvmOnce[t].Do(func() {
+ llvm[t][0], llvm[t][1], llvm[t][2], llvm[t][3] = t.newLLVM()
+ })
+ return llvm[t][0], llvm[t][1], llvm[t][2], llvm[t][3]
+}