From af4c3bbff2d4ef012db945963680f8f764e592ae Mon Sep 17 00:00:00 2001 From: Ophestra Date: Thu, 21 May 2026 18:08:00 +0900 Subject: [PATCH] internal/rosa/package: migrate toybox Signed-off-by: Ophestra --- internal/rosa/package/toybox.az | 134 ++++++++++++++++++++++++++++++++ internal/rosa/rosa.go | 31 +++----- internal/rosa/stage0.go | 4 +- internal/rosa/toybox.go | 92 ---------------------- 4 files changed, 145 insertions(+), 116 deletions(-) create mode 100644 internal/rosa/package/toybox.az delete mode 100644 internal/rosa/toybox.go diff --git a/internal/rosa/package/toybox.az b/internal/rosa/package/toybox.az new file mode 100644 index 00000000..7b1e31cf --- /dev/null +++ b/internal/rosa/package/toybox.az @@ -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, + ]; +} diff --git a/internal/rosa/rosa.go b/internal/rosa/rosa.go index b83b7d07..d3ee5f03 100644 --- a/internal/rosa/rosa.go +++ b/internal/rosa/rosa.go @@ -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") diff --git a/internal/rosa/stage0.go b/internal/rosa/stage0.go index eff0c5a8..a3bd8984 100644 --- a/internal/rosa/stage0.go +++ b/internal/rosa/stage0.go @@ -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 } diff --git a/internal/rosa/toybox.go b/internal/rosa/toybox.go deleted file mode 100644 index 7ced9c32..00000000 --- a/internal/rosa/toybox.go +++ /dev/null @@ -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/", - }) -}