From fe1acbe8bc14d8d8ae19e94d2b80576f6d6b183e Mon Sep 17 00:00:00 2001 From: Ophestra Date: Thu, 22 Oct 2026 13:13:53 +0900 Subject: internal/rosa: optionally bypass cross-compilation Cross-compilation is not applicable to everything, and it is quite wasteful rebuilding the same thing for every architecture when it is just using host tools to create arch-independent files. Signed-off-by: Ophestra --- internal/rosa/rosa.go | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'internal/rosa/rosa.go') diff --git a/internal/rosa/rosa.go b/internal/rosa/rosa.go index e83d7097..2241788f 100644 --- a/internal/rosa/rosa.go +++ b/internal/rosa/rosa.go @@ -267,8 +267,9 @@ function apply { } return t.New(name+"-src", Unversioned, nil, &PackageAttr{ - Paths: paths, - Tools: P{_patch}, + Paths: paths, + Tools: P{_patch}, + NoArch: true, }, &GenericHelper{ Build: buf.String(), }) @@ -302,7 +303,7 @@ type Helper interface { // PackageAttr holds build-system-agnostic attributes. type PackageAttr struct { - // Measure output if populated. Required by [THostNet]. + // Measure output if populated. Required by HostNet. KnownChecksum *pkg.Checksum // Mount the source tree writable. @@ -337,6 +338,8 @@ type PackageAttr struct { // Whether to create [pkg.KindExecNet] instead of [pkg.KindExec]. HostNet bool + // Whether the [Helper] behaves identically across all architectures. + NoArch bool // Inputs added only during cross-compilation. Cross P // Native utilities used by the build process. @@ -405,6 +408,10 @@ func (t Toolchain) New( attr = new(PackageAttr) } + if attr.NoArch { + t = t.native() + } + if attr.Std && !t.stage.isStd() { panic(BootstrapError(name)) } @@ -640,6 +647,17 @@ ln -s ../bin /usr/` ) } +// A CrossError refers to a package that does not support cross-compilation and +// is panicked by the helper implementation. +type CrossError string + +func (e CrossError) Error() string { + return "package " + strconv.Quote(string(e)) + + " does not support cross-compilation" +} + +var _ error = CrossError("") + // GenericHelper directly passes build script segments for invocations of // one-off build scripts too specific to fit into any other [Helper] // implementation, but can still benefit from [Toolchain.New]. @@ -677,14 +695,21 @@ func (attr *GenericHelper) wantsDir() (string, bool) { } // script concatenates specified segments. -func (attr *GenericHelper) script(t Toolchain, _ string) string { +func (attr *GenericHelper) script(t Toolchain, name string) string { if attr == nil { attr = new(GenericHelper) } script := attr.Build if t.cross() { - script = attr.Cross + script + if attr.Cross == "" { + panic(CrossError(name)) + } + cross := attr.Cross + if cross == "\x00" { + cross = "" + } + script = cross + script } if t.opts&OptSkipCheck == 0 { script += attr.Check -- cgit v1.3.1