Files
hakurei/internal/rosa/meson.go
Ophestra 67b2914c94
All checks were successful
Test / Create distribution (push) Successful in 1m1s
Test / Sandbox (push) Successful in 2m34s
Test / Hakurei (push) Successful in 4m1s
Test / ShareFS (push) Successful in 4m0s
Test / Hpkg (push) Successful in 4m31s
Test / Sandbox (race detector) (push) Successful in 5m9s
Test / Hakurei (race detector) (push) Successful in 5m58s
Test / Flake checks (push) Successful in 2m0s
internal/rosa: meson helper
This is used by quite a few projects.

Signed-off-by: Ophestra <cat@gensokyo.uk>
2026-02-16 13:49:13 +09:00

126 lines
2.8 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 }
// MesonAttr holds the project-specific attributes that will be applied to a new
// [pkg.Artifact] compiled via [Meson].
type MesonAttr struct {
// Mount the source tree writable.
Writable bool
// Additional environment variables.
Env []string
// Runs before setup.
ScriptEarly string
// Runs after configure.
ScriptCompiled string
// Runs after install.
Script string
// Flags passed to the setup command.
Configure [][2]string
// Whether to skip meson test.
SkipCheck bool
// Appended after the test command.
AppendTest string
// Suffix appended to the source pathname.
SourceSuffix string
// Passed through to [Toolchain.New], before source.
Paths []pkg.ExecPath
// Passed through to [Toolchain.New].
Flag int
}
// NewViaMeson returns a [pkg.Artifact] for compiling and installing via [Meson].
func (t Toolchain) NewViaMeson(
name, version string,
source pkg.Artifact,
attr *MesonAttr,
extra ...pkg.Artifact,
) pkg.Artifact {
if name == "" || version == "" {
panic("names must be non-empty")
}
if attr == nil {
attr = new(MesonAttr)
}
scriptCompiled := attr.ScriptCompiled
if len(scriptCompiled) > 0 && scriptCompiled[0] != '\n' {
scriptCompiled = "\n" + scriptCompiled
}
var check string
if !attr.SkipCheck {
check = "\nmeson test \\\n\t--print-errorlogs" + attr.AppendTest
}
return t.New(name+"-"+version, attr.Flag, slices.Concat([]pkg.Artifact{
t.Load(Python),
t.Load(Meson),
t.Load(Ninja),
t.Load(PkgConfig),
t.Load(CMake),
}, extra), nil, attr.Env, attr.ScriptEarly+`
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.Configure...) {
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+check+`
meson install \
--destdir=/work
`+attr.Script, slices.Concat(attr.Paths, []pkg.ExecPath{
pkg.Path(AbsUsrSrc.Append(
name+attr.SourceSuffix,
), attr.Writable, source),
})...)
}