From 29505347dcef0291b339d9894ef3e96ea89d8dc5 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 9 Apr 2024 17:16:26 +0200 Subject: [PATCH] bib: use target architecture for buildroot as well The existing code is trying to fetch two containers when doing a cross-arch image. The buildroot is run in the native architecture and only the target tree is run non-native. However it turns out this is not neccessary as even doing the buildroot in non-native is fast enough (given that it's mostly I/O and all I/O is run naively via syscall translation). So this commit removes the fetching of the native arch container for the buildroot. Note that in practise this was already the case when passing --target-arch to any container that had native build available. Here due to a bug/misfeature in the resolver library used it already resolved (incorrectly) to the target architecture and nobody noticed because it was good enough (after [0] got fixed). [0] https://lists.nongnu.org/archive/html/qemu-devel/2024-02/msg03971.html --- bib/cmd/bootc-image-builder/main.go | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/bib/cmd/bootc-image-builder/main.go b/bib/cmd/bootc-image-builder/main.go index 67810a5e..ba8f6311 100644 --- a/bib/cmd/bootc-image-builder/main.go +++ b/bib/cmd/bootc-image-builder/main.go @@ -170,28 +170,22 @@ func makeManifest(c *ManifestConfig, cacheRoot string) (manifest.OSBuildManifest // Resolve container - the normal case is that host and target // architecture are the same. However it is possible to build - // cross-arch images. When this is done the "build" pipeline - // will run with the "native" architecture of the target - // container and the other pipelines (usually just "image" - // will use the target architecture). + // cross-arch images by using qemu-user. Just run everything + // (including the build-root) with the target arch then, it + // is fast enough (given that it's mostly I/O and all I/O is + // run naively via syscall translation) hostArch := arch.Current().String() targetArch := c.Architecture.String() - resolverNative := container.NewResolver(hostArch) - resolverTarget := resolverNative - if hostArch != targetArch { - resolverTarget = container.NewResolver(targetArch) + var resolver *container.Resolver + if targetArch != "" { + resolver = container.NewResolver(targetArch) + } else { + resolver = container.NewResolver(hostArch) } containerSpecs := make(map[string][]container.Spec) for plName, sourceSpecs := range manifest.GetContainerSourceSpecs() { - var resolver *container.Resolver - if plName == "build" { - resolver = resolverNative - } else { - resolver = resolverTarget - } - for _, c := range sourceSpecs { resolver.Add(c) }