internal/rosa/package: migrate toybox
All checks were successful
Test / Create distribution (push) Successful in 1m58s
Test / Sandbox (push) Successful in 5m6s
Test / ShareFS (push) Successful in 7m41s
Test / Sandbox (race detector) (push) Successful in 8m20s
Test / Hakurei (race detector) (push) Successful in 9m28s
Test / Hakurei (push) Successful in 2m43s
Test / Flake checks (push) Successful in 1m22s

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-05-21 18:08:00 +09:00
parent 54aae9d72a
commit af4c3bbff2
4 changed files with 145 additions and 116 deletions

View File

@@ -0,0 +1,134 @@
package toybox-source {
description = "toybox source tree";
exclude = true;
version* = "0.8.13";
output = remoteTar {
url = "https://landley.net/toybox/downloads/toybox-"+version+".tar.gz";
checksum = "rZ1V1ATDte2WeQZanxLVoiRGdfPXhMlEo5-exX-e-ml8cGn9qOv0ABEUVZpX3wTI";
compress = gzip;
};
}
package toybox {
description = "many common Linux command line utilities";
website = "https://landley.net/toybox";
anitya = 13818;
source = toybox-source;
writable = true;
enterSource = true;
toyboxEarly = true;
exec = make {
omitDefaults = true;
inPlace = true;
skipConfigure = true;
preMake = `
LDFLAGS="${LDFLAGS:-''} -static"
chmod +w /bin/
ln -rs "$(which bash)" /bin/ || true
chmod +w kconfig tests
rm \
tests/du.test \
tests/sed.test \
tests/tar.test \
tests/ls.test \
tests/taskset.test
make defconfig
sed -i \
's/^CONFIG_TOYBOX_ZHELP=y$/CONFIG_TOYBOX_ZHELP=0/' \
.config
`;
check = [
"USER=cure",
"tests",
];
skipEarlyStageCheck = true;
install = "PREFIX=/work/system/bin make install_flat";
postInstall = `
mkdir -p /work/usr/bin
ln -s ../../system/bin/env /work/usr/bin
`;
};
inputs = [
bash,
gzip,
kernel-headers,
];
}
package toybox-early {
description = "a build of toybox with unfinished tools enabled to break dependency loops";
website = "https://landley.net/toybox";
exclude = true;
source = toybox-source;
writable = true;
enterSource = true;
toyboxEarly = true;
exec = make {
omitDefaults = true;
inPlace = true;
skipConfigure = true;
preMake = `
LDFLAGS="${LDFLAGS:-''} -static"
chmod +w /bin/
ln -rs "$(which bash)" /bin/ || true
chmod +w kconfig tests
rm \
tests/du.test \
tests/sed.test \
tests/tar.test \
tests/ls.test \
tests/taskset.test
make defconfig
sed -i \
's/^CONFIG_TOYBOX_ZHELP=y$/CONFIG_TOYBOX_ZHELP=0/' \
.config
echo '
CONFIG_EXPR=y
CONFIG_TR=y
CONFIG_AWK=y
CONFIG_DIFF=y
' >> .config
`;
check = [
"USER=cure",
"tests",
];
skipEarlyStageCheck = true;
install = "PREFIX=/work/system/bin make install_flat";
postInstall = `
mkdir -p /work/usr/bin
ln -s ../../system/bin/env /work/usr/bin
`;
};
inputs = [
bash,
gzip,
kernel-headers,
];
}

View File

@@ -76,21 +76,9 @@ func (s *S) triple() string {
return s.linuxArch() + "-rosa-linux-musl"
}
// perArch is a value that differs per architecture.
type perArch[T any] map[string]T
// unwrap returns the value for the current architecture.
func (p perArch[T]) unwrap(s *S) T {
v, ok := p[s.arch]
if !ok {
panic("unsupported target " + s.arch)
}
return v
}
const (
// EnvTriplet holds the return value of triplet.
EnvTriplet = "ROSA_TRIPLE"
// EnvTriple holds the Rosa OS host triple.
EnvTriple = "ROSA_TRIPLE"
)
// earlyLDFLAGS returns LDFLAGS corresponding to triplet.
@@ -225,16 +213,15 @@ const (
)
var (
// stage0Dist is a binary distribution of an initial toolchain [Stage]. It
// is used by [Toolchain.New] as stageEarly.
stage0Dist = H("stage0-dist")
// The Mksh shell is added by [Toolchain.New] and used by almost all packages.
Mksh = H("mksh")
// Toybox is standard utilities added by [Toolchain.New].
Toybox = H("toybox")
// LLVM is the standard toolchain added by [Toolchain.New].
LLVM = H("llvm")
_stage0Dist = H("stage0-dist")
_toyboxEarly = H("toybox-early")
)
// New returns a [pkg.Artifact] based on a [Toolchain] via s.
@@ -262,7 +249,7 @@ func (t Toolchain) New(
support = append(support, extra...)
support = append(support, cureEtc{})
if t.stage == stageEarly {
_, a := t.MustLoad(stage0Dist)
_, a := t.MustLoad(_stage0Dist)
support = append(support, a)
} else {
support = append(support, t.S.New(_stageBusybox).New("gentoo", 0, nil, nil, nil, `
@@ -282,7 +269,7 @@ mkdir -vp /work/system/bin
)))
}
env = fixupEnviron(env, []string{
EnvTriplet + "=" + t.triple(),
EnvTriple + "=" + t.triple(),
lcMessages,
"LDFLAGS=" + t.earlyLDFLAGS(true),
}, "/system/bin",
@@ -297,7 +284,7 @@ mkdir -vp /work/system/bin
toybox := Toybox
if flag&TEarly != 0 {
toybox = toyboxEarly
toybox = _toyboxEarly
}
base := LLVM
@@ -313,7 +300,7 @@ mkdir -vp /work/system/bin
toybox,
))
env = fixupEnviron(env, []string{
EnvTriplet + "=" + t.triple(),
EnvTriple + "=" + t.triple(),
lcMessages,
}, "/system/bin", "/bin")

View File

@@ -28,7 +28,7 @@ tar \
`, pkg.Path(fhs.AbsRoot.Append("stage0"), false, t.Append(nil,
LLVM,
Mksh,
toyboxEarly,
_toyboxEarly,
)...))
})
}
@@ -37,7 +37,7 @@ tar \
func (s *S) HasStage0() (ok bool) {
func() {
defer func() { ok = recover() == nil }()
s.New(stageEarly).MustLoad(stage0Dist)
s.New(stageEarly).MustLoad(_stage0Dist)
}()
return
}

View File

@@ -1,92 +0,0 @@
package rosa
import "hakurei.app/internal/pkg"
var (
gzip = H("gzip")
toyboxEarly = H("toybox-early")
)
func (t Toolchain) newToybox(suffix, script string) (pkg.Artifact, string) {
const (
version = "0.8.13"
checksum = "rZ1V1ATDte2WeQZanxLVoiRGdfPXhMlEo5-exX-e-ml8cGn9qOv0ABEUVZpX3wTI"
)
return t.NewPackage("toybox"+suffix, version, newTar(
"https://landley.net/toybox/downloads/toybox-"+version+".tar.gz",
checksum,
pkg.TarGzip,
), &PackageAttr{
// uses source tree as scratch space
Writable: true,
EnterSource: true,
Flag: TEarly,
}, &MakeHelper{
OmitDefaults: true,
InPlace: true,
SkipConfigure: true,
ScriptMakeEarly: `
LDFLAGS="${LDFLAGS:-''} -static"
chmod +w /bin/
ln -rs "$(which bash)" /bin/ || true
chmod +w kconfig tests
rm \
tests/du.test \
tests/sed.test \
tests/tar.test \
tests/ls.test \
tests/taskset.test
make defconfig
sed -i \
's/^CONFIG_TOYBOX_ZHELP=y$/CONFIG_TOYBOX_ZHELP=0/' \
.config
` + script,
SkipCheck: t.stage.isStage0(),
Check: []string{
"USER=cure",
"tests",
},
Install: "PREFIX=/work/system/bin make install_flat",
Script: `
mkdir -p /work/usr/bin
ln -s ../../system/bin/env /work/usr/bin
`,
},
_bash,
gzip,
_kernelHeaders,
), version
}
func init() {
native.mustRegister(func(t Toolchain) (pkg.Artifact, string) {
return t.newToybox("", "")
}, &Metadata{
Name: "toybox",
Description: "many common Linux command line utilities",
Website: "https://landley.net/toybox/",
ID: 13818,
})
native.mustRegister(func(t Toolchain) (pkg.Artifact, string) {
return t.newToybox("-early", `
echo '
CONFIG_EXPR=y
CONFIG_TR=y
CONFIG_AWK=y
CONFIG_DIFF=y
' >> .config
`)
}, &Metadata{
Name: "toybox-early",
Description: "a build of toybox with unfinished tools enabled to break dependency loops",
Website: "https://landley.net/toybox/",
})
}