aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/rosa/hakurei.go
blob: a44d64da7a719c9ad0efa51038c6f3f509c8fd5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package rosa

import "hakurei.app/internal/pkg"

func (t Toolchain) newHakurei(
	suffix, build, check, install string,
	withHostname bool,
) pkg.Artifact {
	hostname := `
echo 'Building test helper (hostname).'
go build -o /bin/hostname /usr/src/hostname/main.go
`
	if !withHostname {
		hostname = ""
	}

	name := "hakurei" + suffix
	return t.NewPackage(name, hakureiVersion, t.NewPatchedSource(
		"hakurei", hakureiVersion, hakureiSource, false, hakureiPatches...,
	), &PackageAttr{
		Writable: true,
		Env: []string{
			"CGO_ENABLED=1",
			"GOCACHE=/tmp/gocache",
			"CC=clang -O3 -Werror",
		},

		Paths: []pkg.ExecPath{pkg.Path(AbsUsrSrc.Append("hostname", "main.go"), false, pkg.NewFile(
			"hostname.go",
			[]byte(`
package main

import "os"

func main() {
	if name, err := os.Hostname(); err != nil {
		panic(err)
	} else {
		os.Stdout.WriteString(name)
	}
}
`),
		))},
	}, &GenericHelper{
		Build: hostname + `
HAKUREI_VERSION='v` + hakureiVersion + `'
` + build,
		Check:   check,
		Install: install,
	},
		Go,
		PkgConfig,

		// dist tarball
		Gzip,

		// statically linked
		Libseccomp,
		ACL,
		Fuse,
		XCB,
		Wayland,
		WaylandProtocols,

		KernelHeaders,
	)
}
func init() {
	meta := Metadata{
		Name:        "hakurei",
		Description: "low-level userspace tooling for Rosa OS",
		Website:     "https://hakurei.app",
		Version:     hakureiVersion,

		ID: 388834,
	}
	native.MustRegister(meta.Name, func(t Toolchain) (*Metadata, pkg.Artifact) {
		return &meta, t.newHakurei("", `
mkdir -p /work/system/libexec/hakurei/

echo "Building hakurei for $(go env GOOS)/$(go env GOARCH)."
go generate ./...
go build -trimpath -tags=rosa -o /work/system/libexec/hakurei -ldflags="-s -w
	-buildid=
	-linkmode external
	-extldflags=-static
	-X hakurei.app/internal/info.buildVersion=${HAKUREI_VERSION}
	-X hakurei.app/internal/info.hakureiPath=/system/bin/hakurei
	-X hakurei.app/internal/info.hsuPath=/system/bin/hsu
	-X main.hakureiPath=/system/bin/hakurei
" ./...
echo
`, `
echo '##### Testing hakurei.'
go test -ldflags='-buildid= -linkmode external -extldflags=-static' ./...
echo
`, `
mkdir -p /work/system/bin/
(cd /work/system/libexec/hakurei && mv \
	hakurei \
	sharefs \
	../../bin/)
`, true)
	})
}
func init() {
	meta := Metadata{
		Name:        "hakurei-dist",
		Description: "low-level userspace tooling for Rosa OS (distribution tarball)",
		Website:     "https://hakurei.app",
		Version:     hakureiVersion,
	}
	native.MustRegister(meta.Name, func(t Toolchain) (*Metadata, pkg.Artifact) {
		name := "all"
		if t.opts&OptSkipCheck != 0 {
			name = "make"
		}
		return &meta, t.newHakurei("-dist", `
export HAKUREI_VERSION
DESTDIR=/work ./`+name+`.sh
`, "", "", true)
	})
}