Files
hakurei/internal/rosa/cmake.go
Ophestra bc3dd6fbb0
All checks were successful
Test / Create distribution (push) Successful in 1m1s
Test / Sandbox (race detector) (push) Successful in 57s
Test / Sandbox (push) Successful in 2m9s
Test / Hakurei (push) Successful in 3m9s
Test / ShareFS (push) Successful in 3m4s
Test / Hakurei (race detector) (push) Successful in 3m42s
Test / Hpkg (push) Successful in 3m24s
Test / Flake checks (push) Successful in 1m46s
internal/rosa: chmod via patch helper
This works around the zfs overlay mount overhead and significantly reduces I/O in general.

Signed-off-by: Ophestra <cat@gensokyo.uk>
2026-01-30 00:29:44 +09:00

130 lines
3.1 KiB
Go

package rosa
import (
"slices"
"strings"
"hakurei.app/container/check"
"hakurei.app/internal/pkg"
)
func (t Toolchain) newCMake() pkg.Artifact {
const (
version = "4.2.1"
checksum = "Y3OdbMsob6Xk2y1DCME6z4Fryb5_TkFD7knRT8dTNIRtSqbiCJyyDN9AxggN_I75"
)
return t.New("cmake-"+version, 0, []pkg.Artifact{
t.Load(Make),
t.Load(KernelHeaders),
}, nil, nil, `
cd "$(mktemp -d)"
/usr/src/cmake/bootstrap \
--prefix=/system \
--parallel="$(nproc)" \
-- \
-DCMAKE_USE_OPENSSL=OFF
make "-j$(nproc)"
make DESTDIR=/work install
`, pkg.Path(AbsUsrSrc.Append("cmake"), true, t.NewPatchedSource(
// expected to be writable in the copy made during bootstrap
"cmake", version, pkg.NewHTTPGetTar(
nil, "https://github.com/Kitware/CMake/releases/download/"+
"v"+version+"/cmake-"+version+".tar.gz",
mustDecode(checksum),
pkg.TarGzip,
), false,
)))
}
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 {
// Path elements joined with source.
Append []string
// Use source tree as scratch space.
Writable bool
// Dependencies concatenated with the build system itself.
Extra []pkg.Artifact
// CMake CACHE entries.
Cache [][2]string
// Additional environment variables.
Env []string
// Runs before cmake.
ScriptEarly string
// Runs after cmake.
Script string
// Override the default installation prefix [AbsSystem].
Prefix *check.Absolute
// Return an exclusive artifact.
Exclusive bool
}
// NewViaCMake returns a [pkg.Artifact] for compiling and installing via CMake.
func (t Toolchain) NewViaCMake(
name, version, variant string,
source pkg.Artifact,
attr *CMakeAttr,
) pkg.Artifact {
if name == "" || version == "" || variant == "" {
panic("names must be non-empty")
}
if attr == nil {
attr = &CMakeAttr{
Cache: [][2]string{
{"CMAKE_BUILD_TYPE", "Release"},
},
}
}
if len(attr.Cache) == 0 {
panic("CACHE must be non-empty")
}
scriptEarly := attr.ScriptEarly
if attr.Writable {
scriptEarly = `
chmod -R +w "${ROSA_SOURCE}"
` + scriptEarly
}
prefix := attr.Prefix
if prefix == nil {
prefix = AbsSystem
}
var flag int
if attr.Exclusive {
flag |= TExclusive
}
sourcePath := AbsUsrSrc.Append(name)
return t.New(name+"-"+variant+"-"+version, flag, stage3Concat(t, attr.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), scriptEarly+`
mkdir /cure && cd /cure
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) {
for _, v := range attr.Cache {
if !yield("-D" + v[0] + "=" + v[1]) {
return
}
}
}), " \\\n\t")+` \
-DCMAKE_INSTALL_PREFIX="${ROSA_INSTALL_PREFIX}" \
"${ROSA_CMAKE_SOURCE}"
cmake --build .
cmake --install .
`+attr.Script, pkg.Path(sourcePath, attr.Writable, source))
}