internal/rosa/cmake: migrate to helper interface
All checks were successful
Test / Create distribution (push) Successful in 1m5s
Test / Sandbox (push) Successful in 2m40s
Test / Hakurei (push) Successful in 3m51s
Test / ShareFS (push) Successful in 4m2s
Test / Hpkg (push) Successful in 4m36s
Test / Sandbox (race detector) (push) Successful in 5m2s
Test / Hakurei (race detector) (push) Successful in 6m0s
Test / Flake checks (push) Successful in 1m46s

This change also removes some unused options.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-03-01 23:50:22 +09:00
parent 2baa9df133
commit 9deaf853f0
3 changed files with 81 additions and 108 deletions

View File

@@ -1,10 +1,10 @@
package rosa package rosa
import ( import (
"path"
"slices" "slices"
"strings" "strings"
"hakurei.app/container/check"
"hakurei.app/internal/pkg" "hakurei.app/internal/pkg"
) )
@@ -38,49 +38,54 @@ func (t Toolchain) newCMake() pkg.Artifact {
} }
func init() { artifactsF[CMake] = Toolchain.newCMake } func init() { artifactsF[CMake] = Toolchain.newCMake }
// CMakeAttr holds the project-specific attributes that will be applied to a new // CMakeHelper is the [CMake] build system helper.
// [pkg.Artifact] compiled via [CMake]. type CMakeHelper struct {
type CMakeAttr struct {
// Joined with name with a dash if non-empty. // Joined with name with a dash if non-empty.
Variant string Variant string
// Path elements joined with source. // Path elements joined with source.
Append []string Append []string
// Use source tree as scratch space.
Writable bool
// CMake CACHE entries. // CMake CACHE entries.
Cache [][2]string Cache [][2]string
// Additional environment variables.
Env []string
// Runs before cmake.
ScriptEarly string
// Runs after cmake, replaces default.
ScriptConfigured string
// Runs after install. // Runs after install.
Script string Script string
// Override the default installation prefix [AbsSystem].
Prefix *check.Absolute
// Passed through to [Toolchain.New].
Paths []pkg.ExecPath
// Passed through to [Toolchain.New].
Flag int
} }
// NewViaCMake returns a [pkg.Artifact] for compiling and installing via [CMake]. var _ Helper = new(CMakeHelper)
func (t Toolchain) NewViaCMake(
name, version string, // name returns its arguments and an optional variant string joined with '-'.
source pkg.Artifact, func (attr *CMakeHelper) name(name, version string) string {
attr *CMakeAttr, if attr != nil && attr.Variant != "" {
extra ...pkg.Artifact, name += "-" + attr.Variant
) pkg.Artifact {
if name == "" || version == "" {
panic("names must be non-empty")
} }
return name + "-" + version
}
// extra returns a hardcoded slice of [CMake] and [Ninja].
func (*CMakeHelper) extra(int) []PArtifact {
return []PArtifact{CMake, Ninja}
}
// wantsChmod returns false.
func (*CMakeHelper) wantsChmod() bool { return false }
// wantsWrite returns false.
func (*CMakeHelper) wantsWrite() bool { return false }
// scriptEarly returns the zero value.
func (*CMakeHelper) scriptEarly() string { return "" }
// createDir returns true.
func (*CMakeHelper) createDir() bool { return true }
// wantsDir returns a hardcoded, deterministic pathname.
func (*CMakeHelper) wantsDir() string { return "/cure/" }
// script generates the cure script.
func (attr *CMakeHelper) script(name string) string {
if attr == nil { if attr == nil {
attr = &CMakeAttr{ attr = &CMakeHelper{
Cache: [][2]string{ Cache: [][2]string{
{"CMAKE_BUILD_TYPE", "Release"}, {"CMAKE_BUILD_TYPE", "Release"},
}, },
@@ -90,45 +95,21 @@ func (t Toolchain) NewViaCMake(
panic("CACHE must be non-empty") panic("CACHE must be non-empty")
} }
scriptConfigured := "cmake --build .\ncmake --install .\n" return `
if attr.ScriptConfigured != "" {
scriptConfigured = attr.ScriptConfigured
}
prefix := attr.Prefix
if prefix == nil {
prefix = AbsSystem
}
rname := name
if attr.Variant != "" {
rname += "-" + attr.Variant
}
sourcePath := AbsUsrSrc.Append(name)
return t.New(rname+"-"+version, attr.Flag, stage0Concat(t, extra,
t.Load(CMake),
t.Load(Ninja),
), nil, slices.Concat([]string{
"ROSA_SOURCE=" + sourcePath.String(),
"ROSA_CMAKE_SOURCE=" + sourcePath.Append(attr.Append...).String(),
"ROSA_INSTALL_PREFIX=/work" + prefix.String(),
}, attr.Env), attr.ScriptEarly+`
mkdir /cure && cd /cure
cmake -G Ninja \ cmake -G Ninja \
-DCMAKE_C_COMPILER_TARGET="${ROSA_TRIPLE}" \ -DCMAKE_C_COMPILER_TARGET="${ROSA_TRIPLE}" \
-DCMAKE_CXX_COMPILER_TARGET="${ROSA_TRIPLE}" \ -DCMAKE_CXX_COMPILER_TARGET="${ROSA_TRIPLE}" \
-DCMAKE_ASM_COMPILER_TARGET="${ROSA_TRIPLE}" \ -DCMAKE_ASM_COMPILER_TARGET="${ROSA_TRIPLE}" \
`+strings.Join(slices.Collect(func(yield func(string) bool) { ` + strings.Join(slices.Collect(func(yield func(string) bool) {
for _, v := range attr.Cache { for _, v := range attr.Cache {
if !yield("-D" + v[0] + "=" + v[1]) { if !yield("-D" + v[0] + "=" + v[1]) {
return return
} }
} }
}), " \\\n\t")+` \ }), " \\\n\t") + ` \
-DCMAKE_INSTALL_PREFIX="${ROSA_INSTALL_PREFIX}" \ -DCMAKE_INSTALL_PREFIX=/work/system \
"${ROSA_CMAKE_SOURCE}" '/usr/src/` + name + `/` + path.Join(attr.Append...) + `'
`+scriptConfigured+attr.Script, slices.Concat([]pkg.ExecPath{ cmake --build .
pkg.Path(sourcePath, attr.Writable, source), cmake --install .
}, attr.Paths)...) ` + attr.Script
} }

View File

@@ -7,33 +7,27 @@ import (
"strings" "strings"
"sync" "sync"
"hakurei.app/container/check"
"hakurei.app/internal/pkg" "hakurei.app/internal/pkg"
) )
// llvmAttr holds the attributes that will be applied to a new [pkg.Artifact] // llvmAttr holds the attributes that will be applied to a new [pkg.Artifact]
// containing a LLVM variant. // containing a LLVM variant.
type llvmAttr struct { type llvmAttr struct {
// Passed through to PackageAttr.Flag.
flags int flags int
// Concatenated with default environment for CMakeAttr.Env. // Concatenated with default environment for PackageAttr.Env.
env []string env []string
// Concatenated with generated entries for CMakeAttr.Cache. // Concatenated with generated entries for CMakeHelper.Cache.
cmake [][2]string cmake [][2]string
// Override CMakeAttr.Append. // Override CMakeHelper.Append.
append []string append []string
// Concatenated with default dependencies for Toolchain.NewViaCMake. // Passed through to PackageAttr.NonStage0.
extra []pkg.Artifact nonStage0 []pkg.Artifact
// Passed through to CMakeAttr.Paths. // Passed through to PackageAttr.Paths.
paths []pkg.ExecPath paths []pkg.ExecPath
// Passed through to CMakeAttr.ScriptConfigured. // Concatenated with default fixup for CMakeHelper.Script.
scriptConfigured string
// Concatenated with default fixup for CMakeAttr.Script.
script string script string
// Passed through to CMakeAttr.Prefix.
prefix *check.Absolute
// Passed through to CMakeAttr.Writable.
writable bool
// Patch name and body pairs. // Patch name and body pairs.
patches [][2]string patches [][2]string
@@ -101,7 +95,7 @@ func (t Toolchain) newLLVMVariant(variant string, attr *llvmAttr) pkg.Artifact {
} }
} }
var script, scriptEarly string var script string
cache := [][2]string{ cache := [][2]string{
{"CMAKE_BUILD_TYPE", "Release"}, {"CMAKE_BUILD_TYPE", "Release"},
@@ -167,43 +161,41 @@ ln -s ld.lld /work/system/bin/ld
) )
} }
return t.NewViaCMake("llvm", version, t.NewPatchedSource( return t.NewPackage("llvm", version, t.NewPatchedSource(
"llvmorg", version, pkg.NewHTTPGetTar( "llvmorg", version, pkg.NewHTTPGetTar(
nil, "https://github.com/llvm/llvm-project/archive/refs/tags/"+ nil, "https://github.com/llvm/llvm-project/archive/refs/tags/"+
"llvmorg-"+version+".tar.gz", "llvmorg-"+version+".tar.gz",
mustDecode(checksum), mustDecode(checksum),
pkg.TarGzip, pkg.TarGzip,
), true, attr.patches..., ), true, attr.patches...,
), &CMakeAttr{ ), &PackageAttr{
Variant: variant, NonStage0: attr.nonStage0,
Cache: slices.Concat(cache, attr.cmake),
Append: cmakeAppend,
Prefix: attr.prefix,
Env: slices.Concat([]string{ Env: slices.Concat([]string{
"ROSA_LLVM_PROJECTS=" + strings.Join(projects, ";"), "ROSA_LLVM_PROJECTS=" + strings.Join(projects, ";"),
"ROSA_LLVM_RUNTIMES=" + strings.Join(runtimes, ";"), "ROSA_LLVM_RUNTIMES=" + strings.Join(runtimes, ";"),
}, attr.env), }, attr.env),
ScriptEarly: scriptEarly,
ScriptConfigured: attr.scriptConfigured,
Script: script + attr.script,
Writable: attr.writable,
Paths: attr.paths, Paths: attr.paths,
Flag: TExclusive, Flag: TExclusive,
}, stage0Concat(t, attr.extra, }, &CMakeHelper{
t.Load(Libffi), Variant: variant,
t.Load(Python),
t.Load(Perl),
t.Load(Diffutils),
t.Load(Bash),
t.Load(Gawk),
t.Load(Coreutils),
t.Load(Findutils),
t.Load(KernelHeaders), Cache: slices.Concat(cache, attr.cmake),
)...) Append: cmakeAppend,
Script: script + attr.script,
},
Libffi,
Python,
Perl,
Diffutils,
Bash,
Gawk,
Coreutils,
Findutils,
KernelHeaders,
)
} }
// newLLVM returns LLVM toolchain across multiple [pkg.Artifact]. // newLLVM returns LLVM toolchain across multiple [pkg.Artifact].
@@ -246,21 +238,21 @@ func (t Toolchain) newLLVM() (musl, compilerRT, runtimes, clang pkg.Artifact) {
{"COMPILER_RT_BUILD_XRAY", "OFF"}, {"COMPILER_RT_BUILD_XRAY", "OFF"},
}, },
append: []string{"compiler-rt"}, append: []string{"compiler-rt"},
extra: []pkg.Artifact{t.newMusl(true, []string{ nonStage0: []pkg.Artifact{t.newMusl(true, []string{
"CC=clang", "CC=clang",
})}, })},
script: ` script: `
mkdir -p "${ROSA_INSTALL_PREFIX}/lib/clang/21/lib/" mkdir -p "/work/system/lib/clang/21/lib/"
ln -s \ ln -s \
"../../../${ROSA_TRIPLE}" \ "../../../${ROSA_TRIPLE}" \
"${ROSA_INSTALL_PREFIX}/lib/clang/21/lib/" "/work/system/lib/clang/21/lib/"
ln -s \ ln -s \
"clang_rt.crtbegin-` + linuxArch() + `.o" \ "clang_rt.crtbegin-` + linuxArch() + `.o" \
"${ROSA_INSTALL_PREFIX}/lib/${ROSA_TRIPLE}/crtbeginS.o" "/work/system/lib/${ROSA_TRIPLE}/crtbeginS.o"
ln -s \ ln -s \
"clang_rt.crtend-` + linuxArch() + `.o" \ "clang_rt.crtend-` + linuxArch() + `.o" \
"${ROSA_INSTALL_PREFIX}/lib/${ROSA_TRIPLE}/crtendS.o" "/work/system/lib/${ROSA_TRIPLE}/crtendS.o"
`, `,
}) })
@@ -287,7 +279,7 @@ ln -s \
{"LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL", "OFF"}, {"LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL", "OFF"},
}, minimalDeps), }, minimalDeps),
append: []string{"runtimes"}, append: []string{"runtimes"},
extra: []pkg.Artifact{ nonStage0: []pkg.Artifact{
compilerRT, compilerRT,
musl, musl,
}, },
@@ -305,7 +297,7 @@ ln -s \
{"CMAKE_CROSSCOMPILING", "OFF"}, {"CMAKE_CROSSCOMPILING", "OFF"},
{"CXX_SUPPORTS_CUSTOM_LINKER", "ON"}, {"CXX_SUPPORTS_CUSTOM_LINKER", "ON"},
}, minimalDeps), }, minimalDeps),
extra: []pkg.Artifact{ nonStage0: []pkg.Artifact{
musl, musl,
compilerRT, compilerRT,
runtimes, runtimes,

View File

@@ -7,12 +7,12 @@ func (t Toolchain) newZstd() pkg.Artifact {
version = "1.5.7" version = "1.5.7"
checksum = "4XhfR7DwVkwo1R-TmYDAJOcx9YXv9WSFhcFUe3hWEAMmdMLPhFaznCqYIA19_xxV" checksum = "4XhfR7DwVkwo1R-TmYDAJOcx9YXv9WSFhcFUe3hWEAMmdMLPhFaznCqYIA19_xxV"
) )
return t.NewViaCMake("zstd", version, pkg.NewHTTPGetTar( return t.NewPackage("zstd", version, pkg.NewHTTPGetTar(
nil, "https://github.com/facebook/zstd/releases/download/"+ nil, "https://github.com/facebook/zstd/releases/download/"+
"v"+version+"/zstd-"+version+".tar.gz", "v"+version+"/zstd-"+version+".tar.gz",
mustDecode(checksum), mustDecode(checksum),
pkg.TarGzip, pkg.TarGzip,
), &CMakeAttr{ ), nil, &CMakeHelper{
Append: []string{"build", "cmake"}, Append: []string{"build", "cmake"},
Cache: [][2]string{ Cache: [][2]string{
{"CMAKE_BUILD_TYPE", "Release"}, {"CMAKE_BUILD_TYPE", "Release"},