aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/rosa/musl.go
blob: 796783721a42207b3aca2b0c63652c265c76cb88 (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
package rosa

import (
	"slices"

	"hakurei.app/internal/pkg"
)

// MuslAttr holds the attributes that will be applied to musl.
type MuslAttr struct {
	// Install headers only.
	Headers bool
	// Environment variables concatenated with defaults.
	Env []string
	// Dependencies concatenated with defaults.
	Extra []pkg.Artifact
}

// NewMusl returns a [pkg.Artifact] containing an installation of musl libc.
func (t Toolchain) NewMusl(attr *MuslAttr) pkg.Artifact {
	const (
		version  = "1.2.5"
		checksum = "y6USdIeSdHER_Fw2eT2CNjqShEye85oEg2jnOur96D073ukmIpIqDOLmECQroyDb"
	)

	if attr == nil {
		attr = new(MuslAttr)
	}

	target := "install"
	script := `
mkdir -p /work/system/bin
COMPAT_LINKER_NAME="ld-musl-` + linuxArch() + `.so.1"
ln -vs ../lib/libc.so /work/system/bin/linker
ln -vs ../lib/libc.so /work/system/bin/ldd
ln -vs libc.so "/work/system/lib/${COMPAT_LINKER_NAME}"
rm -v "/work/lib/${COMPAT_LINKER_NAME}"
rmdir -v /work/lib
`
	if attr.Headers {
		target = "install-headers"
		script = ""
	}

	return t.New("musl-"+version, 0, stage0Concat(t, attr.Extra,
		t.Load(Make),
		t.Load(Coreutils),
	), nil, slices.Concat([]string{
		"ROSA_MUSL_TARGET=" + target,
	}, attr.Env), `
cd "$(mktemp -d)"
/usr/src/musl/configure \
	--prefix=/system \
	--target="${ROSA_TRIPLE}"
make "-j$(nproc)" DESTDIR=/work "${ROSA_MUSL_TARGET}"
`+script, pkg.Path(AbsUsrSrc.Append("musl"), false, t.NewPatchedSource(
		// expected to be writable in copies
		"musl", version, pkg.NewHTTPGetTar(
			nil, "https://musl.libc.org/releases/musl-"+version+".tar.gz",
			mustDecode(checksum),
			pkg.TarGzip,
		), false,
	)))
}