aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/rosa/meson.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-02-16 13:17:56 +0900
committerOphestra <cat@gensokyo.uk>2026-02-16 13:49:13 +0900
commit67b2914c94de1d35f72fc43a8051056afc8d53e9 (patch)
tree944cbd6a521e9fb0117e0ae59a0121b0784a883f /internal/rosa/meson.go
parent74dee118227cd72a2679f8eb167b43a1b165a415 (diff)
internal/rosa: meson helper
This is used by quite a few projects. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/rosa/meson.go')
-rw-r--r--internal/rosa/meson.go100
1 files changed, 99 insertions, 1 deletions
diff --git a/internal/rosa/meson.go b/internal/rosa/meson.go
index 33817adf..fbdb3637 100644
--- a/internal/rosa/meson.go
+++ b/internal/rosa/meson.go
@@ -1,6 +1,11 @@
package rosa
-import "hakurei.app/internal/pkg"
+import (
+ "slices"
+ "strings"
+
+ "hakurei.app/internal/pkg"
+)
func (t Toolchain) newMeson() pkg.Artifact {
const (
@@ -25,3 +30,96 @@ python3 setup.py \
)))
}
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),
+ })...)
+}