aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/rosa/cmake.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-03-01 23:50:22 +0900
committerOphestra <cat@gensokyo.uk>2026-03-01 23:50:22 +0900
commit9deaf853f0676ee4475468bffd35aae7e1160a74 (patch)
treeb0fe283249a853e64b76f9585c623c745ec9796e /internal/rosa/cmake.go
parent2baa9df1331721ea6e0cbd384784fcb97101b8dc (diff)
internal/rosa/cmake: migrate to helper interface
This change also removes some unused options. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/rosa/cmake.go')
-rw-r--r--internal/rosa/cmake.go103
1 files changed, 42 insertions, 61 deletions
diff --git a/internal/rosa/cmake.go b/internal/rosa/cmake.go
index 33bad61c..85e6d292 100644
--- a/internal/rosa/cmake.go
+++ b/internal/rosa/cmake.go
@@ -1,10 +1,10 @@
package rosa
import (
+ "path"
"slices"
"strings"
- "hakurei.app/container/check"
"hakurei.app/internal/pkg"
)
@@ -38,49 +38,54 @@ func (t Toolchain) newCMake() pkg.Artifact {
}
func init() { artifactsF[CMake] = Toolchain.newCMake }
-// CMakeAttr holds the project-specific attributes that will be applied to a new
-// [pkg.Artifact] compiled via [CMake].
-type CMakeAttr struct {
+// CMakeHelper is the [CMake] build system helper.
+type CMakeHelper struct {
// Joined with name with a dash if non-empty.
Variant string
// Path elements joined with source.
Append []string
- // Use source tree as scratch space.
- Writable bool
// CMake CACHE entries.
Cache [][2]string
- // Additional environment variables.
- Env []string
- // Runs before cmake.
- ScriptEarly string
- // Runs after cmake, replaces default.
- ScriptConfigured string
// Runs after install.
Script string
+}
- // Override the default installation prefix [AbsSystem].
- Prefix *check.Absolute
+var _ Helper = new(CMakeHelper)
- // Passed through to [Toolchain.New].
- Paths []pkg.ExecPath
- // Passed through to [Toolchain.New].
- Flag int
+// name returns its arguments and an optional variant string joined with '-'.
+func (attr *CMakeHelper) name(name, version string) string {
+ if attr != nil && attr.Variant != "" {
+ name += "-" + attr.Variant
+ }
+ return name + "-" + version
}
-// NewViaCMake returns a [pkg.Artifact] for compiling and installing via [CMake].
-func (t Toolchain) NewViaCMake(
- name, version string,
- source pkg.Artifact,
- attr *CMakeAttr,
- extra ...pkg.Artifact,
-) pkg.Artifact {
- if name == "" || version == "" {
- panic("names must be non-empty")
- }
+// 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 {
- attr = &CMakeAttr{
+ attr = &CMakeHelper{
Cache: [][2]string{
{"CMAKE_BUILD_TYPE", "Release"},
},
@@ -90,45 +95,21 @@ func (t Toolchain) NewViaCMake(
panic("CACHE must be non-empty")
}
- scriptConfigured := "cmake --build .\ncmake --install .\n"
- 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
+ return `
cmake -G Ninja \
-DCMAKE_C_COMPILER_TARGET="${ROSA_TRIPLE}" \
-DCMAKE_CXX_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 {
if !yield("-D" + v[0] + "=" + v[1]) {
return
}
}
- }), " \\\n\t")+` \
- -DCMAKE_INSTALL_PREFIX="${ROSA_INSTALL_PREFIX}" \
- "${ROSA_CMAKE_SOURCE}"
-`+scriptConfigured+attr.Script, slices.Concat([]pkg.ExecPath{
- pkg.Path(sourcePath, attr.Writable, source),
- }, attr.Paths)...)
+ }), " \\\n\t") + ` \
+ -DCMAKE_INSTALL_PREFIX=/work/system \
+ '/usr/src/` + name + `/` + path.Join(attr.Append...) + `'
+cmake --build .
+cmake --install .
+` + attr.Script
}