aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/rosa/all.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-01-25 01:32:21 +0900
committerOphestra <cat@gensokyo.uk>2026-01-25 01:43:18 +0900
commit20790af71ec9a69a462ecaaa7fc308e3b685383d (patch)
treee7cfdd8fec51c5dc37db88ad887c07dee947b600 /internal/rosa/all.go
parent43b8a40fc0e8d99bf29531d33f1f57d0c6e9df5e (diff)
internal/rosa: lazy initialise all artifacts
This improves performance, though not as drastically as lazy initialising llvm. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/rosa/all.go')
-rw-r--r--internal/rosa/all.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/internal/rosa/all.go b/internal/rosa/all.go
new file mode 100644
index 00000000..68ae8e91
--- /dev/null
+++ b/internal/rosa/all.go
@@ -0,0 +1,53 @@
+package rosa
+
+import (
+ "sync"
+
+ "hakurei.app/internal/pkg"
+)
+
+// PArtifact is a lazily-initialised [pkg.Artifact] preset.
+type PArtifact int
+
+const (
+ Autoconf PArtifact = iota
+ Bash
+ Busybox
+ CMake
+ Coreutils
+ Diffutils
+ Gettext
+ Git
+ Go
+ KernelHeaders
+ Libffi
+ M4
+ Make
+ Ninja
+ Perl
+ Patch
+ Python
+ Rsync
+ Zlib
+
+ // _presetEnd is the total number of presets and does not denote a preset.
+ _presetEnd
+)
+
+var (
+ // artifactsF is an array of functions for the result of [PArtifact].
+ artifactsF [_presetEnd]func(t Toolchain) pkg.Artifact
+
+ // artifacts stores the result of artifactsF.
+ artifacts [_toolchainEnd][len(artifactsF)]pkg.Artifact
+ // artifactsOnce is for lazy initialisation of artifacts.
+ artifactsOnce [_toolchainEnd][len(artifactsF)]sync.Once
+)
+
+// Load returns the resulting [pkg.Artifact] of [PArtifact].
+func (t Toolchain) Load(p PArtifact) pkg.Artifact {
+ artifactsOnce[t][p].Do(func() {
+ artifacts[t][p] = artifactsF[p](t)
+ })
+ return artifacts[t][p]
+}