From 51d3df2419e26f15d780c98629a357473855ebd4 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Sun, 1 Mar 2026 12:11:41 +0900 Subject: [PATCH] internal/rosa/make: split build and check Doing these together breaks far too many buggy makefiles. Signed-off-by: Ophestra --- internal/rosa/cmake.go | 15 +++--- internal/rosa/curl.go | 3 -- internal/rosa/git.go | 22 +++----- internal/rosa/gnu.go | 23 ++++----- internal/rosa/hakurei.go | 1 + internal/rosa/kernel.go | 2 +- internal/rosa/libcap.go | 2 +- internal/rosa/libgd.go | 3 -- internal/rosa/libseccomp.go | 3 -- internal/rosa/libxml2.go | 3 -- internal/rosa/libxslt.go | 3 -- internal/rosa/make.go | 100 ++++++++++++++++++++++-------------- internal/rosa/openssl.go | 20 ++++---- internal/rosa/perl.go | 21 ++++---- internal/rosa/python.go | 7 +-- internal/rosa/qemu.go | 9 +--- internal/rosa/toybox.go | 11 ++-- internal/rosa/x.go | 4 -- internal/rosa/xcb.go | 12 +---- 19 files changed, 119 insertions(+), 145 deletions(-) diff --git a/internal/rosa/cmake.go b/internal/rosa/cmake.go index 5f049dd..33bad61 100644 --- a/internal/rosa/cmake.go +++ b/internal/rosa/cmake.go @@ -24,14 +24,13 @@ func (t Toolchain) newCMake() pkg.Artifact { ), &MakeAttr{ OmitDefaults: true, - SkipConfigure: true, - ScriptConfigured: ` -/usr/src/cmake/bootstrap \ - --prefix=/system \ - --parallel="$(nproc)" \ - -- \ - -DCMAKE_USE_OPENSSL=OFF -`, + ConfigureName: "/usr/src/cmake/bootstrap", + Configure: [][2]string{ + {"prefix", "/system"}, + {"parallel", `"$(nproc)"`}, + {"--"}, + {"-DCMAKE_USE_OPENSSL", "OFF"}, + }, SkipCheck: true, }, t.Load(KernelHeaders), diff --git a/internal/rosa/curl.go b/internal/rosa/curl.go index c2022ca..d040ad7 100644 --- a/internal/rosa/curl.go +++ b/internal/rosa/curl.go @@ -19,9 +19,6 @@ func (t Toolchain) newCurl() pkg.Artifact { {"with-openssl"}, {"with-ca-bundle", "/system/etc/ssl/certs/ca-bundle.crt"}, }, - ScriptConfigured: ` -make "-j$(nproc)" -`, }, t.Load(Perl), diff --git a/internal/rosa/git.go b/internal/rosa/git.go index 0153f54..a243e50 100644 --- a/internal/rosa/git.go +++ b/internal/rosa/git.go @@ -1,8 +1,6 @@ package rosa -import ( - "hakurei.app/internal/pkg" -) +import "hakurei.app/internal/pkg" func (t Toolchain) newGit() pkg.Artifact { const ( @@ -21,20 +19,14 @@ func (t Toolchain) newGit() pkg.Artifact { Writable: true, InPlace: true, - // test suite in subdirectory - SkipCheck: true, - - Make: []string{"all"}, ScriptEarly: ` cd /usr/src/git make configure -`, - Script: ` ln -s ../../system/bin/perl /usr/bin/ || true function disable_test { - local test=$1 pattern=$2 + local test=$1 pattern=${2:-''} if [ $# -eq 1 ]; then rm "t/${test}.sh" else @@ -56,12 +48,12 @@ disable_test t9300-fast-import disable_test t0211-trace2-perf disable_test t1517-outside-repo disable_test t2200-add-update - -make \ - -C t \ - GIT_PROVE_OPTS="--jobs 32 --failures" \ - prove `, + Check: []string{ + "-C t", + `GIT_PROVE_OPTS="--jobs 32 --failures"`, + "prove", + }, }, t.Load(Perl), t.Load(Diffutils), diff --git a/internal/rosa/gnu.go b/internal/rosa/gnu.go index 75f4b38..a110dce 100644 --- a/internal/rosa/gnu.go +++ b/internal/rosa/gnu.go @@ -65,8 +65,9 @@ func (t Toolchain) newAutoconf() pkg.Artifact { mustDecode(checksum), pkg.TarGzip, ), &MakeAttr{ - Make: []string{ + Check: []string{ `TESTSUITEFLAGS="-j$(nproc)"`, + "check", }, Flag: TExclusive, }, @@ -122,8 +123,9 @@ func (t Toolchain) newLibtool() pkg.Artifact { mustDecode(checksum), pkg.TarGzip, ), &MakeAttr{ - Make: []string{ - `TESTSUITEFLAGS=32`, + Check: []string{ + `TESTSUITEFLAGS="-j$(nproc)"`, + "check", }, }, t.Load(M4), @@ -442,8 +444,9 @@ func (t Toolchain) newTar() pkg.Artifact { {"without-posix-acls"}, {"without-xattrs"}, }, - Make: []string{ + Check: []string{ `TESTSUITEFLAGS="-j$(nproc)"`, + "check", }, }, t.Load(Diffutils), @@ -464,11 +467,7 @@ func (t Toolchain) newBinutils() pkg.Artifact { nil, "https://ftpmirror.gnu.org/gnu/binutils/binutils-"+version+".tar.bz2", mustDecode(checksum), pkg.TarBzip2, - ), &MakeAttr{ - ScriptConfigured: ` -make "-j$(nproc)" -`, - }, + ), nil, t.Load(Bash), ) } @@ -484,11 +483,7 @@ func (t Toolchain) newGMP() pkg.Artifact { "gmp-"+version+".tar.bz2", mustDecode(checksum), pkg.TarBzip2, - ), &MakeAttr{ - ScriptConfigured: ` -make "-j$(nproc)" -`, - }, + ), nil, t.Load(M4), ) } diff --git a/internal/rosa/hakurei.go b/internal/rosa/hakurei.go index 0287917..fe94460 100644 --- a/internal/rosa/hakurei.go +++ b/internal/rosa/hakurei.go @@ -66,6 +66,7 @@ echo '# Building hakurei.' go generate -v ./... go build -trimpath -v -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 diff --git a/internal/rosa/kernel.go b/internal/rosa/kernel.go index bd3a144..def556c 100644 --- a/internal/rosa/kernel.go +++ b/internal/rosa/kernel.go @@ -29,7 +29,7 @@ func (t Toolchain) newKernelHeaders() pkg.Artifact { "-f /usr/src/kernel-headers/Makefile", "O=/tmp/kbuild", "LLVM=1", - `HOSTLDFLAGS="${LDFLAGS}"`, + `HOSTLDFLAGS="${LDFLAGS:-''}"`, "INSTALL_HDR_PATH=/work/system", "headers_install", }, diff --git a/internal/rosa/libcap.go b/internal/rosa/libcap.go index 804581c..4649291 100644 --- a/internal/rosa/libcap.go +++ b/internal/rosa/libcap.go @@ -31,7 +31,7 @@ cd /usr/src/libcap "CC=cc", "all", }, - CheckName: "test", + Check: []string{"test"}, }, t.Load(Bash), t.Load(Diffutils), diff --git a/internal/rosa/libgd.go b/internal/rosa/libgd.go index 6f2991d..fe88cbe 100644 --- a/internal/rosa/libgd.go +++ b/internal/rosa/libgd.go @@ -20,9 +20,6 @@ func (t Toolchain) newLibgd() pkg.Artifact { ScriptEarly: ` mkdir /dev/shm/gd `, - Configure: [][2]string{ - {"enable-static"}, - }, }, t.Load(Zlib), ) diff --git a/internal/rosa/libseccomp.go b/internal/rosa/libseccomp.go index b9b3136..1c2794b 100644 --- a/internal/rosa/libseccomp.go +++ b/internal/rosa/libseccomp.go @@ -19,9 +19,6 @@ func (t Toolchain) newLibseccomp() pkg.Artifact { ScriptEarly: ` ln -s ../system/bin/bash /bin/ `, - Configure: [][2]string{ - {"enable-static"}, - }, }, t.Load(Bash), t.Load(Diffutils), diff --git a/internal/rosa/libxml2.go b/internal/rosa/libxml2.go index 12013e5..058977e 100644 --- a/internal/rosa/libxml2.go +++ b/internal/rosa/libxml2.go @@ -22,9 +22,6 @@ cd /usr/src/ tar xf libxml2.tar.xz mv libxml2-` + version + ` libxml2 `, - Configure: [][2]string{ - {"enable-static"}, - }, SourceSuffix: ".tar.xz", }, t.Load(Diffutils), diff --git a/internal/rosa/libxslt.go b/internal/rosa/libxslt.go index 1531a88..db1fc41 100644 --- a/internal/rosa/libxslt.go +++ b/internal/rosa/libxslt.go @@ -22,9 +22,6 @@ cd /usr/src/ tar xf libxslt.tar.xz mv libxslt-` + version + ` libxslt `, - Configure: [][2]string{ - {"enable-static"}, - }, SourceSuffix: ".tar.xz", // python libxml2 cyclic dependency diff --git a/internal/rosa/make.go b/internal/rosa/make.go index 4d45f32..fb74039 100644 --- a/internal/rosa/make.go +++ b/internal/rosa/make.go @@ -45,6 +45,8 @@ type MakeAttr struct { ScriptEarly string // Runs after configure. ScriptConfigured string + // Runs before check. + ScriptCheckEarly string // Runs after install. Script string @@ -66,7 +68,7 @@ type MakeAttr struct { // Whether to skip the check target. SkipCheck bool // Name of the check target, zero value is equivalent to "check". - CheckName string + Check []string // Replaces the default install command. ScriptInstall string @@ -93,31 +95,30 @@ func (t Toolchain) NewViaMake( attr = new(MakeAttr) } - host := `"${ROSA_TRIPLE}"` - if attr.Host != "" { - host = attr.Host - } - build := `"${ROSA_TRIPLE}"` - if attr.Build != "" { - build = attr.Build - } - var configure string if !attr.SkipConfigure { configure = attr.ConfigureName if configure == "" { - configure += ` -/usr/src/` + name + `/configure \ + configure += `/usr/src/` + name + `/configure \ --prefix=/system` - } - if attr.Host != `""` { - configure += ` \ + host := `"${ROSA_TRIPLE}"` + if attr.Host != "" { + host = attr.Host + } + if attr.Host != `""` { + configure += ` \ --host=` + host - } - if attr.Build != `""` { - configure += ` \ + } + + build := `"${ROSA_TRIPLE}"` + if attr.Build != "" { + build = attr.Build + } + if attr.Build != `""` { + configure += ` \ --build=` + build + } } if len(attr.Configure) > 0 { @@ -149,17 +150,25 @@ func (t Toolchain) NewViaMake( } } - makeTargets := make([]string, 1, 2+len(attr.Make)) - if !attr.SkipCheck { - if attr.CheckName == "" { - makeTargets = append(makeTargets, "check") - } else { - makeTargets = append(makeTargets, attr.CheckName) - } + scriptMake := ` +make \ + "-j$(nproc)"` + if len(attr.Make) > 0 { + scriptMake += " \\\n\t" + strings.Join(attr.Make, " \\\n\t") } - makeTargets = append(makeTargets, attr.Make...) - if len(makeTargets) == 1 { - makeTargets = nil + scriptMake += "\n" + + if !attr.SkipCheck { + scriptMake += attr.ScriptCheckEarly + ` +make \ + "-j$(nproc)" \ + ` + if len(attr.Check) > 0 { + scriptMake += strings.Join(attr.Check, " \\\n\t") + } else { + scriptMake += "check" + } + scriptMake += "\n" } var finalExtra []pkg.Artifact @@ -176,7 +185,9 @@ func (t Toolchain) NewViaMake( scriptEarly := attr.ScriptEarly if !attr.InPlace { - scriptEarly += "\ncd \"$(mktemp -d)\"" + scriptEarly += ` +cd "$(mktemp -d)" +` } else if scriptEarly == "" { panic("cannot remain in root") } @@ -187,14 +198,25 @@ func (t Toolchain) NewViaMake( } scriptInstall += "\n" - return t.New(name+"-"+version, attr.Flag, stage0Concat(t, - attr.NonStage0, - finalExtra..., - ), nil, attr.Env, scriptEarly+configure+attr.ScriptConfigured+` -make "-j$(nproc)"`+strings.Join(makeTargets, " ")+` -`+scriptInstall+attr.Script, slices.Concat(attr.Paths, []pkg.ExecPath{ - pkg.Path(AbsUsrSrc.Append( - name+attr.SourceSuffix, - ), attr.Writable, source), - })...) + return t.New( + name+"-"+version, + attr.Flag, + stage0Concat(t, + attr.NonStage0, + finalExtra..., + ), + nil, + attr.Env, + scriptEarly+ + configure+ + attr.ScriptConfigured+ + scriptMake+ + scriptInstall+ + attr.Script, + slices.Concat(attr.Paths, []pkg.ExecPath{ + pkg.Path(AbsUsrSrc.Append( + name+attr.SourceSuffix, + ), attr.Writable, source), + })..., + ) } diff --git a/internal/rosa/openssl.go b/internal/rosa/openssl.go index df8c4a9..6361714 100644 --- a/internal/rosa/openssl.go +++ b/internal/rosa/openssl.go @@ -13,24 +13,24 @@ func (t Toolchain) newOpenSSL() pkg.Artifact { mustDecode(checksum), pkg.TarGzip, ), &MakeAttr{ - OmitDefaults: true, - SkipConfigure: true, + OmitDefaults: true, Env: []string{ "CC=cc", }, - ScriptConfigured: ` -/usr/src/openssl/Configure \ - --prefix=/system \ - --libdir=lib \ - --openssldir=etc/ssl -`, - CheckName: "test", - Make: []string{ + ConfigureName: "/usr/src/openssl/Configure", + Configure: [][2]string{ + {"prefix", "/system"}, + {"libdir", "lib"}, + {"openssldir", "etc/ssl"}, + }, + Check: []string{ `HARNESS_JOBS="$(expr "$(nproc)" '*' 2)"`, + "test", }, }, t.Load(Perl), + t.Load(Coreutils), t.Load(Zlib), t.Load(KernelHeaders), diff --git a/internal/rosa/perl.go b/internal/rosa/perl.go index 63b512d..2598cdc 100644 --- a/internal/rosa/perl.go +++ b/internal/rosa/perl.go @@ -29,8 +29,6 @@ echo 'print STDOUT "1..0 # Skip broken test\n";' > ext/Pod-Html/t/htmldir3.t rm -f /system/bin/ps # perl does not like toybox ps `, ConfigureName: "./Configure", - Host: `""`, - Build: `""`, Configure: [][2]string{ {"-des"}, {"Dprefix", "/system"}, @@ -40,7 +38,10 @@ rm -f /system/bin/ps # perl does not like toybox ps {"Doptimize", "'-O2 -fno-strict-aliasing'"}, {"Duseithreads"}, }, - CheckName: "TEST_JOBS=256 test_harness", + Check: []string{ + "TEST_JOBS=256", + "test_harness", + }, ScriptInstall: "./perl -Ilib -I. installperl --destdir=/work", Flag: TEarly, @@ -95,16 +96,18 @@ func (t Toolchain) newViaPerlMakeMaker( return t.NewViaMake("perl-"+name, version, t.NewPatchedSource( "perl-"+name, version, source, false, patches..., ), &MakeAttr{ - Writable: true, - OmitDefaults: true, - SkipConfigure: true, - InPlace: true, + Writable: true, + OmitDefaults: true, + InPlace: true, ScriptEarly: ` cd /usr/src/perl-` + name + ` -perl Makefile.PL PREFIX=/system `, - CheckName: "test", + ConfigureName: "perl Makefile.PL", + Configure: [][2]string{ + {"PREFIX", "/system"}, + }, + Check: []string{"test"}, }, slices.Concat(extra, []pkg.Artifact{ t.Load(Perl), })...) diff --git a/internal/rosa/python.go b/internal/rosa/python.go index 069b574..2c98424 100644 --- a/internal/rosa/python.go +++ b/internal/rosa/python.go @@ -48,12 +48,7 @@ func (t Toolchain) newPython() pkg.Artifact { "LDFLAGS=-Wl,--dynamic-linker=/system/lib/" + "ld-musl-" + linuxArch() + ".so.1", }, - - ScriptEarly: ` -export HOME="$(mktemp -d)" -`, - - CheckName: "test", + Check: []string{"test"}, }, t.Load(Zlib), t.Load(Libffi), diff --git a/internal/rosa/qemu.go b/internal/rosa/qemu.go index 07787c9..34241e0 100644 --- a/internal/rosa/qemu.go +++ b/internal/rosa/qemu.go @@ -1,8 +1,6 @@ package rosa -import ( - "hakurei.app/internal/pkg" -) +import "hakurei.app/internal/pkg" func (t Toolchain) newQEMU() pkg.Artifact { const ( @@ -57,7 +55,6 @@ _notrun 'appears to spuriously fail on zfs' EOF ) `, - Configure: [][2]string{ {"disable-download"}, {"disable-docs"}, @@ -70,10 +67,6 @@ EOF "ppc-softmmu," + "ppc64-softmmu"}, }, - - ScriptConfigured: ` -make "-j$(nproc)" -`, }, t.Load(Bash), t.Load(Python), diff --git a/internal/rosa/toybox.go b/internal/rosa/toybox.go index aa646db..329ad73 100644 --- a/internal/rosa/toybox.go +++ b/internal/rosa/toybox.go @@ -19,7 +19,7 @@ func (t Toolchain) newToybox(suffix, script string) pkg.Artifact { SkipConfigure: true, ScriptEarly: ` -LDFLAGS="${LDFLAGS} -static" +LDFLAGS="${LDFLAGS:-''} -static" chmod +w /bin/ ln -rs "$(which bash)" /bin/ || true @@ -37,13 +37,14 @@ make defconfig sed -i \ 's/^CONFIG_TOYBOX_ZHELP=y$/CONFIG_TOYBOX_ZHELP=0/' \ .config - -make "-j$(nproc)" `, ScriptConfigured: script, - CheckName: "USER=cure tests", SkipCheck: t.isStage0(), - ScriptInstall: "PREFIX=/work/system/bin make install_flat", + Check: []string{ + "USER=cure", + "tests", + }, + ScriptInstall: "PREFIX=/work/system/bin make install_flat", Script: ` mkdir -p /work/usr/bin ln -s ../../system/bin/env /work/usr/bin diff --git a/internal/rosa/x.go b/internal/rosa/x.go index 19777bd..191bbe6 100644 --- a/internal/rosa/x.go +++ b/internal/rosa/x.go @@ -64,10 +64,6 @@ func (t Toolchain) newLibXau() pkg.Artifact { cd /usr/src/libXau autoreconf -if `, - - Configure: [][2]string{ - {"enable-static"}, - }, }, t.Load(M4), t.Load(Perl), diff --git a/internal/rosa/xcb.go b/internal/rosa/xcb.go index b659cf2..b35c517 100644 --- a/internal/rosa/xcb.go +++ b/internal/rosa/xcb.go @@ -11,11 +11,7 @@ func (t Toolchain) newXCBProto() pkg.Artifact { nil, "https://xcb.freedesktop.org/dist/xcb-proto-"+version+".tar.gz", mustDecode(checksum), pkg.TarGzip, - ), &MakeAttr{ - Configure: [][2]string{ - {"enable-static"}, - }, - }, + ), nil, t.Load(Python), ) } @@ -30,11 +26,7 @@ func (t Toolchain) newXCB() pkg.Artifact { nil, "https://xcb.freedesktop.org/dist/libxcb-"+version+".tar.gz", mustDecode(checksum), pkg.TarGzip, - ), &MakeAttr{ - Configure: [][2]string{ - {"enable-static"}, - }, - }, + ), nil, t.Load(Python), t.Load(PkgConfig),