Files
hakurei/internal/rosa/meson.go
Ophestra 04d9984da0
All checks were successful
Test / Create distribution (push) Successful in 57s
Test / Sandbox (push) Successful in 2m57s
Test / Hakurei (push) Successful in 4m4s
Test / ShareFS (push) Successful in 4m21s
Test / Sandbox (race detector) (push) Successful in 5m15s
Test / Hakurei (race detector) (push) Successful in 6m12s
Test / Flake checks (push) Successful in 1m26s
internal/rosa/meson: migrate to helper interface
This change also removes some unused options.

Signed-off-by: Ophestra <cat@gensokyo.uk>
2026-03-02 14:07:16 +09:00

127 lines
2.7 KiB
Go

package rosa
import (
"slices"
"strings"
"hakurei.app/internal/pkg"
)
func (t Toolchain) newMeson() pkg.Artifact {
const (
version = "1.10.1"
checksum = "w895BXF_icncnXatT_OLCFe2PYEtg4KrKooMgUYdN-nQVvbFX3PvYWHGEpogsHtd"
)
return t.New("meson-"+version, 0, []pkg.Artifact{
t.Load(Python),
t.Load(Setuptools),
}, nil, nil, `
cd /usr/src/meson
chmod -R +w meson.egg-info
python3 setup.py \
install \
--prefix=/system \
--root=/work
`, pkg.Path(AbsUsrSrc.Append("meson"), true, pkg.NewHTTPGetTar(
nil, "https://github.com/mesonbuild/meson/releases/download/"+
version+"/meson-"+version+".tar.gz",
mustDecode(checksum),
pkg.TarGzip,
)))
}
func init() { artifactsF[Meson] = Toolchain.newMeson }
// MesonHelper is the [Meson] build system helper.
type MesonHelper struct {
// Runs after setup.
ScriptCompileEarly string
// Runs after compile.
ScriptCompiled string
// Runs after install.
Script string
// Flags passed to the setup command.
Setup [][2]string
// Whether to skip meson test.
SkipTest bool
}
var _ Helper = new(MesonHelper)
// name returns its arguments joined with '-'.
func (*MesonHelper) name(name, version string) string {
return name + "-" + version
}
// extra returns hardcoded meson runtime dependencies.
func (*MesonHelper) extra(int) []PArtifact {
return []PArtifact{
Python,
Meson,
Ninja,
PkgConfig,
CMake,
}
}
// wantsChmod returns false.
func (*MesonHelper) wantsChmod() bool { return false }
// wantsWrite returns false.
func (*MesonHelper) wantsWrite() bool { return false }
// scriptEarly returns the zero value.
func (*MesonHelper) scriptEarly() string { return "" }
// createDir returns false.
func (*MesonHelper) createDir() bool { return false }
// wantsDir requests a new directory in TMPDIR.
func (*MesonHelper) wantsDir() string { return `"$(mktemp -d)"` }
// script generates the cure script.
func (attr *MesonHelper) script(name string) string {
if attr == nil {
attr = new(MesonHelper)
}
scriptCompiled := attr.ScriptCompiled
if len(scriptCompiled) > 0 && scriptCompiled[0] != '\n' {
scriptCompiled = "\n" + scriptCompiled
}
var scriptTest string
if !attr.SkipTest {
scriptTest = `
meson test \
--print-errorlogs`
}
return `
cd "$(mktemp -d)"
meson setup \
` + strings.Join(slices.Collect(func(yield func(string) bool) {
for _, v := range append([][2]string{
{"prefix", "/system"},
{"buildtype", "release"},
}, attr.Setup...) {
s := "-" + v[0]
if len(v[0]) > 0 && v[0][0] != 'D' {
s = "-" + s
}
if v[1] != "" {
s += "=" + v[1]
}
if !yield(s) {
return
}
}
}), " \\\n\t") + ` \
. '/usr/src/` + name + `'
meson compile` + scriptCompiled + scriptTest + `
meson install \
--destdir=/work
` + attr.Script
}